#include<bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#define MAXN 3000007
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
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
282192 KB |
Output is correct |
2 |
Correct |
113 ms |
282192 KB |
Output is correct |
3 |
Correct |
108 ms |
282196 KB |
Output is correct |
4 |
Correct |
112 ms |
282196 KB |
Output is correct |
5 |
Correct |
112 ms |
282196 KB |
Output is correct |
6 |
Correct |
114 ms |
282816 KB |
Output is correct |
7 |
Correct |
117 ms |
282628 KB |
Output is correct |
8 |
Correct |
120 ms |
282704 KB |
Output is correct |
9 |
Correct |
117 ms |
282704 KB |
Output is correct |
10 |
Correct |
110 ms |
282708 KB |
Output is correct |
11 |
Correct |
106 ms |
282708 KB |
Output is correct |
12 |
Correct |
106 ms |
282708 KB |
Output is correct |
13 |
Correct |
105 ms |
282704 KB |
Output is correct |
14 |
Correct |
109 ms |
282704 KB |
Output is correct |
15 |
Correct |
106 ms |
282704 KB |
Output is correct |
16 |
Correct |
107 ms |
282848 KB |
Output is correct |
17 |
Correct |
105 ms |
282708 KB |
Output is correct |
18 |
Correct |
107 ms |
282708 KB |
Output is correct |
19 |
Correct |
116 ms |
282704 KB |
Output is correct |
20 |
Correct |
117 ms |
282696 KB |
Output is correct |
21 |
Correct |
109 ms |
282144 KB |
Output is correct |
22 |
Correct |
109 ms |
282704 KB |
Output is correct |
23 |
Correct |
109 ms |
282796 KB |
Output is correct |
24 |
Correct |
107 ms |
282840 KB |
Output is correct |
25 |
Correct |
109 ms |
282896 KB |
Output is correct |
26 |
Correct |
112 ms |
282704 KB |
Output is correct |
27 |
Correct |
113 ms |
282176 KB |
Output is correct |
28 |
Correct |
109 ms |
282704 KB |
Output is correct |
29 |
Correct |
109 ms |
282688 KB |
Output is correct |
30 |
Correct |
111 ms |
282528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
282192 KB |
Output is correct |
2 |
Correct |
113 ms |
282192 KB |
Output is correct |
3 |
Correct |
108 ms |
282196 KB |
Output is correct |
4 |
Correct |
112 ms |
282196 KB |
Output is correct |
5 |
Correct |
112 ms |
282196 KB |
Output is correct |
6 |
Correct |
114 ms |
282816 KB |
Output is correct |
7 |
Correct |
117 ms |
282628 KB |
Output is correct |
8 |
Correct |
120 ms |
282704 KB |
Output is correct |
9 |
Correct |
117 ms |
282704 KB |
Output is correct |
10 |
Correct |
110 ms |
282708 KB |
Output is correct |
11 |
Correct |
106 ms |
282708 KB |
Output is correct |
12 |
Correct |
106 ms |
282708 KB |
Output is correct |
13 |
Correct |
105 ms |
282704 KB |
Output is correct |
14 |
Correct |
109 ms |
282704 KB |
Output is correct |
15 |
Correct |
106 ms |
282704 KB |
Output is correct |
16 |
Correct |
107 ms |
282848 KB |
Output is correct |
17 |
Correct |
105 ms |
282708 KB |
Output is correct |
18 |
Correct |
107 ms |
282708 KB |
Output is correct |
19 |
Correct |
116 ms |
282704 KB |
Output is correct |
20 |
Correct |
117 ms |
282696 KB |
Output is correct |
21 |
Correct |
109 ms |
282144 KB |
Output is correct |
22 |
Correct |
109 ms |
282704 KB |
Output is correct |
23 |
Correct |
109 ms |
282796 KB |
Output is correct |
24 |
Correct |
107 ms |
282840 KB |
Output is correct |
25 |
Correct |
109 ms |
282896 KB |
Output is correct |
26 |
Correct |
112 ms |
282704 KB |
Output is correct |
27 |
Correct |
113 ms |
282176 KB |
Output is correct |
28 |
Correct |
109 ms |
282704 KB |
Output is correct |
29 |
Correct |
109 ms |
282688 KB |
Output is correct |
30 |
Correct |
111 ms |
282528 KB |
Output is correct |
31 |
Correct |
742 ms |
344608 KB |
Output is correct |
32 |
Correct |
440 ms |
287640 KB |
Output is correct |
33 |
Correct |
677 ms |
339512 KB |
Output is correct |
34 |
Correct |
664 ms |
340464 KB |
Output is correct |
35 |
Correct |
725 ms |
344148 KB |
Output is correct |
36 |
Correct |
763 ms |
343704 KB |
Output is correct |
37 |
Correct |
540 ms |
337956 KB |
Output is correct |
38 |
Correct |
548 ms |
337492 KB |
Output is correct |
39 |
Correct |
433 ms |
338004 KB |
Output is correct |
40 |
Correct |
459 ms |
337568 KB |
Output is correct |
41 |
Correct |
551 ms |
345344 KB |
Output is correct |
42 |
Correct |
564 ms |
345424 KB |
Output is correct |
43 |
Correct |
349 ms |
291412 KB |
Output is correct |
44 |
Correct |
546 ms |
345680 KB |
Output is correct |
45 |
Correct |
541 ms |
345580 KB |
Output is correct |
46 |
Correct |
478 ms |
345428 KB |
Output is correct |
47 |
Correct |
365 ms |
340052 KB |
Output is correct |
48 |
Correct |
370 ms |
340780 KB |
Output is correct |
49 |
Correct |
390 ms |
343152 KB |
Output is correct |
50 |
Correct |
444 ms |
343120 KB |
Output is correct |
51 |
Correct |
390 ms |
343376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
3308 ms |
1019188 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2625 ms |
1023768 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
282192 KB |
Output is correct |
2 |
Correct |
113 ms |
282192 KB |
Output is correct |
3 |
Correct |
108 ms |
282196 KB |
Output is correct |
4 |
Correct |
112 ms |
282196 KB |
Output is correct |
5 |
Correct |
112 ms |
282196 KB |
Output is correct |
6 |
Correct |
114 ms |
282816 KB |
Output is correct |
7 |
Correct |
117 ms |
282628 KB |
Output is correct |
8 |
Correct |
120 ms |
282704 KB |
Output is correct |
9 |
Correct |
117 ms |
282704 KB |
Output is correct |
10 |
Correct |
110 ms |
282708 KB |
Output is correct |
11 |
Correct |
106 ms |
282708 KB |
Output is correct |
12 |
Correct |
106 ms |
282708 KB |
Output is correct |
13 |
Correct |
105 ms |
282704 KB |
Output is correct |
14 |
Correct |
109 ms |
282704 KB |
Output is correct |
15 |
Correct |
106 ms |
282704 KB |
Output is correct |
16 |
Correct |
107 ms |
282848 KB |
Output is correct |
17 |
Correct |
105 ms |
282708 KB |
Output is correct |
18 |
Correct |
107 ms |
282708 KB |
Output is correct |
19 |
Correct |
116 ms |
282704 KB |
Output is correct |
20 |
Correct |
117 ms |
282696 KB |
Output is correct |
21 |
Correct |
109 ms |
282144 KB |
Output is correct |
22 |
Correct |
109 ms |
282704 KB |
Output is correct |
23 |
Correct |
109 ms |
282796 KB |
Output is correct |
24 |
Correct |
107 ms |
282840 KB |
Output is correct |
25 |
Correct |
109 ms |
282896 KB |
Output is correct |
26 |
Correct |
112 ms |
282704 KB |
Output is correct |
27 |
Correct |
113 ms |
282176 KB |
Output is correct |
28 |
Correct |
109 ms |
282704 KB |
Output is correct |
29 |
Correct |
109 ms |
282688 KB |
Output is correct |
30 |
Correct |
111 ms |
282528 KB |
Output is correct |
31 |
Correct |
742 ms |
344608 KB |
Output is correct |
32 |
Correct |
440 ms |
287640 KB |
Output is correct |
33 |
Correct |
677 ms |
339512 KB |
Output is correct |
34 |
Correct |
664 ms |
340464 KB |
Output is correct |
35 |
Correct |
725 ms |
344148 KB |
Output is correct |
36 |
Correct |
763 ms |
343704 KB |
Output is correct |
37 |
Correct |
540 ms |
337956 KB |
Output is correct |
38 |
Correct |
548 ms |
337492 KB |
Output is correct |
39 |
Correct |
433 ms |
338004 KB |
Output is correct |
40 |
Correct |
459 ms |
337568 KB |
Output is correct |
41 |
Correct |
551 ms |
345344 KB |
Output is correct |
42 |
Correct |
564 ms |
345424 KB |
Output is correct |
43 |
Correct |
349 ms |
291412 KB |
Output is correct |
44 |
Correct |
546 ms |
345680 KB |
Output is correct |
45 |
Correct |
541 ms |
345580 KB |
Output is correct |
46 |
Correct |
478 ms |
345428 KB |
Output is correct |
47 |
Correct |
365 ms |
340052 KB |
Output is correct |
48 |
Correct |
370 ms |
340780 KB |
Output is correct |
49 |
Correct |
390 ms |
343152 KB |
Output is correct |
50 |
Correct |
444 ms |
343120 KB |
Output is correct |
51 |
Correct |
390 ms |
343376 KB |
Output is correct |
52 |
Correct |
697 ms |
341328 KB |
Output is correct |
53 |
Correct |
609 ms |
337744 KB |
Output is correct |
54 |
Correct |
698 ms |
346756 KB |
Output is correct |
55 |
Correct |
568 ms |
346700 KB |
Output is correct |
56 |
Correct |
568 ms |
344864 KB |
Output is correct |
57 |
Correct |
537 ms |
347984 KB |
Output is correct |
58 |
Correct |
553 ms |
346448 KB |
Output is correct |
59 |
Correct |
573 ms |
344916 KB |
Output is correct |
60 |
Correct |
563 ms |
347988 KB |
Output is correct |
61 |
Correct |
440 ms |
302288 KB |
Output is correct |
62 |
Correct |
654 ms |
341772 KB |
Output is correct |
63 |
Correct |
769 ms |
347732 KB |
Output is correct |
64 |
Correct |
714 ms |
348756 KB |
Output is correct |
65 |
Correct |
642 ms |
348656 KB |
Output is correct |
66 |
Correct |
551 ms |
348496 KB |
Output is correct |
67 |
Correct |
426 ms |
288848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
114 ms |
282192 KB |
Output is correct |
2 |
Correct |
113 ms |
282192 KB |
Output is correct |
3 |
Correct |
108 ms |
282196 KB |
Output is correct |
4 |
Correct |
112 ms |
282196 KB |
Output is correct |
5 |
Correct |
112 ms |
282196 KB |
Output is correct |
6 |
Correct |
114 ms |
282816 KB |
Output is correct |
7 |
Correct |
117 ms |
282628 KB |
Output is correct |
8 |
Correct |
120 ms |
282704 KB |
Output is correct |
9 |
Correct |
117 ms |
282704 KB |
Output is correct |
10 |
Correct |
110 ms |
282708 KB |
Output is correct |
11 |
Correct |
106 ms |
282708 KB |
Output is correct |
12 |
Correct |
106 ms |
282708 KB |
Output is correct |
13 |
Correct |
105 ms |
282704 KB |
Output is correct |
14 |
Correct |
109 ms |
282704 KB |
Output is correct |
15 |
Correct |
106 ms |
282704 KB |
Output is correct |
16 |
Correct |
107 ms |
282848 KB |
Output is correct |
17 |
Correct |
105 ms |
282708 KB |
Output is correct |
18 |
Correct |
107 ms |
282708 KB |
Output is correct |
19 |
Correct |
116 ms |
282704 KB |
Output is correct |
20 |
Correct |
117 ms |
282696 KB |
Output is correct |
21 |
Correct |
109 ms |
282144 KB |
Output is correct |
22 |
Correct |
109 ms |
282704 KB |
Output is correct |
23 |
Correct |
109 ms |
282796 KB |
Output is correct |
24 |
Correct |
107 ms |
282840 KB |
Output is correct |
25 |
Correct |
109 ms |
282896 KB |
Output is correct |
26 |
Correct |
112 ms |
282704 KB |
Output is correct |
27 |
Correct |
113 ms |
282176 KB |
Output is correct |
28 |
Correct |
109 ms |
282704 KB |
Output is correct |
29 |
Correct |
109 ms |
282688 KB |
Output is correct |
30 |
Correct |
111 ms |
282528 KB |
Output is correct |
31 |
Correct |
742 ms |
344608 KB |
Output is correct |
32 |
Correct |
440 ms |
287640 KB |
Output is correct |
33 |
Correct |
677 ms |
339512 KB |
Output is correct |
34 |
Correct |
664 ms |
340464 KB |
Output is correct |
35 |
Correct |
725 ms |
344148 KB |
Output is correct |
36 |
Correct |
763 ms |
343704 KB |
Output is correct |
37 |
Correct |
540 ms |
337956 KB |
Output is correct |
38 |
Correct |
548 ms |
337492 KB |
Output is correct |
39 |
Correct |
433 ms |
338004 KB |
Output is correct |
40 |
Correct |
459 ms |
337568 KB |
Output is correct |
41 |
Correct |
551 ms |
345344 KB |
Output is correct |
42 |
Correct |
564 ms |
345424 KB |
Output is correct |
43 |
Correct |
349 ms |
291412 KB |
Output is correct |
44 |
Correct |
546 ms |
345680 KB |
Output is correct |
45 |
Correct |
541 ms |
345580 KB |
Output is correct |
46 |
Correct |
478 ms |
345428 KB |
Output is correct |
47 |
Correct |
365 ms |
340052 KB |
Output is correct |
48 |
Correct |
370 ms |
340780 KB |
Output is correct |
49 |
Correct |
390 ms |
343152 KB |
Output is correct |
50 |
Correct |
444 ms |
343120 KB |
Output is correct |
51 |
Correct |
390 ms |
343376 KB |
Output is correct |
52 |
Runtime error |
3308 ms |
1019188 KB |
Execution killed with signal 11 |
53 |
Halted |
0 ms |
0 KB |
- |