Submission #966658

# Submission time Handle Problem Language Result Execution time Memory
966658 2024-04-20T07:49:38 Z emptypringlescan New Home (APIO18_new_home) C++17
100 / 100
2773 ms 325392 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
priority_queue<int> bruh[300005],del[300005];
int cnum;
struct node{
	int s,e,m;
	int val,pnum;
	node *l, *r;
	node(int S, int E){
		s=S; e=E; m=(s+e)/2;
		val=0;
		l=r=NULL;
		if(s==e){
			pnum=cnum;
			cnum++;
		}
	}
	
	void update(int S, int V, int R){
		if(s==e){
			if(R!=-1) del[pnum].push(R);
			if(V!=-1) bruh[pnum].push(V);
			while(!del[pnum].empty()&&!bruh[pnum].empty()&&bruh[pnum].top()==del[pnum].top()){
				bruh[pnum].pop();
				del[pnum].pop();
			}
			if(!bruh[pnum].empty()) val=bruh[pnum].top();
			else val=0;
			return;
		}
		if(S<=m){
			if(!l) l=new node(s,m);
			l->update(S,V,R);
		}
		else{
			if(!r) r=new node(m+1,e);
			r->update(S,V,R);
		}
		val=max((l?l->val:0),(r?r->val:0));
	}
	int query(int S){
		if(s==e){
			if(s==0) return max(S,val-S);
			else return S-s;
		}
		if(S<=m) return (l?l->query(S):0);
		else{
			if(!l||l->val-S<=S-m) return max((l?max(l->val-S,0ll):0),(r?r->query(S):0ll));
			else return l->query(S);
		}
	}
} *root;
int32_t main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,q,k;
    cin >> n >> k >> q;
    vector<pair<pair<int,int>,pair<int,int> > > up; //time,loc,type,+-1
    for(int i=0; i<n; i++){
		int a,b,c,d;
		cin >> a >> b >> c >> d;
		up.push_back({{c,a},{b,1}});
		up.push_back({{d+1,a},{b,-1}});
	}
	sort(up.begin(),up.end());
	root=new node(0,1e8+5);
	pair<pair<int,int>,int> qu[q]; //time,loc,index
	for(int i=0; i<q; i++){
		int a,b;
		cin >> a >> b;
		qu[i]={{b,a},i};
	}
	sort(qu,qu+q);
	multiset<int> occ[k+1];
	multiset<int>::iterator it;
	for(int i=1; i<=k; i++){
		occ[i].insert(0);
		occ[i].insert(1e16);
		root->update(0,1e16,-1);
	}
	int ans[q],cnt=0;
	for(int i=0; i<q; i++){
		while(cnt<(int)up.size()&&up[cnt].first.first<=qu[i].first.first){
			if(up[cnt].second.second==1){
				int t=up[cnt].second.first,p=up[cnt].first.second;
				it=occ[t].upper_bound(p);
				int nxt=*it;
				it--;
				int prv=*it;
				root->update(prv,p,nxt);
				root->update(p,nxt,-1);
				occ[t].insert(p);
			}
			else{
				int t=up[cnt].second.first,p=up[cnt].first.second;
				occ[t].erase(occ[t].find(p));
				it=occ[t].upper_bound(p);
				int nxt=*it;
				it--;
				int prv=*it;
				root->update(prv,nxt,p);
				root->update(p,-1,nxt);
			}
			cnt++;
		}
		int loc=qu[i].first.second;
		if(bruh[0].top()==1e16){
			ans[qu[i].second]=-1;
			continue;
		}/*
		int lo=0,hi=1e8,mid;
		while(lo<hi){
			mid=(lo+hi)/2;
			int big=root->query(max(loc-mid-1,0ll));
			if(big<=loc+mid) assert(big>=loc-mid),hi=mid;
			else lo=mid+1;
		}*/
		ans[qu[i].second]=root->query(loc);
	}
	for(int i=0; i<q; i++) cout << ans[i] << '\n';
}
/*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 4 ms 19036 KB Output is correct
2 Correct 4 ms 19036 KB Output is correct
3 Correct 5 ms 19032 KB Output is correct
4 Correct 5 ms 19036 KB Output is correct
5 Correct 5 ms 19292 KB Output is correct
6 Correct 6 ms 19828 KB Output is correct
7 Correct 5 ms 19804 KB Output is correct
8 Correct 6 ms 19804 KB Output is correct
9 Correct 6 ms 19804 KB Output is correct
10 Correct 7 ms 19804 KB Output is correct
11 Correct 6 ms 19804 KB Output is correct
12 Correct 5 ms 19800 KB Output is correct
13 Correct 7 ms 19804 KB Output is correct
14 Correct 6 ms 20060 KB Output is correct
15 Correct 5 ms 19804 KB Output is correct
16 Correct 6 ms 19768 KB Output is correct
17 Correct 6 ms 19804 KB Output is correct
18 Correct 5 ms 19804 KB Output is correct
19 Correct 6 ms 19804 KB Output is correct
20 Correct 6 ms 19804 KB Output is correct
21 Correct 4 ms 19292 KB Output is correct
22 Correct 6 ms 19804 KB Output is correct
23 Correct 5 ms 19800 KB Output is correct
24 Correct 5 ms 19800 KB Output is correct
25 Correct 7 ms 20004 KB Output is correct
26 Correct 5 ms 19804 KB Output is correct
27 Correct 5 ms 19292 KB Output is correct
28 Correct 6 ms 19804 KB Output is correct
29 Correct 5 ms 19712 KB Output is correct
30 Correct 5 ms 19548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 4 ms 19036 KB Output is correct
3 Correct 5 ms 19032 KB Output is correct
4 Correct 5 ms 19036 KB Output is correct
5 Correct 5 ms 19292 KB Output is correct
6 Correct 6 ms 19828 KB Output is correct
7 Correct 5 ms 19804 KB Output is correct
8 Correct 6 ms 19804 KB Output is correct
9 Correct 6 ms 19804 KB Output is correct
10 Correct 7 ms 19804 KB Output is correct
11 Correct 6 ms 19804 KB Output is correct
12 Correct 5 ms 19800 KB Output is correct
13 Correct 7 ms 19804 KB Output is correct
14 Correct 6 ms 20060 KB Output is correct
15 Correct 5 ms 19804 KB Output is correct
16 Correct 6 ms 19768 KB Output is correct
17 Correct 6 ms 19804 KB Output is correct
18 Correct 5 ms 19804 KB Output is correct
19 Correct 6 ms 19804 KB Output is correct
20 Correct 6 ms 19804 KB Output is correct
21 Correct 4 ms 19292 KB Output is correct
22 Correct 6 ms 19804 KB Output is correct
23 Correct 5 ms 19800 KB Output is correct
24 Correct 5 ms 19800 KB Output is correct
25 Correct 7 ms 20004 KB Output is correct
26 Correct 5 ms 19804 KB Output is correct
27 Correct 5 ms 19292 KB Output is correct
28 Correct 6 ms 19804 KB Output is correct
29 Correct 5 ms 19712 KB Output is correct
30 Correct 5 ms 19548 KB Output is correct
31 Correct 400 ms 79552 KB Output is correct
32 Correct 93 ms 28592 KB Output is correct
33 Correct 359 ms 77380 KB Output is correct
34 Correct 357 ms 78032 KB Output is correct
35 Correct 383 ms 79188 KB Output is correct
36 Correct 414 ms 79064 KB Output is correct
37 Correct 227 ms 77248 KB Output is correct
38 Correct 230 ms 77512 KB Output is correct
39 Correct 199 ms 77232 KB Output is correct
40 Correct 198 ms 77128 KB Output is correct
41 Correct 216 ms 77688 KB Output is correct
42 Correct 212 ms 77916 KB Output is correct
43 Correct 68 ms 30908 KB Output is correct
44 Correct 216 ms 77812 KB Output is correct
45 Correct 205 ms 77524 KB Output is correct
46 Correct 197 ms 77248 KB Output is correct
47 Correct 158 ms 75020 KB Output is correct
48 Correct 158 ms 74464 KB Output is correct
49 Correct 174 ms 75760 KB Output is correct
50 Correct 176 ms 77052 KB Output is correct
51 Correct 187 ms 75452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1277 ms 283244 KB Output is correct
2 Correct 964 ms 274268 KB Output is correct
3 Correct 861 ms 314392 KB Output is correct
4 Correct 1173 ms 289428 KB Output is correct
5 Correct 889 ms 275584 KB Output is correct
6 Correct 918 ms 274180 KB Output is correct
7 Correct 872 ms 313992 KB Output is correct
8 Correct 1141 ms 288420 KB Output is correct
9 Correct 1264 ms 280488 KB Output is correct
10 Correct 919 ms 275968 KB Output is correct
11 Correct 782 ms 270216 KB Output is correct
12 Correct 833 ms 275572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2554 ms 277804 KB Output is correct
2 Correct 480 ms 73184 KB Output is correct
3 Correct 2396 ms 276396 KB Output is correct
4 Correct 1519 ms 323228 KB Output is correct
5 Correct 2128 ms 288612 KB Output is correct
6 Correct 2067 ms 295656 KB Output is correct
7 Correct 2036 ms 275108 KB Output is correct
8 Correct 2303 ms 275704 KB Output is correct
9 Correct 1563 ms 325204 KB Output is correct
10 Correct 2090 ms 289564 KB Output is correct
11 Correct 2355 ms 280332 KB Output is correct
12 Correct 2349 ms 276504 KB Output is correct
13 Correct 1042 ms 269548 KB Output is correct
14 Correct 962 ms 264828 KB Output is correct
15 Correct 1120 ms 270956 KB Output is correct
16 Correct 1361 ms 274952 KB Output is correct
17 Correct 1172 ms 270180 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 4 ms 19036 KB Output is correct
3 Correct 5 ms 19032 KB Output is correct
4 Correct 5 ms 19036 KB Output is correct
5 Correct 5 ms 19292 KB Output is correct
6 Correct 6 ms 19828 KB Output is correct
7 Correct 5 ms 19804 KB Output is correct
8 Correct 6 ms 19804 KB Output is correct
9 Correct 6 ms 19804 KB Output is correct
10 Correct 7 ms 19804 KB Output is correct
11 Correct 6 ms 19804 KB Output is correct
12 Correct 5 ms 19800 KB Output is correct
13 Correct 7 ms 19804 KB Output is correct
14 Correct 6 ms 20060 KB Output is correct
15 Correct 5 ms 19804 KB Output is correct
16 Correct 6 ms 19768 KB Output is correct
17 Correct 6 ms 19804 KB Output is correct
18 Correct 5 ms 19804 KB Output is correct
19 Correct 6 ms 19804 KB Output is correct
20 Correct 6 ms 19804 KB Output is correct
21 Correct 4 ms 19292 KB Output is correct
22 Correct 6 ms 19804 KB Output is correct
23 Correct 5 ms 19800 KB Output is correct
24 Correct 5 ms 19800 KB Output is correct
25 Correct 7 ms 20004 KB Output is correct
26 Correct 5 ms 19804 KB Output is correct
27 Correct 5 ms 19292 KB Output is correct
28 Correct 6 ms 19804 KB Output is correct
29 Correct 5 ms 19712 KB Output is correct
30 Correct 5 ms 19548 KB Output is correct
31 Correct 400 ms 79552 KB Output is correct
32 Correct 93 ms 28592 KB Output is correct
33 Correct 359 ms 77380 KB Output is correct
34 Correct 357 ms 78032 KB Output is correct
35 Correct 383 ms 79188 KB Output is correct
36 Correct 414 ms 79064 KB Output is correct
37 Correct 227 ms 77248 KB Output is correct
38 Correct 230 ms 77512 KB Output is correct
39 Correct 199 ms 77232 KB Output is correct
40 Correct 198 ms 77128 KB Output is correct
41 Correct 216 ms 77688 KB Output is correct
42 Correct 212 ms 77916 KB Output is correct
43 Correct 68 ms 30908 KB Output is correct
44 Correct 216 ms 77812 KB Output is correct
45 Correct 205 ms 77524 KB Output is correct
46 Correct 197 ms 77248 KB Output is correct
47 Correct 158 ms 75020 KB Output is correct
48 Correct 158 ms 74464 KB Output is correct
49 Correct 174 ms 75760 KB Output is correct
50 Correct 176 ms 77052 KB Output is correct
51 Correct 187 ms 75452 KB Output is correct
52 Correct 283 ms 88120 KB Output is correct
53 Correct 296 ms 86624 KB Output is correct
54 Correct 330 ms 82740 KB Output is correct
55 Correct 250 ms 81408 KB Output is correct
56 Correct 244 ms 82348 KB Output is correct
57 Correct 231 ms 78780 KB Output is correct
58 Correct 240 ms 80572 KB Output is correct
59 Correct 247 ms 81620 KB Output is correct
60 Correct 246 ms 78724 KB Output is correct
61 Correct 99 ms 40032 KB Output is correct
62 Correct 277 ms 88252 KB Output is correct
63 Correct 315 ms 84312 KB Output is correct
64 Correct 330 ms 82368 KB Output is correct
65 Correct 333 ms 79204 KB Output is correct
66 Correct 254 ms 77916 KB Output is correct
67 Correct 113 ms 30660 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 19036 KB Output is correct
2 Correct 4 ms 19036 KB Output is correct
3 Correct 5 ms 19032 KB Output is correct
4 Correct 5 ms 19036 KB Output is correct
5 Correct 5 ms 19292 KB Output is correct
6 Correct 6 ms 19828 KB Output is correct
7 Correct 5 ms 19804 KB Output is correct
8 Correct 6 ms 19804 KB Output is correct
9 Correct 6 ms 19804 KB Output is correct
10 Correct 7 ms 19804 KB Output is correct
11 Correct 6 ms 19804 KB Output is correct
12 Correct 5 ms 19800 KB Output is correct
13 Correct 7 ms 19804 KB Output is correct
14 Correct 6 ms 20060 KB Output is correct
15 Correct 5 ms 19804 KB Output is correct
16 Correct 6 ms 19768 KB Output is correct
17 Correct 6 ms 19804 KB Output is correct
18 Correct 5 ms 19804 KB Output is correct
19 Correct 6 ms 19804 KB Output is correct
20 Correct 6 ms 19804 KB Output is correct
21 Correct 4 ms 19292 KB Output is correct
22 Correct 6 ms 19804 KB Output is correct
23 Correct 5 ms 19800 KB Output is correct
24 Correct 5 ms 19800 KB Output is correct
25 Correct 7 ms 20004 KB Output is correct
26 Correct 5 ms 19804 KB Output is correct
27 Correct 5 ms 19292 KB Output is correct
28 Correct 6 ms 19804 KB Output is correct
29 Correct 5 ms 19712 KB Output is correct
30 Correct 5 ms 19548 KB Output is correct
31 Correct 400 ms 79552 KB Output is correct
32 Correct 93 ms 28592 KB Output is correct
33 Correct 359 ms 77380 KB Output is correct
34 Correct 357 ms 78032 KB Output is correct
35 Correct 383 ms 79188 KB Output is correct
36 Correct 414 ms 79064 KB Output is correct
37 Correct 227 ms 77248 KB Output is correct
38 Correct 230 ms 77512 KB Output is correct
39 Correct 199 ms 77232 KB Output is correct
40 Correct 198 ms 77128 KB Output is correct
41 Correct 216 ms 77688 KB Output is correct
42 Correct 212 ms 77916 KB Output is correct
43 Correct 68 ms 30908 KB Output is correct
44 Correct 216 ms 77812 KB Output is correct
45 Correct 205 ms 77524 KB Output is correct
46 Correct 197 ms 77248 KB Output is correct
47 Correct 158 ms 75020 KB Output is correct
48 Correct 158 ms 74464 KB Output is correct
49 Correct 174 ms 75760 KB Output is correct
50 Correct 176 ms 77052 KB Output is correct
51 Correct 187 ms 75452 KB Output is correct
52 Correct 1277 ms 283244 KB Output is correct
53 Correct 964 ms 274268 KB Output is correct
54 Correct 861 ms 314392 KB Output is correct
55 Correct 1173 ms 289428 KB Output is correct
56 Correct 889 ms 275584 KB Output is correct
57 Correct 918 ms 274180 KB Output is correct
58 Correct 872 ms 313992 KB Output is correct
59 Correct 1141 ms 288420 KB Output is correct
60 Correct 1264 ms 280488 KB Output is correct
61 Correct 919 ms 275968 KB Output is correct
62 Correct 782 ms 270216 KB Output is correct
63 Correct 833 ms 275572 KB Output is correct
64 Correct 2554 ms 277804 KB Output is correct
65 Correct 480 ms 73184 KB Output is correct
66 Correct 2396 ms 276396 KB Output is correct
67 Correct 1519 ms 323228 KB Output is correct
68 Correct 2128 ms 288612 KB Output is correct
69 Correct 2067 ms 295656 KB Output is correct
70 Correct 2036 ms 275108 KB Output is correct
71 Correct 2303 ms 275704 KB Output is correct
72 Correct 1563 ms 325204 KB Output is correct
73 Correct 2090 ms 289564 KB Output is correct
74 Correct 2355 ms 280332 KB Output is correct
75 Correct 2349 ms 276504 KB Output is correct
76 Correct 1042 ms 269548 KB Output is correct
77 Correct 962 ms 264828 KB Output is correct
78 Correct 1120 ms 270956 KB Output is correct
79 Correct 1361 ms 274952 KB Output is correct
80 Correct 1172 ms 270180 KB Output is correct
81 Correct 283 ms 88120 KB Output is correct
82 Correct 296 ms 86624 KB Output is correct
83 Correct 330 ms 82740 KB Output is correct
84 Correct 250 ms 81408 KB Output is correct
85 Correct 244 ms 82348 KB Output is correct
86 Correct 231 ms 78780 KB Output is correct
87 Correct 240 ms 80572 KB Output is correct
88 Correct 247 ms 81620 KB Output is correct
89 Correct 246 ms 78724 KB Output is correct
90 Correct 99 ms 40032 KB Output is correct
91 Correct 277 ms 88252 KB Output is correct
92 Correct 315 ms 84312 KB Output is correct
93 Correct 330 ms 82368 KB Output is correct
94 Correct 333 ms 79204 KB Output is correct
95 Correct 254 ms 77916 KB Output is correct
96 Correct 113 ms 30660 KB Output is correct
97 Correct 1741 ms 325392 KB Output is correct
98 Correct 471 ms 64424 KB Output is correct
99 Correct 2773 ms 267668 KB Output is correct
100 Correct 1602 ms 315808 KB Output is correct
101 Correct 1977 ms 294960 KB Output is correct
102 Correct 2763 ms 274588 KB Output is correct
103 Correct 1771 ms 268196 KB Output is correct
104 Correct 1739 ms 266728 KB Output is correct
105 Correct 1070 ms 266152 KB Output is correct
106 Correct 1063 ms 266716 KB Output is correct
107 Correct 1354 ms 286628 KB Output is correct
108 Correct 1416 ms 294200 KB Output is correct
109 Correct 1263 ms 277672 KB Output is correct
110 Correct 1425 ms 286192 KB Output is correct
111 Correct 1550 ms 290956 KB Output is correct
112 Correct 1317 ms 273828 KB Output is correct
113 Correct 388 ms 127652 KB Output is correct
114 Correct 1623 ms 324624 KB Output is correct
115 Correct 1868 ms 301372 KB Output is correct
116 Correct 1947 ms 294428 KB Output is correct
117 Correct 1965 ms 279464 KB Output is correct
118 Correct 1616 ms 270740 KB Output is correct
119 Correct 548 ms 76324 KB Output is correct
120 Correct 726 ms 249372 KB Output is correct
121 Correct 822 ms 258116 KB Output is correct
122 Correct 802 ms 255940 KB Output is correct
123 Correct 874 ms 261668 KB Output is correct
124 Correct 922 ms 268716 KB Output is correct
125 Correct 909 ms 261884 KB Output is correct
126 Correct 1010 ms 268024 KB Output is correct