//#pragma GCC optimize("Ofast,unroll-loops")
#include <bits/stdc++.h>
using namespace std;
typedef long long llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
#define endl '\n'
int n,k,q;
int ans[300001];
set<int> pre[300001];
map<int,int> pre2[300001];
bool vis[3000001];
map<pair<int,pair<int,int>>,int> xx;
map<pair<int,pair<int,int>>,int> xx2;
map<int,int> ss;
map<int,int> ss2;
vector<pair<int,int>> yy;
int ne=0;
int nn;
pair<int,int> solve(int i,int j){
pair<int,int> ac={i,0};
pair<int,int> ac2={j+1,0};
return {lower_bound(yy.begin(),yy.end(),ac)-yy.begin(),lower_bound(yy.begin(),yy.end(),ac2)-yy.begin()-1};
}
priority_queue<pair<int,int>> tree[4*800001];
priority_queue<pair<int,int>> tree2[4*800001];
int kk=1;
//int ans[300001];
void update(int no,int l,int r,int aa,int bb,pair<int,int> x,int st){
/*if(no==0){
cout<<aa<<":"<<bb<<":"<<x.a<<":"<<x.b<<endl;
}*/
if(r<aa or l>bb){
return;
}
if(aa<=l and r<=bb){
//cout<<l<<",,"<<r<<endl;
if(kk){
if(tree[no].size()){
pair<int,int> ma=tree[no].top();
tree[no].pop();
tree[no].push(max(ma,x));
ma=tree2[no].top();
tree2[no].pop();
tree2[no].push(max(ma,{-x.a,x.b}));
}
else{
tree[no].push(x);
tree2[no].push({-x.a,x.b});
}
return ;
}
tree[no].push(x);
tree2[no].push({-x.a,x.b});
}
else{
int mid=(l+r)/2;
update(no*2+1,l,mid,aa,bb,x,st);
update(no*2+2,mid+1,r,aa,bb,x,st);
}
}
int query(int no,int l,int r,int i){
int cur=0;
while(tree[no].size()){
if(vis[(tree[no].top()).b]){
tree[no].pop();
}
else{
break;
}
}
while(tree2[no].size()){
if(vis[(tree2[no].top()).b]){
tree2[no].pop();
}
else{
break;
}
}
if(tree[no].size()){
//cout<<l<<","<<r<<","<<yy[i].a<<endl;
cur=max(cur,abs((tree[no].top()).a-yy[i].a));
cur=max(cur,abs(-(tree2[no].top()).a-yy[i].a));
}
if(l<r){
int mid=(l+r)/2;
if(i<=mid){
cur=max(cur,query(no*2+1,l,mid,i));
}
else{
cur=max(cur,query(no*2+2,mid+1,r,i));
}
}
return cur;
}
void add(int i,int aa,int bb,int st){
int mid=(aa+bb)/2;
if(st==1){
xx[{i,{aa,mid}}]=ne;
pair<int,int> ind=solve(aa,mid);
update(0,0,nn-1,ind.a,ind.b,{aa,ne},0);
ne++;
xx[{i,{mid+1,bb}}]=ne;
ind=solve(mid+1,bb);
update(0,0,nn-1,ind.a,ind.b,{bb,ne},1);
ne++;
}
else{
vis[xx[{i,{aa,mid}}]]=1;
vis[xx[{i,{mid+1,bb}}]]=1;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>k>>q;
vector<pair<pair<int,int>,pair<int,int>>> cur;
vector<pair<int,int>> zz5;
for(int i=0;i<n;i++){
int x,aa,bb,tt;
cin>>x>>tt>>aa>>bb;
ss[x]++;
tt--;
if(aa!=1 or bb!=1e8){
kk=0;
}
cur.pb({{aa,-1},{x,tt}});
cur.pb({{bb,1},{x,tt}});
// pre[tt].insert(x);
zz5.pb({tt,x});
}
if(kk){
for(auto j:zz5){
pre[j.a].insert(j.b);
}
}
for(int i=0;i<q;i++){
int x,aa;
cin>>x>>aa;
ss[x]++;
cur.pb({{aa,0},{x,i}});
/*if(kk){
//pre[aa].insert(x);
}*/
}
sort(cur.begin(),cur.end());
int ind5=-1;
ss[-2e8]++;
ss[2e8]++;
for(auto j:ss){
ind5++;
ss2[j.a]=ind5;
yy.pb({j.a,ind5});
}
nn=yy.size();
//sort(cur.begin(),cur.end());
/* for(auto j:yy){
cout<<j.a<<",";
}
cout<<endl;*/
for(int i=0;i<k;i++){
pre[i].insert(-2e8);
pre2[i][-2e8]++;
pre[i].insert(2e8);
pre2[i][2e8]++;
//if(kk==0){
/*if(kk==0){
add(i,-2e8,2e8,1);
}*/
// xx[{i,{-2e8,2e8}}]=;
// update(0,0,nn-1,0,nn-1);
}
for(int i=0;i<k;i++){
vector<int> xx;
for(auto j:pre[i]){
xx.pb(j);
}
for(int j=0;j+1<xx.size();j++){
add(i,xx[j],xx[j+1],1);
//cout<<i<<":"<<xx[j]<<":"<<xx[j+1]<<endl;
}
}
for(auto j:cur){
if(j.a.b==-1){
//add
if(kk){
continue;
}
//continue;
if(pre2[j.b.b].find(j.b.a)!=pre2[j.b.b].end()){
if(pre2[j.b.b][j.b.a]>0){
pre2[j.b.b][j.b.a]++;
continue;
}
}
//else{
pre2[j.b.b][j.b.a]++;
int re=*(pre[j.b.b].lower_bound(j.b.a));
auto jj=pre[j.b.b].lower_bound(j.b.a);
jj--;
int le=*jj;
pre[j.b.b].insert(j.b.a);
add(j.b.b,le,re,0);
add(j.b.b,le,j.b.a,1);
add(j.b.b,j.b.a,re,1);
//}
}
else if(j.a.b==1){
//remove
if(kk){
continue;
}
//continue;
pre2[j.b.b][j.b.a]--;
if(pre2[j.b.b][j.b.a]==0){
pre[j.b.b].erase(j.b.a);
int re=*(pre[j.b.b].lower_bound(j.b.a));
auto jj=pre[j.b.b].lower_bound(j.b.a);
jj--;
int le=*jj;
add(j.b.b,le,j.b.a,0);
add(j.b.b,j.b.a,re,0);
add(j.b.b,le,re,1);
}
}
else{
//cout<<j.b.a<<":"<<j.b.b<<endl;
int ans2=query(0,0,nn-1,ss2[j.b.a]);
if(ans2>1e8){
ans2=-1;
}
ans[j.b.b]=ans2;
}
}
for(int i=0;i<q;i++){
cout<<ans[i]<<endl;
}
/*for(int i=0;i<cur.size();i++){
cur[i].b.a=ss2[cur[i].b.a];
}*/
return 0;
}
Compilation message
new_home.cpp: In function 'int main()':
new_home.cpp:201:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
201 | for(int j=0;j+1<xx.size();j++){
| ~~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
137 ms |
228892 KB |
Output is correct |
2 |
Correct |
138 ms |
228872 KB |
Output is correct |
3 |
Correct |
132 ms |
228768 KB |
Output is correct |
4 |
Correct |
130 ms |
228904 KB |
Output is correct |
5 |
Correct |
171 ms |
228968 KB |
Output is correct |
6 |
Correct |
135 ms |
229344 KB |
Output is correct |
7 |
Correct |
136 ms |
229684 KB |
Output is correct |
8 |
Correct |
153 ms |
229512 KB |
Output is correct |
9 |
Correct |
142 ms |
229664 KB |
Output is correct |
10 |
Correct |
136 ms |
229328 KB |
Output is correct |
11 |
Correct |
138 ms |
229508 KB |
Output is correct |
12 |
Correct |
134 ms |
229296 KB |
Output is correct |
13 |
Correct |
139 ms |
229448 KB |
Output is correct |
14 |
Correct |
137 ms |
229296 KB |
Output is correct |
15 |
Correct |
135 ms |
229468 KB |
Output is correct |
16 |
Correct |
135 ms |
229548 KB |
Output is correct |
17 |
Correct |
133 ms |
229496 KB |
Output is correct |
18 |
Correct |
131 ms |
229556 KB |
Output is correct |
19 |
Correct |
137 ms |
229508 KB |
Output is correct |
20 |
Correct |
136 ms |
229444 KB |
Output is correct |
21 |
Correct |
128 ms |
229088 KB |
Output is correct |
22 |
Correct |
133 ms |
229700 KB |
Output is correct |
23 |
Correct |
144 ms |
229648 KB |
Output is correct |
24 |
Correct |
133 ms |
229536 KB |
Output is correct |
25 |
Correct |
136 ms |
229444 KB |
Output is correct |
26 |
Correct |
139 ms |
229436 KB |
Output is correct |
27 |
Correct |
135 ms |
229164 KB |
Output is correct |
28 |
Correct |
144 ms |
229388 KB |
Output is correct |
29 |
Correct |
135 ms |
229328 KB |
Output is correct |
30 |
Correct |
156 ms |
229336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
137 ms |
228892 KB |
Output is correct |
2 |
Correct |
138 ms |
228872 KB |
Output is correct |
3 |
Correct |
132 ms |
228768 KB |
Output is correct |
4 |
Correct |
130 ms |
228904 KB |
Output is correct |
5 |
Correct |
171 ms |
228968 KB |
Output is correct |
6 |
Correct |
135 ms |
229344 KB |
Output is correct |
7 |
Correct |
136 ms |
229684 KB |
Output is correct |
8 |
Correct |
153 ms |
229512 KB |
Output is correct |
9 |
Correct |
142 ms |
229664 KB |
Output is correct |
10 |
Correct |
136 ms |
229328 KB |
Output is correct |
11 |
Correct |
138 ms |
229508 KB |
Output is correct |
12 |
Correct |
134 ms |
229296 KB |
Output is correct |
13 |
Correct |
139 ms |
229448 KB |
Output is correct |
14 |
Correct |
137 ms |
229296 KB |
Output is correct |
15 |
Correct |
135 ms |
229468 KB |
Output is correct |
16 |
Correct |
135 ms |
229548 KB |
Output is correct |
17 |
Correct |
133 ms |
229496 KB |
Output is correct |
18 |
Correct |
131 ms |
229556 KB |
Output is correct |
19 |
Correct |
137 ms |
229508 KB |
Output is correct |
20 |
Correct |
136 ms |
229444 KB |
Output is correct |
21 |
Correct |
128 ms |
229088 KB |
Output is correct |
22 |
Correct |
133 ms |
229700 KB |
Output is correct |
23 |
Correct |
144 ms |
229648 KB |
Output is correct |
24 |
Correct |
133 ms |
229536 KB |
Output is correct |
25 |
Correct |
136 ms |
229444 KB |
Output is correct |
26 |
Correct |
139 ms |
229436 KB |
Output is correct |
27 |
Correct |
135 ms |
229164 KB |
Output is correct |
28 |
Correct |
144 ms |
229388 KB |
Output is correct |
29 |
Correct |
135 ms |
229328 KB |
Output is correct |
30 |
Correct |
156 ms |
229336 KB |
Output is correct |
31 |
Correct |
2783 ms |
348716 KB |
Output is correct |
32 |
Correct |
192 ms |
233928 KB |
Output is correct |
33 |
Correct |
2083 ms |
311348 KB |
Output is correct |
34 |
Correct |
2710 ms |
350632 KB |
Output is correct |
35 |
Correct |
2413 ms |
337184 KB |
Output is correct |
36 |
Correct |
1886 ms |
311124 KB |
Output is correct |
37 |
Correct |
1725 ms |
317324 KB |
Output is correct |
38 |
Correct |
1373 ms |
301048 KB |
Output is correct |
39 |
Correct |
1068 ms |
305624 KB |
Output is correct |
40 |
Correct |
1072 ms |
301108 KB |
Output is correct |
41 |
Correct |
2720 ms |
331904 KB |
Output is correct |
42 |
Correct |
2685 ms |
335420 KB |
Output is correct |
43 |
Correct |
187 ms |
233912 KB |
Output is correct |
44 |
Correct |
2605 ms |
330688 KB |
Output is correct |
45 |
Correct |
2488 ms |
322972 KB |
Output is correct |
46 |
Correct |
2364 ms |
311824 KB |
Output is correct |
47 |
Correct |
1196 ms |
325224 KB |
Output is correct |
48 |
Correct |
1138 ms |
323384 KB |
Output is correct |
49 |
Correct |
1367 ms |
328024 KB |
Output is correct |
50 |
Correct |
1655 ms |
340152 KB |
Output is correct |
51 |
Correct |
1422 ms |
322536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4746 ms |
439568 KB |
Output is correct |
2 |
Correct |
3050 ms |
430256 KB |
Output is correct |
3 |
Correct |
4735 ms |
520728 KB |
Output is correct |
4 |
Correct |
4965 ms |
464720 KB |
Output is correct |
5 |
Correct |
2541 ms |
407692 KB |
Output is correct |
6 |
Correct |
2822 ms |
425636 KB |
Output is correct |
7 |
Correct |
4746 ms |
520872 KB |
Output is correct |
8 |
Correct |
4770 ms |
464760 KB |
Output is correct |
9 |
Correct |
4728 ms |
444384 KB |
Output is correct |
10 |
Correct |
4027 ms |
434640 KB |
Output is correct |
11 |
Correct |
2180 ms |
429388 KB |
Output is correct |
12 |
Correct |
2937 ms |
433380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5130 ms |
641220 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
137 ms |
228892 KB |
Output is correct |
2 |
Correct |
138 ms |
228872 KB |
Output is correct |
3 |
Correct |
132 ms |
228768 KB |
Output is correct |
4 |
Correct |
130 ms |
228904 KB |
Output is correct |
5 |
Correct |
171 ms |
228968 KB |
Output is correct |
6 |
Correct |
135 ms |
229344 KB |
Output is correct |
7 |
Correct |
136 ms |
229684 KB |
Output is correct |
8 |
Correct |
153 ms |
229512 KB |
Output is correct |
9 |
Correct |
142 ms |
229664 KB |
Output is correct |
10 |
Correct |
136 ms |
229328 KB |
Output is correct |
11 |
Correct |
138 ms |
229508 KB |
Output is correct |
12 |
Correct |
134 ms |
229296 KB |
Output is correct |
13 |
Correct |
139 ms |
229448 KB |
Output is correct |
14 |
Correct |
137 ms |
229296 KB |
Output is correct |
15 |
Correct |
135 ms |
229468 KB |
Output is correct |
16 |
Correct |
135 ms |
229548 KB |
Output is correct |
17 |
Correct |
133 ms |
229496 KB |
Output is correct |
18 |
Correct |
131 ms |
229556 KB |
Output is correct |
19 |
Correct |
137 ms |
229508 KB |
Output is correct |
20 |
Correct |
136 ms |
229444 KB |
Output is correct |
21 |
Correct |
128 ms |
229088 KB |
Output is correct |
22 |
Correct |
133 ms |
229700 KB |
Output is correct |
23 |
Correct |
144 ms |
229648 KB |
Output is correct |
24 |
Correct |
133 ms |
229536 KB |
Output is correct |
25 |
Correct |
136 ms |
229444 KB |
Output is correct |
26 |
Correct |
139 ms |
229436 KB |
Output is correct |
27 |
Correct |
135 ms |
229164 KB |
Output is correct |
28 |
Correct |
144 ms |
229388 KB |
Output is correct |
29 |
Correct |
135 ms |
229328 KB |
Output is correct |
30 |
Correct |
156 ms |
229336 KB |
Output is correct |
31 |
Correct |
2783 ms |
348716 KB |
Output is correct |
32 |
Correct |
192 ms |
233928 KB |
Output is correct |
33 |
Correct |
2083 ms |
311348 KB |
Output is correct |
34 |
Correct |
2710 ms |
350632 KB |
Output is correct |
35 |
Correct |
2413 ms |
337184 KB |
Output is correct |
36 |
Correct |
1886 ms |
311124 KB |
Output is correct |
37 |
Correct |
1725 ms |
317324 KB |
Output is correct |
38 |
Correct |
1373 ms |
301048 KB |
Output is correct |
39 |
Correct |
1068 ms |
305624 KB |
Output is correct |
40 |
Correct |
1072 ms |
301108 KB |
Output is correct |
41 |
Correct |
2720 ms |
331904 KB |
Output is correct |
42 |
Correct |
2685 ms |
335420 KB |
Output is correct |
43 |
Correct |
187 ms |
233912 KB |
Output is correct |
44 |
Correct |
2605 ms |
330688 KB |
Output is correct |
45 |
Correct |
2488 ms |
322972 KB |
Output is correct |
46 |
Correct |
2364 ms |
311824 KB |
Output is correct |
47 |
Correct |
1196 ms |
325224 KB |
Output is correct |
48 |
Correct |
1138 ms |
323384 KB |
Output is correct |
49 |
Correct |
1367 ms |
328024 KB |
Output is correct |
50 |
Correct |
1655 ms |
340152 KB |
Output is correct |
51 |
Correct |
1422 ms |
322536 KB |
Output is correct |
52 |
Correct |
2068 ms |
386204 KB |
Output is correct |
53 |
Correct |
2029 ms |
378484 KB |
Output is correct |
54 |
Correct |
2343 ms |
370728 KB |
Output is correct |
55 |
Correct |
2412 ms |
355716 KB |
Output is correct |
56 |
Correct |
2244 ms |
359064 KB |
Output is correct |
57 |
Correct |
2602 ms |
340380 KB |
Output is correct |
58 |
Correct |
2521 ms |
353832 KB |
Output is correct |
59 |
Correct |
2329 ms |
356728 KB |
Output is correct |
60 |
Correct |
2605 ms |
341816 KB |
Output is correct |
61 |
Correct |
298 ms |
262288 KB |
Output is correct |
62 |
Correct |
1973 ms |
376432 KB |
Output is correct |
63 |
Correct |
2157 ms |
368500 KB |
Output is correct |
64 |
Correct |
2256 ms |
371000 KB |
Output is correct |
65 |
Correct |
2482 ms |
359128 KB |
Output is correct |
66 |
Correct |
2675 ms |
340124 KB |
Output is correct |
67 |
Correct |
794 ms |
277256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
137 ms |
228892 KB |
Output is correct |
2 |
Correct |
138 ms |
228872 KB |
Output is correct |
3 |
Correct |
132 ms |
228768 KB |
Output is correct |
4 |
Correct |
130 ms |
228904 KB |
Output is correct |
5 |
Correct |
171 ms |
228968 KB |
Output is correct |
6 |
Correct |
135 ms |
229344 KB |
Output is correct |
7 |
Correct |
136 ms |
229684 KB |
Output is correct |
8 |
Correct |
153 ms |
229512 KB |
Output is correct |
9 |
Correct |
142 ms |
229664 KB |
Output is correct |
10 |
Correct |
136 ms |
229328 KB |
Output is correct |
11 |
Correct |
138 ms |
229508 KB |
Output is correct |
12 |
Correct |
134 ms |
229296 KB |
Output is correct |
13 |
Correct |
139 ms |
229448 KB |
Output is correct |
14 |
Correct |
137 ms |
229296 KB |
Output is correct |
15 |
Correct |
135 ms |
229468 KB |
Output is correct |
16 |
Correct |
135 ms |
229548 KB |
Output is correct |
17 |
Correct |
133 ms |
229496 KB |
Output is correct |
18 |
Correct |
131 ms |
229556 KB |
Output is correct |
19 |
Correct |
137 ms |
229508 KB |
Output is correct |
20 |
Correct |
136 ms |
229444 KB |
Output is correct |
21 |
Correct |
128 ms |
229088 KB |
Output is correct |
22 |
Correct |
133 ms |
229700 KB |
Output is correct |
23 |
Correct |
144 ms |
229648 KB |
Output is correct |
24 |
Correct |
133 ms |
229536 KB |
Output is correct |
25 |
Correct |
136 ms |
229444 KB |
Output is correct |
26 |
Correct |
139 ms |
229436 KB |
Output is correct |
27 |
Correct |
135 ms |
229164 KB |
Output is correct |
28 |
Correct |
144 ms |
229388 KB |
Output is correct |
29 |
Correct |
135 ms |
229328 KB |
Output is correct |
30 |
Correct |
156 ms |
229336 KB |
Output is correct |
31 |
Correct |
2783 ms |
348716 KB |
Output is correct |
32 |
Correct |
192 ms |
233928 KB |
Output is correct |
33 |
Correct |
2083 ms |
311348 KB |
Output is correct |
34 |
Correct |
2710 ms |
350632 KB |
Output is correct |
35 |
Correct |
2413 ms |
337184 KB |
Output is correct |
36 |
Correct |
1886 ms |
311124 KB |
Output is correct |
37 |
Correct |
1725 ms |
317324 KB |
Output is correct |
38 |
Correct |
1373 ms |
301048 KB |
Output is correct |
39 |
Correct |
1068 ms |
305624 KB |
Output is correct |
40 |
Correct |
1072 ms |
301108 KB |
Output is correct |
41 |
Correct |
2720 ms |
331904 KB |
Output is correct |
42 |
Correct |
2685 ms |
335420 KB |
Output is correct |
43 |
Correct |
187 ms |
233912 KB |
Output is correct |
44 |
Correct |
2605 ms |
330688 KB |
Output is correct |
45 |
Correct |
2488 ms |
322972 KB |
Output is correct |
46 |
Correct |
2364 ms |
311824 KB |
Output is correct |
47 |
Correct |
1196 ms |
325224 KB |
Output is correct |
48 |
Correct |
1138 ms |
323384 KB |
Output is correct |
49 |
Correct |
1367 ms |
328024 KB |
Output is correct |
50 |
Correct |
1655 ms |
340152 KB |
Output is correct |
51 |
Correct |
1422 ms |
322536 KB |
Output is correct |
52 |
Correct |
4746 ms |
439568 KB |
Output is correct |
53 |
Correct |
3050 ms |
430256 KB |
Output is correct |
54 |
Correct |
4735 ms |
520728 KB |
Output is correct |
55 |
Correct |
4965 ms |
464720 KB |
Output is correct |
56 |
Correct |
2541 ms |
407692 KB |
Output is correct |
57 |
Correct |
2822 ms |
425636 KB |
Output is correct |
58 |
Correct |
4746 ms |
520872 KB |
Output is correct |
59 |
Correct |
4770 ms |
464760 KB |
Output is correct |
60 |
Correct |
4728 ms |
444384 KB |
Output is correct |
61 |
Correct |
4027 ms |
434640 KB |
Output is correct |
62 |
Correct |
2180 ms |
429388 KB |
Output is correct |
63 |
Correct |
2937 ms |
433380 KB |
Output is correct |
64 |
Execution timed out |
5130 ms |
641220 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |