//#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};
}
set<pair<int,int>> tree[4*800001];
//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;
tree[no].insert(x);
}
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].begin())).b]){
tree[no].erase(tree[no].begin());
}
else{
break;
}
}
while(tree[no].size()){
auto j=tree[no].end();
j--;
if(vis[(*j).b]){
tree[no].erase(j);
}
else{
break;
}
}
if(tree[no].size()){
//cout<<l<<","<<r<<","<<yy[i].a<<endl;
cur=max(cur,abs((*tree[no].begin()).a-yy[i].a));
auto jj=tree[no].end();
jj--;
cur=max(cur,abs((*jj).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;
for(int i=0;i<n;i++){
int x,aa,bb,tt;
cin>>x>>tt>>aa>>bb;
ss[x]++;
tt--;
cur.pb({{aa,-1},{x,tt}});
cur.pb({{bb,1},{x,tt}});
}
for(int i=0;i<q;i++){
int x,aa;
cin>>x>>aa;
ss[x]++;
cur.pb({{aa,0},{x,i}});
}
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]++;
add(i,-2e8,2e8,1);
// xx[{i,{-2e8,2e8}}]=;
// update(0,0,nn-1,0,nn-1);
}
for(auto j:cur){
if(j.a.b==-1){
//add
//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
//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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
178756 KB |
Output is correct |
2 |
Correct |
99 ms |
178780 KB |
Output is correct |
3 |
Correct |
94 ms |
178704 KB |
Output is correct |
4 |
Correct |
95 ms |
178884 KB |
Output is correct |
5 |
Correct |
96 ms |
178784 KB |
Output is correct |
6 |
Correct |
101 ms |
179396 KB |
Output is correct |
7 |
Correct |
102 ms |
179968 KB |
Output is correct |
8 |
Correct |
106 ms |
179688 KB |
Output is correct |
9 |
Correct |
102 ms |
179940 KB |
Output is correct |
10 |
Correct |
99 ms |
179396 KB |
Output is correct |
11 |
Correct |
98 ms |
179404 KB |
Output is correct |
12 |
Correct |
109 ms |
179268 KB |
Output is correct |
13 |
Correct |
100 ms |
179396 KB |
Output is correct |
14 |
Correct |
106 ms |
179400 KB |
Output is correct |
15 |
Correct |
102 ms |
179556 KB |
Output is correct |
16 |
Correct |
100 ms |
179636 KB |
Output is correct |
17 |
Correct |
100 ms |
179612 KB |
Output is correct |
18 |
Correct |
101 ms |
179660 KB |
Output is correct |
19 |
Correct |
107 ms |
179640 KB |
Output is correct |
20 |
Correct |
108 ms |
179696 KB |
Output is correct |
21 |
Correct |
99 ms |
179244 KB |
Output is correct |
22 |
Correct |
102 ms |
179796 KB |
Output is correct |
23 |
Correct |
100 ms |
179732 KB |
Output is correct |
24 |
Correct |
103 ms |
179648 KB |
Output is correct |
25 |
Correct |
100 ms |
179524 KB |
Output is correct |
26 |
Correct |
99 ms |
179308 KB |
Output is correct |
27 |
Correct |
100 ms |
179140 KB |
Output is correct |
28 |
Correct |
101 ms |
179396 KB |
Output is correct |
29 |
Correct |
100 ms |
179396 KB |
Output is correct |
30 |
Correct |
102 ms |
179240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
178756 KB |
Output is correct |
2 |
Correct |
99 ms |
178780 KB |
Output is correct |
3 |
Correct |
94 ms |
178704 KB |
Output is correct |
4 |
Correct |
95 ms |
178884 KB |
Output is correct |
5 |
Correct |
96 ms |
178784 KB |
Output is correct |
6 |
Correct |
101 ms |
179396 KB |
Output is correct |
7 |
Correct |
102 ms |
179968 KB |
Output is correct |
8 |
Correct |
106 ms |
179688 KB |
Output is correct |
9 |
Correct |
102 ms |
179940 KB |
Output is correct |
10 |
Correct |
99 ms |
179396 KB |
Output is correct |
11 |
Correct |
98 ms |
179404 KB |
Output is correct |
12 |
Correct |
109 ms |
179268 KB |
Output is correct |
13 |
Correct |
100 ms |
179396 KB |
Output is correct |
14 |
Correct |
106 ms |
179400 KB |
Output is correct |
15 |
Correct |
102 ms |
179556 KB |
Output is correct |
16 |
Correct |
100 ms |
179636 KB |
Output is correct |
17 |
Correct |
100 ms |
179612 KB |
Output is correct |
18 |
Correct |
101 ms |
179660 KB |
Output is correct |
19 |
Correct |
107 ms |
179640 KB |
Output is correct |
20 |
Correct |
108 ms |
179696 KB |
Output is correct |
21 |
Correct |
99 ms |
179244 KB |
Output is correct |
22 |
Correct |
102 ms |
179796 KB |
Output is correct |
23 |
Correct |
100 ms |
179732 KB |
Output is correct |
24 |
Correct |
103 ms |
179648 KB |
Output is correct |
25 |
Correct |
100 ms |
179524 KB |
Output is correct |
26 |
Correct |
99 ms |
179308 KB |
Output is correct |
27 |
Correct |
100 ms |
179140 KB |
Output is correct |
28 |
Correct |
101 ms |
179396 KB |
Output is correct |
29 |
Correct |
100 ms |
179396 KB |
Output is correct |
30 |
Correct |
102 ms |
179240 KB |
Output is correct |
31 |
Correct |
4365 ms |
332248 KB |
Output is correct |
32 |
Correct |
165 ms |
183612 KB |
Output is correct |
33 |
Correct |
2408 ms |
272824 KB |
Output is correct |
34 |
Correct |
4604 ms |
337460 KB |
Output is correct |
35 |
Correct |
3656 ms |
311640 KB |
Output is correct |
36 |
Correct |
2294 ms |
268112 KB |
Output is correct |
37 |
Correct |
2443 ms |
282064 KB |
Output is correct |
38 |
Correct |
1443 ms |
264520 KB |
Output is correct |
39 |
Correct |
1178 ms |
270480 KB |
Output is correct |
40 |
Correct |
1131 ms |
264828 KB |
Output is correct |
41 |
Execution timed out |
5045 ms |
328224 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5096 ms |
711992 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
5100 ms |
724776 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
178756 KB |
Output is correct |
2 |
Correct |
99 ms |
178780 KB |
Output is correct |
3 |
Correct |
94 ms |
178704 KB |
Output is correct |
4 |
Correct |
95 ms |
178884 KB |
Output is correct |
5 |
Correct |
96 ms |
178784 KB |
Output is correct |
6 |
Correct |
101 ms |
179396 KB |
Output is correct |
7 |
Correct |
102 ms |
179968 KB |
Output is correct |
8 |
Correct |
106 ms |
179688 KB |
Output is correct |
9 |
Correct |
102 ms |
179940 KB |
Output is correct |
10 |
Correct |
99 ms |
179396 KB |
Output is correct |
11 |
Correct |
98 ms |
179404 KB |
Output is correct |
12 |
Correct |
109 ms |
179268 KB |
Output is correct |
13 |
Correct |
100 ms |
179396 KB |
Output is correct |
14 |
Correct |
106 ms |
179400 KB |
Output is correct |
15 |
Correct |
102 ms |
179556 KB |
Output is correct |
16 |
Correct |
100 ms |
179636 KB |
Output is correct |
17 |
Correct |
100 ms |
179612 KB |
Output is correct |
18 |
Correct |
101 ms |
179660 KB |
Output is correct |
19 |
Correct |
107 ms |
179640 KB |
Output is correct |
20 |
Correct |
108 ms |
179696 KB |
Output is correct |
21 |
Correct |
99 ms |
179244 KB |
Output is correct |
22 |
Correct |
102 ms |
179796 KB |
Output is correct |
23 |
Correct |
100 ms |
179732 KB |
Output is correct |
24 |
Correct |
103 ms |
179648 KB |
Output is correct |
25 |
Correct |
100 ms |
179524 KB |
Output is correct |
26 |
Correct |
99 ms |
179308 KB |
Output is correct |
27 |
Correct |
100 ms |
179140 KB |
Output is correct |
28 |
Correct |
101 ms |
179396 KB |
Output is correct |
29 |
Correct |
100 ms |
179396 KB |
Output is correct |
30 |
Correct |
102 ms |
179240 KB |
Output is correct |
31 |
Correct |
4365 ms |
332248 KB |
Output is correct |
32 |
Correct |
165 ms |
183612 KB |
Output is correct |
33 |
Correct |
2408 ms |
272824 KB |
Output is correct |
34 |
Correct |
4604 ms |
337460 KB |
Output is correct |
35 |
Correct |
3656 ms |
311640 KB |
Output is correct |
36 |
Correct |
2294 ms |
268112 KB |
Output is correct |
37 |
Correct |
2443 ms |
282064 KB |
Output is correct |
38 |
Correct |
1443 ms |
264520 KB |
Output is correct |
39 |
Correct |
1178 ms |
270480 KB |
Output is correct |
40 |
Correct |
1131 ms |
264828 KB |
Output is correct |
41 |
Execution timed out |
5045 ms |
328224 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
96 ms |
178756 KB |
Output is correct |
2 |
Correct |
99 ms |
178780 KB |
Output is correct |
3 |
Correct |
94 ms |
178704 KB |
Output is correct |
4 |
Correct |
95 ms |
178884 KB |
Output is correct |
5 |
Correct |
96 ms |
178784 KB |
Output is correct |
6 |
Correct |
101 ms |
179396 KB |
Output is correct |
7 |
Correct |
102 ms |
179968 KB |
Output is correct |
8 |
Correct |
106 ms |
179688 KB |
Output is correct |
9 |
Correct |
102 ms |
179940 KB |
Output is correct |
10 |
Correct |
99 ms |
179396 KB |
Output is correct |
11 |
Correct |
98 ms |
179404 KB |
Output is correct |
12 |
Correct |
109 ms |
179268 KB |
Output is correct |
13 |
Correct |
100 ms |
179396 KB |
Output is correct |
14 |
Correct |
106 ms |
179400 KB |
Output is correct |
15 |
Correct |
102 ms |
179556 KB |
Output is correct |
16 |
Correct |
100 ms |
179636 KB |
Output is correct |
17 |
Correct |
100 ms |
179612 KB |
Output is correct |
18 |
Correct |
101 ms |
179660 KB |
Output is correct |
19 |
Correct |
107 ms |
179640 KB |
Output is correct |
20 |
Correct |
108 ms |
179696 KB |
Output is correct |
21 |
Correct |
99 ms |
179244 KB |
Output is correct |
22 |
Correct |
102 ms |
179796 KB |
Output is correct |
23 |
Correct |
100 ms |
179732 KB |
Output is correct |
24 |
Correct |
103 ms |
179648 KB |
Output is correct |
25 |
Correct |
100 ms |
179524 KB |
Output is correct |
26 |
Correct |
99 ms |
179308 KB |
Output is correct |
27 |
Correct |
100 ms |
179140 KB |
Output is correct |
28 |
Correct |
101 ms |
179396 KB |
Output is correct |
29 |
Correct |
100 ms |
179396 KB |
Output is correct |
30 |
Correct |
102 ms |
179240 KB |
Output is correct |
31 |
Correct |
4365 ms |
332248 KB |
Output is correct |
32 |
Correct |
165 ms |
183612 KB |
Output is correct |
33 |
Correct |
2408 ms |
272824 KB |
Output is correct |
34 |
Correct |
4604 ms |
337460 KB |
Output is correct |
35 |
Correct |
3656 ms |
311640 KB |
Output is correct |
36 |
Correct |
2294 ms |
268112 KB |
Output is correct |
37 |
Correct |
2443 ms |
282064 KB |
Output is correct |
38 |
Correct |
1443 ms |
264520 KB |
Output is correct |
39 |
Correct |
1178 ms |
270480 KB |
Output is correct |
40 |
Correct |
1131 ms |
264828 KB |
Output is correct |
41 |
Execution timed out |
5045 ms |
328224 KB |
Time limit exceeded |
42 |
Halted |
0 ms |
0 KB |
- |