当前位置:网站首页>B. Integers Shop-Hello 2022
B. Integers Shop-Hello 2022
2022-06-23 17:21:00 【Qin Sanma】
B. Integers Shop
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
The integers shop sells nn segments. The ii-th of them contains all integers from lili to riri and costs cici coins.
Tomorrow Vasya will go to this shop and will buy some segments there. He will get all integers that appear in at least one of bought segments. The total cost of the purchase is the sum of costs of all segments in it.
After shopping, Vasya will get some more integers as a gift. He will get integer xx as a gift if and only if all of the following conditions are satisfied:
- Vasya hasn't bought xx.
- Vasya has bought integer ll that is less than xx.
- Vasya has bought integer rr that is greater than xx.
Vasya can get integer xx as a gift only once so he won't have the same integers after receiving a gift.
For example, if Vasya buys segment [2,4][2,4] for 2020 coins and segment [7,8][7,8] for 2222 coins, he spends 4242 coins and receives integers 2,3,4,7,82,3,4,7,8 from these segments. He also gets integers 55 and 66 as a gift.
Due to the technical issues only the first ss segments (that is, segments [l1,r1],[l2,r2],…,[ls,rs][l1,r1],[l2,r2],…,[ls,rs]) will be available tomorrow in the shop.
Vasya wants to get (to buy or to get as a gift) as many integers as possible. If he can do this in differents ways, he selects the cheapest of them.
For each ss from 11 to nn, find how many coins will Vasya spend if only the first ss segments will be available.
Input
The first line contains a single integer tt (1≤t≤10001≤t≤1000) — the number of test cases.
The first line of each test case contains the single integer nn (1≤n≤1051≤n≤105) — the number of segments in the shop.
Each of next nn lines contains three integers lili, riri, cici (1≤li≤ri≤109,1≤ci≤1091≤li≤ri≤109,1≤ci≤109) — the ends of the ii-th segments and its cost.
It is guaranteed that the total sum of nn over all test cases doesn't exceed 2⋅1052⋅105.
Output
For each test case output nn integers: the ss-th (1≤s≤n1≤s≤n) of them should be the number of coins Vasia will spend in the shop if only the first ss segments will be available.
Example
input
Copy
3 2 2 4 20 7 8 22 2 5 11 42 5 11 42 6 1 4 4 5 8 9 7 8 7 2 10 252 1 11 271 1 10 1
output
Copy
20 42 42 42 4 13 11 256 271 271
Note
In the first test case if s=1s=1 then Vasya can buy only the segment [2,4][2,4] for 2020 coins and get 33 integers.
The way to get 77 integers for 4242 coins in case s=2s=2 is described in the statement.
In the second test case note, that there can be the same segments in the shop.
=========================================================================
First of all, make sure that when the number is the most , Two paragraphs of numbers must be chosen , And no choice , After the selection, there is no need to re select , So we maintain left,right The extreme value of . Once you can modify , Modify immediately left, And its cost , And it should be revised together with the answer . If left Same as current , Then take the minimum , Revise with the answer .
The special case is , What we are currently encountering is the maximum interval , Then we have to modify the left and right expenses , But we can change the answer to the minimum cost per time and itself .
# include<iostream>
# include<algorithm>
# include<math.h>
using namespace std;
typedef long long int ll;
ll lef[200000+10],righ[200000+10],cost[200000+10];
int main()
{
/*
When the left endpoint is modified but the right endpoint is not
The left endpoint cost must be modified , The answer should also be modified
The same is true for the right endpoint
When the left endpoint is the same as the original left endpoint Change the left endpoint cost to a smaller value
The same is true for the right endpoint
Special judgement
When the left end point and the right end point cover all the original sections , The answer should be output ,
*/
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>lef[i]>>righ[i]>>cost[i];
}
ll ans=0x7f7f7f7f7f7f7f7f;
ll leftans=ans,rightans=ans;
ll l=ans,r=0;
for(int i=1;i<=n;i++)
{
if(l>lef[i])
{
l=lef[i];
leftans=cost[i];
ans=leftans+rightans;
}
else if(l==lef[i])
{
leftans=min(leftans,cost[i]);
ans=min(ans,leftans+rightans);
}
if(r<righ[i])
{
r=righ[i];
rightans=cost[i];
ans=leftans+rightans;
}
else if(r==righ[i])
{
rightans=min(rightans,cost[i]);
ans=min(ans,leftans+rightans);
}
if(r==righ[i]&&l==lef[i])
{
ans=min(ans,cost[i]);
}
cout<<ans<<endl;
}
}
return 0;
}
边栏推荐
- Safe and comfortable, a new generation of Qijun carefully interprets the love of the old father
- Apache foundation officially announced Apache inlong as a top-level project
- 酒店入住时间和离店时间的日期选择
- Intranet penetration token stealing
- Digital twin excavator of Tupu software realizes remote control
- [network communication -- webrtc] analysis of webrtc source code -- supplement of pacingcontroller related knowledge points
- The evolution of social structure and capital system brought about by the yuan universe
- 亚朵更新招股书:继续推进纳斯达克上市,已提前“套现”2060万元
- Another breakthrough! Alibaba cloud enters the Gartner cloud AI developer service Challenger quadrant
- How to make sales management more efficient?
猜你喜欢

Interface ownership dispute

JS common error reporting and exception capture

Digital twin excavator of Tupu software realizes remote control

【30. 串联所有单词的子串】

面渣逆袭:MySQL六十六问!建议收藏
![[go] calling Alipay to scan code for payment in a sandbox environment](/img/d4/c6d72a697bc08f69f11121a15109b3.png)
[go] calling Alipay to scan code for payment in a sandbox environment

Robot Orientation and some misunderstandings in major selection in college entrance examination

Troubleshooting of datanode entering stale status

Shushulang passed the listing hearing: the gross profit margin of the tablet business fell, and the profit in 2021 fell by 11% year-on-year

华为手机通过adb安装APK提示“签名不一致,该应用可能已被修改”
随机推荐
Innovative technology leader! Huawei cloud gaussdb won the 2022 authoritative award in the field of cloud native database
Redis cluster operation method
Safe and comfortable, a new generation of Qijun carefully interprets the love of the old father
Troubleshooting of datanode entering stale status
[untitled] Application of laser welding in medical treatment
The Google play academy team PK competition is in full swing!
Counter attack by flour dregs: MySQL 66 question! Suggested collection
ctfshow php的特性
The R language uses the RMSE function of the yardstick package to evaluate the performance of the regression model, the RMSE of the regression model on each fold of each cross validation (or resamplin
混沌工程在云原生中间件稳定性治理中的实践分享
How to select securities companies? Is it safe to open a mobile account?
电感参数有哪些?怎么选择电感?
How about stock online account opening and account opening process? Is online account opening safe?
Apache基金会正式宣布Apache InLong成为顶级项目
How to select an oscilloscope? These 10 points must be considered!
Look, this is the principle analysis of modulation and demodulation! Simulation documents attached
官方零基础入门 Jetpack Compose 的中文课程来啦!
Tensorrt Paser loading onnx inference use
How important is 5g dual card dual access?
ASEMI肖特基二极管和超快恢复二极管在开关电源中的对比