#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define MAXN 1000007
using namespace std;
const int inf=1e9+7;
int n,k,q,x,t,l,r,ans[MAXN];
struct event{
int x,type,tim,id;
inline friend bool operator < (event fr,event sc){
if(fr.tim!=sc.tim)return fr.tim<sc.tim;
else return fr.type<sc.type;
}
}s[MAXN];
multiset<int> stores[MAXN];
/*void solve(){
tim++; ask.clear();
for(event e:z){
if((e.type==0 or e.type==2) and false){
sp[e.id]=tim;
}else if(e.type==1){
ask.push_back(e);
}
}
poss.clear(); st.clear(); ts.clear();
for(int i=1;i<=k;i++){
if(sp[i]==tim)poss.push_back(i);
else{
vector<int> w;
for(int f:stores[i]){
w.push_back(f);
}
if(w.empty()){
st.push_back({0,inf});
ts.push_back({inf,2*inf});
break;
}
st.push_back({0,w[0]});
for(int f=0;f<w.size()-1;f++){
int pos=(w[f]+w[f+1])/2+(w[f]+w[f+1])%2;
int val=(w[f+1]-w[f])/2;
st.push_back({pos,pos+val});
ts.push_back({pos-(w[f]+w[f+1])%2,val-(pos-(w[f]+w[f+1])%2)});
}
ts.push_back({inf,-w.back()});
}
}
if(!st.empty()){
sort(st.begin(),st.end());
sort(ts.begin(),ts.end());
sort(ask.begin(),ask.end(),cmp);
int pt=0;
while(!pq.empty())pq.pop();
for(int i=0;i<ask.size();i++){
while(pt<st.size() and st[pt].first<=ask[i].x){
pq.push(st[pt].second);
pt++;
}
ans[ask[i].id]=max(ans[ask[i].id],pq.top()-ask[i].x);
}
pt=ts.size()-1;
while(!pq.empty())pq.pop();
for(int i=ask.size()-1;i>=0;i--){
while(pt>=0 and ts[pt].first>=ask[i].x){
pq.push(ts[pt].second);
pt--;
}
ans[ask[i].id]=max(ans[ask[i].id],pq.top()+ask[i].x);
}
}
for(event e:z){
if(e.type==0){
stores[e.id].insert(e.x);
}else if(e.type==2){
stores[e.id].erase(stores[e.id].find(e.x));
}else{
for(int i:poss){
ans[e.id]=max(ans[e.id],calc(e.x,i));
}
}
}
}*/
struct node{
int l,r;
int val;
int setid;
};
int num,pt,ft;
node tree[4*MAXN];
multiset<int> vals[MAXN];
void update(int v,int l,int r,int pos,int val,bool t){
if(l==r){
if(tree[v].setid==0){
ft++; tree[v].setid=ft;
}
int id=tree[v].setid;
if(t)vals[id].insert(val);
else vals[id].erase(vals[id].find(val));
if(!vals[id].empty())tree[v].val=*vals[id].rbegin();
else tree[v].val=-inf;
}else{
int tt=(l+r)/2;
if(tree[v].l==0){
num++; tree[v].l=num;
tree[num].val=-inf;
}
if(tree[v].r==0){
num++; tree[v].r=num;
tree[num].val=-inf;
}
if(pos<=tt)update(tree[v].l,l,tt,pos,val,t);
else update(tree[v].r,tt+1,r,pos,val,t);
tree[v].val=max(tree[tree[v].l].val,tree[tree[v].r].val);
}
}
int getmax(int v,int l,int r,int ll,int rr){
if(ll>rr or v==0)return -inf;
if(l==ll and r==rr){
return tree[v].val;
}else{
int tt=(l+r)/2;
return max( getmax(tree[v].l,l,tt,ll,min(tt,rr)) , getmax(tree[v].r,tt+1,r,max(tt+1,ll),rr) );
}
}
void addline(int pos,int val){
update(1,0,inf,pos,val,true);
}
void remline(int pos,int val){
update(1,0,inf,pos,val,false);
}
int up(int s){
if(s>=0)return s/2+s%2;
else return s/2;
}
int down(int s){
if(s>=0)return s/2;
else return s/2+s%2;
}
void add(int x,int type,bool dir){
stores[type].insert(x);
auto it=stores[type].find(x);
it--;
int lpos=*it;
it++; it++;
int rpos=*it;
if(!dir){
remline(up(lpos+rpos),(rpos-lpos)/2+up(lpos+rpos));
addline(up(lpos+x),(x-lpos)/2+up(lpos+x));
addline(up(x+rpos),(rpos-x)/2+up(x+rpos));
}else{
remline(down(lpos+rpos),(rpos-lpos)/2-down(lpos+rpos));
addline(down(lpos+x),(x-lpos)/2-down(lpos+x));
addline(down(x+rpos),(rpos-x)/2-down(x+rpos));
}
}
void rem(int x,int type,bool dir){
auto it=stores[type].find(x);
it--;
int lpos=*it;
it++; it++;
int rpos=*it;
if(!dir){
addline(up(lpos+rpos),(rpos-lpos)/2+up(lpos+rpos));
remline(up(lpos+x),(x-lpos)/2+up(lpos+x));
remline(up(x+rpos),(rpos-x)/2+up(x+rpos));
}else{
addline(down(lpos+rpos),(rpos-lpos)/2-down(lpos+rpos));
remline(down(lpos+x),(x-lpos)/2-down(lpos+x));
remline(down(x+rpos),(rpos-x)/2-down(x+rpos));
}
stores[type].erase(stores[type].find(x));
}
int maxs(int l,int r){
return getmax(1,0,inf,l,r);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>k>>q;
for(int i=1;i<=k;i++){
stores[i].insert(0);
stores[i].insert(inf);
}
for(int i=1;i<=n;i++){
cin>>x>>t>>l>>r;
x+=inf/2;
pt++; s[pt]={x,0,l,t};
pt++; s[pt]={x,2,r,t};
}
for(int i=1;i<=q;i++){
cin>>x>>t;
x+=inf/2;
pt++; s[pt]={x,1,t,i};
}
sort(s+1,s+pt+1);
num=1;
for(int i=1;i<=k;i++)addline(up(0+inf),inf/2+up(0+inf));
for(int i=1;i<=pt;i++){
if(s[i].type==0){
add(s[i].x,s[i].id,false);
}else if(s[i].type==2){
rem(s[i].x,s[i].id,false);
}else{
ans[s[i].id]=max(ans[s[i].id],maxs(0,s[i].x)-s[i].x);
}
}
for(int i=1;i<=k;i++){
remline(up(0+inf),inf/2+up(0+inf));
addline(down(0+inf),inf/2-down(0+inf));
}
for(int i=1;i<=pt;i++){
if(s[i].type==0){
add(s[i].x,s[i].id,true);
}else if(s[i].type==2){
rem(s[i].x,s[i].id,true);
}else{
ans[s[i].id]=max(ans[s[i].id],maxs(s[i].x,inf)+s[i].x);
}
}
for(int i=1;i<=q;i++){
if(ans[i]>200000000)cout<<"-1\n";
else cout<<ans[i]<<"\n";
}
return 0;
}
/*
4 2 4
3 1 1 10
9 2 2 4
7 2 5 7
4 1 8 10
5 3
5 6
5 9
1 10
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
94288 KB |
Output is correct |
2 |
Correct |
35 ms |
94300 KB |
Output is correct |
3 |
Correct |
35 ms |
94268 KB |
Output is correct |
4 |
Correct |
36 ms |
94300 KB |
Output is correct |
5 |
Correct |
38 ms |
94400 KB |
Output is correct |
6 |
Correct |
37 ms |
95068 KB |
Output is correct |
7 |
Correct |
38 ms |
94812 KB |
Output is correct |
8 |
Correct |
38 ms |
94812 KB |
Output is correct |
9 |
Correct |
38 ms |
94800 KB |
Output is correct |
10 |
Correct |
39 ms |
95060 KB |
Output is correct |
11 |
Correct |
37 ms |
94800 KB |
Output is correct |
12 |
Correct |
38 ms |
94812 KB |
Output is correct |
13 |
Correct |
40 ms |
94912 KB |
Output is correct |
14 |
Correct |
37 ms |
94808 KB |
Output is correct |
15 |
Correct |
38 ms |
95320 KB |
Output is correct |
16 |
Correct |
38 ms |
94804 KB |
Output is correct |
17 |
Correct |
37 ms |
95056 KB |
Output is correct |
18 |
Correct |
38 ms |
94948 KB |
Output is correct |
19 |
Correct |
37 ms |
94824 KB |
Output is correct |
20 |
Correct |
38 ms |
95060 KB |
Output is correct |
21 |
Correct |
43 ms |
94292 KB |
Output is correct |
22 |
Correct |
39 ms |
94980 KB |
Output is correct |
23 |
Correct |
38 ms |
95056 KB |
Output is correct |
24 |
Correct |
38 ms |
95056 KB |
Output is correct |
25 |
Correct |
38 ms |
95060 KB |
Output is correct |
26 |
Correct |
37 ms |
95060 KB |
Output is correct |
27 |
Correct |
37 ms |
94296 KB |
Output is correct |
28 |
Correct |
39 ms |
94800 KB |
Output is correct |
29 |
Correct |
38 ms |
94804 KB |
Output is correct |
30 |
Correct |
37 ms |
94896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
94288 KB |
Output is correct |
2 |
Correct |
35 ms |
94300 KB |
Output is correct |
3 |
Correct |
35 ms |
94268 KB |
Output is correct |
4 |
Correct |
36 ms |
94300 KB |
Output is correct |
5 |
Correct |
38 ms |
94400 KB |
Output is correct |
6 |
Correct |
37 ms |
95068 KB |
Output is correct |
7 |
Correct |
38 ms |
94812 KB |
Output is correct |
8 |
Correct |
38 ms |
94812 KB |
Output is correct |
9 |
Correct |
38 ms |
94800 KB |
Output is correct |
10 |
Correct |
39 ms |
95060 KB |
Output is correct |
11 |
Correct |
37 ms |
94800 KB |
Output is correct |
12 |
Correct |
38 ms |
94812 KB |
Output is correct |
13 |
Correct |
40 ms |
94912 KB |
Output is correct |
14 |
Correct |
37 ms |
94808 KB |
Output is correct |
15 |
Correct |
38 ms |
95320 KB |
Output is correct |
16 |
Correct |
38 ms |
94804 KB |
Output is correct |
17 |
Correct |
37 ms |
95056 KB |
Output is correct |
18 |
Correct |
38 ms |
94948 KB |
Output is correct |
19 |
Correct |
37 ms |
94824 KB |
Output is correct |
20 |
Correct |
38 ms |
95060 KB |
Output is correct |
21 |
Correct |
43 ms |
94292 KB |
Output is correct |
22 |
Correct |
39 ms |
94980 KB |
Output is correct |
23 |
Correct |
38 ms |
95056 KB |
Output is correct |
24 |
Correct |
38 ms |
95056 KB |
Output is correct |
25 |
Correct |
38 ms |
95060 KB |
Output is correct |
26 |
Correct |
37 ms |
95060 KB |
Output is correct |
27 |
Correct |
37 ms |
94296 KB |
Output is correct |
28 |
Correct |
39 ms |
94800 KB |
Output is correct |
29 |
Correct |
38 ms |
94804 KB |
Output is correct |
30 |
Correct |
37 ms |
94896 KB |
Output is correct |
31 |
Correct |
648 ms |
159768 KB |
Output is correct |
32 |
Correct |
356 ms |
100692 KB |
Output is correct |
33 |
Correct |
555 ms |
154448 KB |
Output is correct |
34 |
Correct |
570 ms |
155388 KB |
Output is correct |
35 |
Correct |
634 ms |
159456 KB |
Output is correct |
36 |
Correct |
663 ms |
158800 KB |
Output is correct |
37 |
Correct |
468 ms |
153020 KB |
Output is correct |
38 |
Correct |
442 ms |
152656 KB |
Output is correct |
39 |
Correct |
372 ms |
152912 KB |
Output is correct |
40 |
Correct |
369 ms |
152524 KB |
Output is correct |
41 |
Correct |
470 ms |
160336 KB |
Output is correct |
42 |
Correct |
479 ms |
160592 KB |
Output is correct |
43 |
Correct |
270 ms |
105968 KB |
Output is correct |
44 |
Correct |
462 ms |
160600 KB |
Output is correct |
45 |
Correct |
460 ms |
160632 KB |
Output is correct |
46 |
Correct |
406 ms |
160636 KB |
Output is correct |
47 |
Correct |
325 ms |
154964 KB |
Output is correct |
48 |
Correct |
289 ms |
155648 KB |
Output is correct |
49 |
Correct |
311 ms |
158172 KB |
Output is correct |
50 |
Correct |
363 ms |
158292 KB |
Output is correct |
51 |
Correct |
328 ms |
158176 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
553 ms |
396628 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
581 ms |
381012 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
94288 KB |
Output is correct |
2 |
Correct |
35 ms |
94300 KB |
Output is correct |
3 |
Correct |
35 ms |
94268 KB |
Output is correct |
4 |
Correct |
36 ms |
94300 KB |
Output is correct |
5 |
Correct |
38 ms |
94400 KB |
Output is correct |
6 |
Correct |
37 ms |
95068 KB |
Output is correct |
7 |
Correct |
38 ms |
94812 KB |
Output is correct |
8 |
Correct |
38 ms |
94812 KB |
Output is correct |
9 |
Correct |
38 ms |
94800 KB |
Output is correct |
10 |
Correct |
39 ms |
95060 KB |
Output is correct |
11 |
Correct |
37 ms |
94800 KB |
Output is correct |
12 |
Correct |
38 ms |
94812 KB |
Output is correct |
13 |
Correct |
40 ms |
94912 KB |
Output is correct |
14 |
Correct |
37 ms |
94808 KB |
Output is correct |
15 |
Correct |
38 ms |
95320 KB |
Output is correct |
16 |
Correct |
38 ms |
94804 KB |
Output is correct |
17 |
Correct |
37 ms |
95056 KB |
Output is correct |
18 |
Correct |
38 ms |
94948 KB |
Output is correct |
19 |
Correct |
37 ms |
94824 KB |
Output is correct |
20 |
Correct |
38 ms |
95060 KB |
Output is correct |
21 |
Correct |
43 ms |
94292 KB |
Output is correct |
22 |
Correct |
39 ms |
94980 KB |
Output is correct |
23 |
Correct |
38 ms |
95056 KB |
Output is correct |
24 |
Correct |
38 ms |
95056 KB |
Output is correct |
25 |
Correct |
38 ms |
95060 KB |
Output is correct |
26 |
Correct |
37 ms |
95060 KB |
Output is correct |
27 |
Correct |
37 ms |
94296 KB |
Output is correct |
28 |
Correct |
39 ms |
94800 KB |
Output is correct |
29 |
Correct |
38 ms |
94804 KB |
Output is correct |
30 |
Correct |
37 ms |
94896 KB |
Output is correct |
31 |
Correct |
648 ms |
159768 KB |
Output is correct |
32 |
Correct |
356 ms |
100692 KB |
Output is correct |
33 |
Correct |
555 ms |
154448 KB |
Output is correct |
34 |
Correct |
570 ms |
155388 KB |
Output is correct |
35 |
Correct |
634 ms |
159456 KB |
Output is correct |
36 |
Correct |
663 ms |
158800 KB |
Output is correct |
37 |
Correct |
468 ms |
153020 KB |
Output is correct |
38 |
Correct |
442 ms |
152656 KB |
Output is correct |
39 |
Correct |
372 ms |
152912 KB |
Output is correct |
40 |
Correct |
369 ms |
152524 KB |
Output is correct |
41 |
Correct |
470 ms |
160336 KB |
Output is correct |
42 |
Correct |
479 ms |
160592 KB |
Output is correct |
43 |
Correct |
270 ms |
105968 KB |
Output is correct |
44 |
Correct |
462 ms |
160600 KB |
Output is correct |
45 |
Correct |
460 ms |
160632 KB |
Output is correct |
46 |
Correct |
406 ms |
160636 KB |
Output is correct |
47 |
Correct |
325 ms |
154964 KB |
Output is correct |
48 |
Correct |
289 ms |
155648 KB |
Output is correct |
49 |
Correct |
311 ms |
158172 KB |
Output is correct |
50 |
Correct |
363 ms |
158292 KB |
Output is correct |
51 |
Correct |
328 ms |
158176 KB |
Output is correct |
52 |
Correct |
553 ms |
153384 KB |
Output is correct |
53 |
Correct |
526 ms |
149812 KB |
Output is correct |
54 |
Correct |
644 ms |
158804 KB |
Output is correct |
55 |
Correct |
519 ms |
158676 KB |
Output is correct |
56 |
Correct |
532 ms |
157016 KB |
Output is correct |
57 |
Correct |
484 ms |
160232 KB |
Output is correct |
58 |
Correct |
517 ms |
158544 KB |
Output is correct |
59 |
Correct |
518 ms |
157084 KB |
Output is correct |
60 |
Correct |
491 ms |
160340 KB |
Output is correct |
61 |
Correct |
342 ms |
114512 KB |
Output is correct |
62 |
Correct |
550 ms |
153504 KB |
Output is correct |
63 |
Correct |
661 ms |
159828 KB |
Output is correct |
64 |
Correct |
676 ms |
160856 KB |
Output is correct |
65 |
Correct |
570 ms |
160848 KB |
Output is correct |
66 |
Correct |
504 ms |
160600 KB |
Output is correct |
67 |
Correct |
334 ms |
100948 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
37 ms |
94288 KB |
Output is correct |
2 |
Correct |
35 ms |
94300 KB |
Output is correct |
3 |
Correct |
35 ms |
94268 KB |
Output is correct |
4 |
Correct |
36 ms |
94300 KB |
Output is correct |
5 |
Correct |
38 ms |
94400 KB |
Output is correct |
6 |
Correct |
37 ms |
95068 KB |
Output is correct |
7 |
Correct |
38 ms |
94812 KB |
Output is correct |
8 |
Correct |
38 ms |
94812 KB |
Output is correct |
9 |
Correct |
38 ms |
94800 KB |
Output is correct |
10 |
Correct |
39 ms |
95060 KB |
Output is correct |
11 |
Correct |
37 ms |
94800 KB |
Output is correct |
12 |
Correct |
38 ms |
94812 KB |
Output is correct |
13 |
Correct |
40 ms |
94912 KB |
Output is correct |
14 |
Correct |
37 ms |
94808 KB |
Output is correct |
15 |
Correct |
38 ms |
95320 KB |
Output is correct |
16 |
Correct |
38 ms |
94804 KB |
Output is correct |
17 |
Correct |
37 ms |
95056 KB |
Output is correct |
18 |
Correct |
38 ms |
94948 KB |
Output is correct |
19 |
Correct |
37 ms |
94824 KB |
Output is correct |
20 |
Correct |
38 ms |
95060 KB |
Output is correct |
21 |
Correct |
43 ms |
94292 KB |
Output is correct |
22 |
Correct |
39 ms |
94980 KB |
Output is correct |
23 |
Correct |
38 ms |
95056 KB |
Output is correct |
24 |
Correct |
38 ms |
95056 KB |
Output is correct |
25 |
Correct |
38 ms |
95060 KB |
Output is correct |
26 |
Correct |
37 ms |
95060 KB |
Output is correct |
27 |
Correct |
37 ms |
94296 KB |
Output is correct |
28 |
Correct |
39 ms |
94800 KB |
Output is correct |
29 |
Correct |
38 ms |
94804 KB |
Output is correct |
30 |
Correct |
37 ms |
94896 KB |
Output is correct |
31 |
Correct |
648 ms |
159768 KB |
Output is correct |
32 |
Correct |
356 ms |
100692 KB |
Output is correct |
33 |
Correct |
555 ms |
154448 KB |
Output is correct |
34 |
Correct |
570 ms |
155388 KB |
Output is correct |
35 |
Correct |
634 ms |
159456 KB |
Output is correct |
36 |
Correct |
663 ms |
158800 KB |
Output is correct |
37 |
Correct |
468 ms |
153020 KB |
Output is correct |
38 |
Correct |
442 ms |
152656 KB |
Output is correct |
39 |
Correct |
372 ms |
152912 KB |
Output is correct |
40 |
Correct |
369 ms |
152524 KB |
Output is correct |
41 |
Correct |
470 ms |
160336 KB |
Output is correct |
42 |
Correct |
479 ms |
160592 KB |
Output is correct |
43 |
Correct |
270 ms |
105968 KB |
Output is correct |
44 |
Correct |
462 ms |
160600 KB |
Output is correct |
45 |
Correct |
460 ms |
160632 KB |
Output is correct |
46 |
Correct |
406 ms |
160636 KB |
Output is correct |
47 |
Correct |
325 ms |
154964 KB |
Output is correct |
48 |
Correct |
289 ms |
155648 KB |
Output is correct |
49 |
Correct |
311 ms |
158172 KB |
Output is correct |
50 |
Correct |
363 ms |
158292 KB |
Output is correct |
51 |
Correct |
328 ms |
158176 KB |
Output is correct |
52 |
Runtime error |
553 ms |
396628 KB |
Execution killed with signal 11 |
53 |
Halted |
0 ms |
0 KB |
- |