#include <bits/stdc++.h>
using namespace std;
typedef pair<long long,long long> P;
P arr[250000];
const int sz=262144;
struct Node {
vector<long long> v;
};
Node merge(Node l,Node r) {
Node ret;
int lind=0;
int rind=0;
for(int i=0;i<10;i++) {
if (lind!=10&&(rind==10||l.v[lind]<r.v[rind])) {
ret.v.push_back(l.v[lind++]);
}
else {
ret.v.push_back(r.v[rind++]);
}
}
return ret;
}
Node emp;
struct SegmentTree {
Node seg[sz*2];
Node sum(int l,int r,int node=1,int nodel=0,int noder=sz-1) {
if (r<nodel||l>noder) {
return emp;
}
if (l<=nodel&&noder<=r) {
return seg[node];
}
int mid=(nodel+noder)/2;
return merge(sum(l,r,node*2,nodel,mid),sum(l,r,node*2+1,mid+1,noder));
}
void update(int i,long long val) {
i+=sz;
Node cpy=emp;
cpy.v[0]=val;
seg[i]=merge(seg[i],cpy);
while (i>1) {
i/=2;
seg[i]=merge(seg[i*2],seg[i*2+1]);
}
}
};
Node pl(Node a,long long x) {
for(int i=0;i<10;i++) {
a.v[i]+=x;
}
return a;
}
SegmentTree st1;
SegmentTree st2;
int main(void) {
int n,k;
scanf("%d %d",&n,&k);
for(int i=0;i<10;i++) {
emp.v.push_back(1e12);
}
vector<int> press;
for(int i=0;i<n;i++) {
scanf("%lld %lld",&arr[i].first,&arr[i].second);
press.push_back(arr[i].second);
}
sort(press.begin(),press.end());
press.erase(unique(press.begin(),press.end()),press.end());
sort(arr,arr+n);
for(int i=0;i<sz*2;i++) {
st1.seg[i]=emp;
st2.seg[i]=emp;
}
Node ret=emp;
for(int i=0;i<n;i++) {
int y=lower_bound(press.begin(),press.end(),arr[i].second)-press.begin();
if (y!=0) {
ret=merge(ret,pl(st1.sum(0,y-1),arr[i].first+arr[i].second));
}
ret=merge(ret,pl(st2.sum(y,sz-1),arr[i].first-arr[i].second));
st1.update(y,-arr[i].first-arr[i].second);
st2.update(y,-arr[i].first+arr[i].second);
}
for(int i=0;i<k;i++) {
printf("%lld\n",ret.v[i]);
}
}
Compilation message
road_construction.cpp: In function 'int main()':
road_construction.cpp:66:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | scanf("%d %d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~~
road_construction.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | scanf("%lld %lld",&arr[i].first,&arr[i].second);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
244 ms |
250560 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3230 ms |
259900 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10024 ms |
189808 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
10024 ms |
189808 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
244 ms |
250560 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
244 ms |
250560 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |