#include<iostream>
#include<set>
#include<map>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
#define fi first
#define se second
const int N=3e5+1,Q=3e5+1,K=3e5+1;
int n,k,q;
struct pt{
ll x,tp,t;//<0: add, =0: qry, >0: rmv
};
bool operator<(pt x,pt y){
return x.t<y.t;
}
pt a[2*N];
multiset<ll>s[K];
map<pair<ll,ll>,vector<ll> >mp;//should clear after inserting all stores :)
struct upd{
ll x,l,r,pos;
};
bool operator<(upd x,upd y){
return x.pos<y.pos;
}
vector<upd>pve,nve;
string f(ll x){
string ret;
if(x<=-1e8) return "-inf";
if(x>=1e8) return "inf";
if(x==0) ret+='0';
while(x>0){
char c=x%10+48;
x/=10;
ret=c+ret;
}
return ret;
}
void add(ll xl,ll xr,ll t){
mp[{xl,xr}].push_back(t);
}
void rmv(ll xl,ll xr,ll t){
ll p=mp[{xl,xr}].back();
mp[{xl,xr}].pop_back();
if(mp[{xl,xr}].empty()) mp.erase({xl,xr});
if(p==t) return;t--;
upd pl={-xl,p,t,-(xl+xr)/2};
upd nl={xr,p,t,(xl+xr+1)/2};
pve.push_back(pl);nve.push_back(nl);
}
ll ans[Q];
pair<pair<ll,ll>,int>b[Q];
pair<ll,ll>c[Q];
ll st[1<<20];
void init(int id,int l,int r){
st[id]=-1e9;
if(l==r) return;
int mid=(l+r)/2;
init(id*2,l,mid);init(id*2+1,mid+1,r);
}
void upd(int id,int l,int r,int ql,int qr,ll v){
if(l>qr || r<ql) return;
if(ql<=l && r<=qr){
st[id]=max(st[id],v);
return;
}
int mid=(l+r)/2;
upd(id*2,l,mid,ql,qr,v);
upd(id*2+1,mid+1,r,ql,qr,v);
}
ll qry(int id,int l,int r,int p){
if(l==r) return st[id];
int mid=(l+r)/2;
if(p<=mid) return max(st[id],qry(id*2,l,mid,p));
else return max(st[id],qry(id*2+1,mid+1,r,p));
}
int main(){
ios::sync_with_stdio(false);
cin >> n >> k >> q;
for(int i=1; i<=n ;i++){
ll x,tp,u,v;cin >> x >> tp >> u >> v;
a[i*2-1]={x,-tp,u};
a[i*2]={x,tp,v+1};
}
for(int i=1; i<=k ;i++){
s[i].insert(-1e9);
s[i].insert(1e9);
mp[{(ll)-1e9,(ll)1e9}].push_back(1);
}
sort(a+1,a+2*n+1);
for(int i=1; i<=2*n ;i++){
ll x=a[i].x,tp=a[i].tp,t=a[i].t;
if(tp<0){
tp=-tp;
auto it=s[tp].lower_bound(x);
auto it2=it;--it2;
rmv(*it2,*it,t);add(*it2,x,t);add(x,*it,t);
s[tp].insert(x);
}
else{
s[tp].erase(s[tp].lower_bound(x));
auto it=s[tp].lower_bound(x);
auto it2=it;--it2;
rmv(*it2,x,t);rmv(x,*it,t);add(*it2,*it,t);
}
}
for(int i=1; i<=k ;i++) rmv(-1e9,1e9,1e9);
sort(nve.begin(),nve.end());
sort(pve.begin(),pve.end());
for(int i=1; i<=q ;i++){
cin >> b[i].fi.fi >> b[i].fi.se;
b[i].se=i;
c[i]={b[i].fi.se,i};
}
sort(c+1,c+q+1);
for(int i=1; i<=q ;i++) b[c[i].se].fi.se=i;
sort(b+1,b+q+1);
int ptr=0;
init(1,1,q);
for(int i=1; i<=q ;i++){
while(ptr<nve.size() && nve[ptr].pos<=b[i].fi.fi){
int l=lower_bound(c+1,c+q+1,(pair<ll,ll>){nve[ptr].l,0LL})-c;
int r=lower_bound(c+1,c+q+1,(pair<ll,ll>){nve[ptr].r+1,0LL})-c-1;
if(l<=r) upd(1,1,q,l,r,nve[ptr].x);
ptr++;
}
ans[b[i].se]=max(ans[b[i].se],qry(1,1,q,b[i].fi.se)-b[i].fi.fi);
}
init(1,1,q);
reverse(b+1,b+q+1);
for(int i=1; i<=q ;i++) b[i].fi.fi=-b[i].fi.fi;
ptr=0;
for(int i=1; i<=q ;i++){
while(ptr<pve.size() && pve[ptr].pos<=b[i].fi.fi){
int l=lower_bound(c+1,c+q+1,(pair<ll,ll>){pve[ptr].l,0LL})-c;
int r=lower_bound(c+1,c+q+1,(pair<ll,ll>){pve[ptr].r+1,0LL})-c-1;
if(l<=r) upd(1,1,q,l,r,pve[ptr].x);
ptr++;
}
ans[b[i].se]=max(ans[b[i].se],qry(1,1,q,b[i].fi.se)-b[i].fi.fi);
}
for(int i=1; i<=q ;i++){
if(ans[i]>=(ll)1e8) cout << "-1\n";
else cout << ans[i] << '\n';
}
}
Compilation message
new_home.cpp: In function 'void rmv(ll, ll, ll)':
new_home.cpp:47:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if(p==t) return;t--;
^~
new_home.cpp:47:18: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
if(p==t) return;t--;
^
new_home.cpp: In function 'int main()':
new_home.cpp:122:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ptr<nve.size() && nve[ptr].pos<=b[i].fi.fi){
~~~^~~~~~~~~~~
new_home.cpp:135:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ptr<pve.size() && pve[ptr].pos<=b[i].fi.fi){
~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14572 KB |
Output is correct |
2 |
Correct |
13 ms |
14456 KB |
Output is correct |
3 |
Correct |
13 ms |
14456 KB |
Output is correct |
4 |
Correct |
14 ms |
14456 KB |
Output is correct |
5 |
Correct |
13 ms |
14584 KB |
Output is correct |
6 |
Correct |
13 ms |
14712 KB |
Output is correct |
7 |
Correct |
13 ms |
14712 KB |
Output is correct |
8 |
Correct |
13 ms |
14840 KB |
Output is correct |
9 |
Correct |
13 ms |
14840 KB |
Output is correct |
10 |
Correct |
13 ms |
14840 KB |
Output is correct |
11 |
Correct |
13 ms |
14712 KB |
Output is correct |
12 |
Correct |
13 ms |
14712 KB |
Output is correct |
13 |
Correct |
16 ms |
14712 KB |
Output is correct |
14 |
Correct |
13 ms |
14712 KB |
Output is correct |
15 |
Correct |
13 ms |
14712 KB |
Output is correct |
16 |
Correct |
13 ms |
14840 KB |
Output is correct |
17 |
Correct |
13 ms |
14712 KB |
Output is correct |
18 |
Correct |
13 ms |
14840 KB |
Output is correct |
19 |
Correct |
13 ms |
14712 KB |
Output is correct |
20 |
Correct |
13 ms |
14712 KB |
Output is correct |
21 |
Correct |
12 ms |
14712 KB |
Output is correct |
22 |
Correct |
16 ms |
14840 KB |
Output is correct |
23 |
Correct |
13 ms |
14712 KB |
Output is correct |
24 |
Correct |
16 ms |
14724 KB |
Output is correct |
25 |
Correct |
16 ms |
14712 KB |
Output is correct |
26 |
Correct |
16 ms |
14712 KB |
Output is correct |
27 |
Correct |
14 ms |
14712 KB |
Output is correct |
28 |
Correct |
13 ms |
14712 KB |
Output is correct |
29 |
Correct |
12 ms |
14712 KB |
Output is correct |
30 |
Correct |
12 ms |
14456 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14572 KB |
Output is correct |
2 |
Correct |
13 ms |
14456 KB |
Output is correct |
3 |
Correct |
13 ms |
14456 KB |
Output is correct |
4 |
Correct |
14 ms |
14456 KB |
Output is correct |
5 |
Correct |
13 ms |
14584 KB |
Output is correct |
6 |
Correct |
13 ms |
14712 KB |
Output is correct |
7 |
Correct |
13 ms |
14712 KB |
Output is correct |
8 |
Correct |
13 ms |
14840 KB |
Output is correct |
9 |
Correct |
13 ms |
14840 KB |
Output is correct |
10 |
Correct |
13 ms |
14840 KB |
Output is correct |
11 |
Correct |
13 ms |
14712 KB |
Output is correct |
12 |
Correct |
13 ms |
14712 KB |
Output is correct |
13 |
Correct |
16 ms |
14712 KB |
Output is correct |
14 |
Correct |
13 ms |
14712 KB |
Output is correct |
15 |
Correct |
13 ms |
14712 KB |
Output is correct |
16 |
Correct |
13 ms |
14840 KB |
Output is correct |
17 |
Correct |
13 ms |
14712 KB |
Output is correct |
18 |
Correct |
13 ms |
14840 KB |
Output is correct |
19 |
Correct |
13 ms |
14712 KB |
Output is correct |
20 |
Correct |
13 ms |
14712 KB |
Output is correct |
21 |
Correct |
12 ms |
14712 KB |
Output is correct |
22 |
Correct |
16 ms |
14840 KB |
Output is correct |
23 |
Correct |
13 ms |
14712 KB |
Output is correct |
24 |
Correct |
16 ms |
14724 KB |
Output is correct |
25 |
Correct |
16 ms |
14712 KB |
Output is correct |
26 |
Correct |
16 ms |
14712 KB |
Output is correct |
27 |
Correct |
14 ms |
14712 KB |
Output is correct |
28 |
Correct |
13 ms |
14712 KB |
Output is correct |
29 |
Correct |
12 ms |
14712 KB |
Output is correct |
30 |
Correct |
12 ms |
14456 KB |
Output is correct |
31 |
Correct |
607 ms |
45392 KB |
Output is correct |
32 |
Correct |
129 ms |
25440 KB |
Output is correct |
33 |
Correct |
556 ms |
39208 KB |
Output is correct |
34 |
Correct |
600 ms |
39472 KB |
Output is correct |
35 |
Correct |
747 ms |
45364 KB |
Output is correct |
36 |
Correct |
727 ms |
45224 KB |
Output is correct |
37 |
Correct |
454 ms |
36548 KB |
Output is correct |
38 |
Correct |
464 ms |
36392 KB |
Output is correct |
39 |
Correct |
348 ms |
35828 KB |
Output is correct |
40 |
Correct |
363 ms |
35876 KB |
Output is correct |
41 |
Correct |
392 ms |
36284 KB |
Output is correct |
42 |
Correct |
425 ms |
36160 KB |
Output is correct |
43 |
Correct |
109 ms |
29668 KB |
Output is correct |
44 |
Correct |
400 ms |
36232 KB |
Output is correct |
45 |
Correct |
366 ms |
36268 KB |
Output is correct |
46 |
Correct |
316 ms |
36328 KB |
Output is correct |
47 |
Correct |
233 ms |
35236 KB |
Output is correct |
48 |
Correct |
222 ms |
34872 KB |
Output is correct |
49 |
Correct |
275 ms |
35320 KB |
Output is correct |
50 |
Correct |
319 ms |
35884 KB |
Output is correct |
51 |
Correct |
266 ms |
35416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3826 ms |
115336 KB |
Output is correct |
2 |
Correct |
2843 ms |
130968 KB |
Output is correct |
3 |
Correct |
2469 ms |
237732 KB |
Output is correct |
4 |
Correct |
2958 ms |
169272 KB |
Output is correct |
5 |
Correct |
2415 ms |
130736 KB |
Output is correct |
6 |
Correct |
2748 ms |
131064 KB |
Output is correct |
7 |
Correct |
2819 ms |
237856 KB |
Output is correct |
8 |
Correct |
2560 ms |
139064 KB |
Output is correct |
9 |
Correct |
1879 ms |
115632 KB |
Output is correct |
10 |
Correct |
2639 ms |
122752 KB |
Output is correct |
11 |
Correct |
1498 ms |
129552 KB |
Output is correct |
12 |
Correct |
1742 ms |
131528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
5068 ms |
139412 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14572 KB |
Output is correct |
2 |
Correct |
13 ms |
14456 KB |
Output is correct |
3 |
Correct |
13 ms |
14456 KB |
Output is correct |
4 |
Correct |
14 ms |
14456 KB |
Output is correct |
5 |
Correct |
13 ms |
14584 KB |
Output is correct |
6 |
Correct |
13 ms |
14712 KB |
Output is correct |
7 |
Correct |
13 ms |
14712 KB |
Output is correct |
8 |
Correct |
13 ms |
14840 KB |
Output is correct |
9 |
Correct |
13 ms |
14840 KB |
Output is correct |
10 |
Correct |
13 ms |
14840 KB |
Output is correct |
11 |
Correct |
13 ms |
14712 KB |
Output is correct |
12 |
Correct |
13 ms |
14712 KB |
Output is correct |
13 |
Correct |
16 ms |
14712 KB |
Output is correct |
14 |
Correct |
13 ms |
14712 KB |
Output is correct |
15 |
Correct |
13 ms |
14712 KB |
Output is correct |
16 |
Correct |
13 ms |
14840 KB |
Output is correct |
17 |
Correct |
13 ms |
14712 KB |
Output is correct |
18 |
Correct |
13 ms |
14840 KB |
Output is correct |
19 |
Correct |
13 ms |
14712 KB |
Output is correct |
20 |
Correct |
13 ms |
14712 KB |
Output is correct |
21 |
Correct |
12 ms |
14712 KB |
Output is correct |
22 |
Correct |
16 ms |
14840 KB |
Output is correct |
23 |
Correct |
13 ms |
14712 KB |
Output is correct |
24 |
Correct |
16 ms |
14724 KB |
Output is correct |
25 |
Correct |
16 ms |
14712 KB |
Output is correct |
26 |
Correct |
16 ms |
14712 KB |
Output is correct |
27 |
Correct |
14 ms |
14712 KB |
Output is correct |
28 |
Correct |
13 ms |
14712 KB |
Output is correct |
29 |
Correct |
12 ms |
14712 KB |
Output is correct |
30 |
Correct |
12 ms |
14456 KB |
Output is correct |
31 |
Correct |
607 ms |
45392 KB |
Output is correct |
32 |
Correct |
129 ms |
25440 KB |
Output is correct |
33 |
Correct |
556 ms |
39208 KB |
Output is correct |
34 |
Correct |
600 ms |
39472 KB |
Output is correct |
35 |
Correct |
747 ms |
45364 KB |
Output is correct |
36 |
Correct |
727 ms |
45224 KB |
Output is correct |
37 |
Correct |
454 ms |
36548 KB |
Output is correct |
38 |
Correct |
464 ms |
36392 KB |
Output is correct |
39 |
Correct |
348 ms |
35828 KB |
Output is correct |
40 |
Correct |
363 ms |
35876 KB |
Output is correct |
41 |
Correct |
392 ms |
36284 KB |
Output is correct |
42 |
Correct |
425 ms |
36160 KB |
Output is correct |
43 |
Correct |
109 ms |
29668 KB |
Output is correct |
44 |
Correct |
400 ms |
36232 KB |
Output is correct |
45 |
Correct |
366 ms |
36268 KB |
Output is correct |
46 |
Correct |
316 ms |
36328 KB |
Output is correct |
47 |
Correct |
233 ms |
35236 KB |
Output is correct |
48 |
Correct |
222 ms |
34872 KB |
Output is correct |
49 |
Correct |
275 ms |
35320 KB |
Output is correct |
50 |
Correct |
319 ms |
35884 KB |
Output is correct |
51 |
Correct |
266 ms |
35416 KB |
Output is correct |
52 |
Correct |
633 ms |
57092 KB |
Output is correct |
53 |
Correct |
508 ms |
51144 KB |
Output is correct |
54 |
Correct |
567 ms |
50832 KB |
Output is correct |
55 |
Correct |
400 ms |
44944 KB |
Output is correct |
56 |
Correct |
488 ms |
49348 KB |
Output is correct |
57 |
Correct |
446 ms |
38904 KB |
Output is correct |
58 |
Correct |
477 ms |
44948 KB |
Output is correct |
59 |
Correct |
440 ms |
49216 KB |
Output is correct |
60 |
Correct |
544 ms |
38812 KB |
Output is correct |
61 |
Correct |
128 ms |
44252 KB |
Output is correct |
62 |
Correct |
516 ms |
57124 KB |
Output is correct |
63 |
Correct |
690 ms |
47044 KB |
Output is correct |
64 |
Correct |
695 ms |
47888 KB |
Output is correct |
65 |
Correct |
484 ms |
40024 KB |
Output is correct |
66 |
Correct |
435 ms |
36428 KB |
Output is correct |
67 |
Correct |
220 ms |
29892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
14572 KB |
Output is correct |
2 |
Correct |
13 ms |
14456 KB |
Output is correct |
3 |
Correct |
13 ms |
14456 KB |
Output is correct |
4 |
Correct |
14 ms |
14456 KB |
Output is correct |
5 |
Correct |
13 ms |
14584 KB |
Output is correct |
6 |
Correct |
13 ms |
14712 KB |
Output is correct |
7 |
Correct |
13 ms |
14712 KB |
Output is correct |
8 |
Correct |
13 ms |
14840 KB |
Output is correct |
9 |
Correct |
13 ms |
14840 KB |
Output is correct |
10 |
Correct |
13 ms |
14840 KB |
Output is correct |
11 |
Correct |
13 ms |
14712 KB |
Output is correct |
12 |
Correct |
13 ms |
14712 KB |
Output is correct |
13 |
Correct |
16 ms |
14712 KB |
Output is correct |
14 |
Correct |
13 ms |
14712 KB |
Output is correct |
15 |
Correct |
13 ms |
14712 KB |
Output is correct |
16 |
Correct |
13 ms |
14840 KB |
Output is correct |
17 |
Correct |
13 ms |
14712 KB |
Output is correct |
18 |
Correct |
13 ms |
14840 KB |
Output is correct |
19 |
Correct |
13 ms |
14712 KB |
Output is correct |
20 |
Correct |
13 ms |
14712 KB |
Output is correct |
21 |
Correct |
12 ms |
14712 KB |
Output is correct |
22 |
Correct |
16 ms |
14840 KB |
Output is correct |
23 |
Correct |
13 ms |
14712 KB |
Output is correct |
24 |
Correct |
16 ms |
14724 KB |
Output is correct |
25 |
Correct |
16 ms |
14712 KB |
Output is correct |
26 |
Correct |
16 ms |
14712 KB |
Output is correct |
27 |
Correct |
14 ms |
14712 KB |
Output is correct |
28 |
Correct |
13 ms |
14712 KB |
Output is correct |
29 |
Correct |
12 ms |
14712 KB |
Output is correct |
30 |
Correct |
12 ms |
14456 KB |
Output is correct |
31 |
Correct |
607 ms |
45392 KB |
Output is correct |
32 |
Correct |
129 ms |
25440 KB |
Output is correct |
33 |
Correct |
556 ms |
39208 KB |
Output is correct |
34 |
Correct |
600 ms |
39472 KB |
Output is correct |
35 |
Correct |
747 ms |
45364 KB |
Output is correct |
36 |
Correct |
727 ms |
45224 KB |
Output is correct |
37 |
Correct |
454 ms |
36548 KB |
Output is correct |
38 |
Correct |
464 ms |
36392 KB |
Output is correct |
39 |
Correct |
348 ms |
35828 KB |
Output is correct |
40 |
Correct |
363 ms |
35876 KB |
Output is correct |
41 |
Correct |
392 ms |
36284 KB |
Output is correct |
42 |
Correct |
425 ms |
36160 KB |
Output is correct |
43 |
Correct |
109 ms |
29668 KB |
Output is correct |
44 |
Correct |
400 ms |
36232 KB |
Output is correct |
45 |
Correct |
366 ms |
36268 KB |
Output is correct |
46 |
Correct |
316 ms |
36328 KB |
Output is correct |
47 |
Correct |
233 ms |
35236 KB |
Output is correct |
48 |
Correct |
222 ms |
34872 KB |
Output is correct |
49 |
Correct |
275 ms |
35320 KB |
Output is correct |
50 |
Correct |
319 ms |
35884 KB |
Output is correct |
51 |
Correct |
266 ms |
35416 KB |
Output is correct |
52 |
Correct |
3826 ms |
115336 KB |
Output is correct |
53 |
Correct |
2843 ms |
130968 KB |
Output is correct |
54 |
Correct |
2469 ms |
237732 KB |
Output is correct |
55 |
Correct |
2958 ms |
169272 KB |
Output is correct |
56 |
Correct |
2415 ms |
130736 KB |
Output is correct |
57 |
Correct |
2748 ms |
131064 KB |
Output is correct |
58 |
Correct |
2819 ms |
237856 KB |
Output is correct |
59 |
Correct |
2560 ms |
139064 KB |
Output is correct |
60 |
Correct |
1879 ms |
115632 KB |
Output is correct |
61 |
Correct |
2639 ms |
122752 KB |
Output is correct |
62 |
Correct |
1498 ms |
129552 KB |
Output is correct |
63 |
Correct |
1742 ms |
131528 KB |
Output is correct |
64 |
Execution timed out |
5068 ms |
139412 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |