Submission #62443

# Submission time Handle Problem Language Result Execution time Memory
62443 2018-07-28T13:20:57 Z tmwilliamlin168 New Home (APIO18_new_home) C++14
100 / 100
3564 ms 362312 KB
#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second

const int mxN=3e5, mxC=1e8;
int n, k, q, x[mxN+2], ts[2*mxN+1], e2i, st[2*(2*mxN+1)], ans[mxN];
vector<array<int, 2>> es1[mxN];
array<int, 3> qs[mxN];
array<int, 4> es2[4*mxN];

struct scmp {
	inline bool operator()(const int &a, const int &b) const {
		return x[a]==x[b]?a<b:x[a]<x[b];
	}
};
map<int, int, scmp> smp;

inline void solve() {
	for(int i=0; i<k; ++i) {
		smp[n+1]=0;
		for(auto a : es1[i]) {
			auto it1=smp.upper_bound(a[1]), it2=it1--;
			es2[e2i++]={(x[it1->fi]+x[it2->fi]+1)/2, x[it2->fi], it2->se, a[0]};
			it2->se=a[0];
			if(it1->fi==a[1]) {
				it2=it1--;
				es2[e2i++]={(x[it1->fi]+x[a[1]]+1)/2, x[a[1]], it2->se, a[0]};
				smp.erase(it2);
			} else
				smp[a[1]]=a[0];
		}
		es2[e2i++]={0, 2*mxC, smp[n+1], 2*n+1};
	}
	sort(es2, es2+e2i);
	for(int i1=0, i2=0; i1<q; ++i1) {
		while(es2[i2][0]<=qs[i1][0]) {
			for(int l=es2[i2][2]+2*n+1, r=es2[i2][3]+2*n+1; l<r; ++l/=2, r/=2) {
				if(l&1)
					st[l]=max(es2[i2][1], st[l]);
				if(r&1)
					st[r-1]=max(es2[i2][1], st[r-1]);
			}
			++i2;
		}
		for(int i=qs[i1][2]+2*n+1; i; i/=2)
			ans[qs[i1][1]]=max(st[i]-qs[i1][0], ans[qs[i1][1]]);
	}
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n >> k >> q;
	for(int i=0; i<n; ++i) {
		int ti;
		cin >> x[i] >> ti >> ts[2*i] >> ts[2*i+1], --ti, ++ts[2*i+1];
		es1[ti].push_back({ts[2*i], i});
		es1[ti].push_back({ts[2*i+1], i});
	}
	x[n]=-2*mxC;
	x[n+1]=2*mxC;
	sort(ts, ts+2*n+1);
	for(int i=0; i<k; ++i) {
		for(auto &a : es1[i])
			a[0]=lower_bound(ts, ts+2*n+1, a[0])-ts;
		sort(es1[i].begin(), es1[i].end());
	}
	for(int i=0; i<q; ++i) {
		cin >> qs[i][0] >> qs[i][2], qs[i][2]=upper_bound(ts, ts+2*n+1, qs[i][2])-ts-1;
		qs[i][1]=i;
	}
	sort(qs, qs+q);
	smp[n]=0;
	solve();
	for(int i=0; i<n; ++i)
		x[i]=mxC-x[i];
	for(int i=0; i<q; ++i)
		qs[i][0]=mxC-qs[i][0];
	reverse(qs, qs+q);
	e2i=0;
	memset(st, 0, 4*2*(2*n+1));
	solve();
	for(int i=0; i<q; ++i)
		cout << (ans[i]>=mxC?-1:ans[i]) << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 12 ms 7588 KB Output is correct
4 Correct 12 ms 7588 KB Output is correct
5 Correct 13 ms 7700 KB Output is correct
6 Correct 13 ms 7776 KB Output is correct
7 Correct 14 ms 7832 KB Output is correct
8 Correct 13 ms 7852 KB Output is correct
9 Correct 13 ms 7872 KB Output is correct
10 Correct 13 ms 7892 KB Output is correct
11 Correct 13 ms 7912 KB Output is correct
12 Correct 14 ms 7932 KB Output is correct
13 Correct 14 ms 7932 KB Output is correct
14 Correct 10 ms 7932 KB Output is correct
15 Correct 14 ms 7932 KB Output is correct
16 Correct 14 ms 8012 KB Output is correct
17 Correct 13 ms 8152 KB Output is correct
18 Correct 13 ms 8152 KB Output is correct
19 Correct 14 ms 8188 KB Output is correct
20 Correct 12 ms 8188 KB Output is correct
21 Correct 12 ms 8188 KB Output is correct
22 Correct 13 ms 8188 KB Output is correct
23 Correct 14 ms 8188 KB Output is correct
24 Correct 17 ms 8188 KB Output is correct
25 Correct 14 ms 8188 KB Output is correct
26 Correct 14 ms 8212 KB Output is correct
27 Correct 13 ms 8212 KB Output is correct
28 Correct 10 ms 8212 KB Output is correct
29 Correct 13 ms 8256 KB Output is correct
30 Correct 14 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 12 ms 7588 KB Output is correct
4 Correct 12 ms 7588 KB Output is correct
5 Correct 13 ms 7700 KB Output is correct
6 Correct 13 ms 7776 KB Output is correct
7 Correct 14 ms 7832 KB Output is correct
8 Correct 13 ms 7852 KB Output is correct
9 Correct 13 ms 7872 KB Output is correct
10 Correct 13 ms 7892 KB Output is correct
11 Correct 13 ms 7912 KB Output is correct
12 Correct 14 ms 7932 KB Output is correct
13 Correct 14 ms 7932 KB Output is correct
14 Correct 10 ms 7932 KB Output is correct
15 Correct 14 ms 7932 KB Output is correct
16 Correct 14 ms 8012 KB Output is correct
17 Correct 13 ms 8152 KB Output is correct
18 Correct 13 ms 8152 KB Output is correct
19 Correct 14 ms 8188 KB Output is correct
20 Correct 12 ms 8188 KB Output is correct
21 Correct 12 ms 8188 KB Output is correct
22 Correct 13 ms 8188 KB Output is correct
23 Correct 14 ms 8188 KB Output is correct
24 Correct 17 ms 8188 KB Output is correct
25 Correct 14 ms 8188 KB Output is correct
26 Correct 14 ms 8212 KB Output is correct
27 Correct 13 ms 8212 KB Output is correct
28 Correct 10 ms 8212 KB Output is correct
29 Correct 13 ms 8256 KB Output is correct
30 Correct 14 ms 8272 KB Output is correct
31 Correct 347 ms 18692 KB Output is correct
32 Correct 275 ms 18956 KB Output is correct
33 Correct 369 ms 22168 KB Output is correct
34 Correct 334 ms 25548 KB Output is correct
35 Correct 377 ms 27888 KB Output is correct
36 Correct 381 ms 30944 KB Output is correct
37 Correct 322 ms 33800 KB Output is correct
38 Correct 284 ms 36272 KB Output is correct
39 Correct 268 ms 39044 KB Output is correct
40 Correct 264 ms 41956 KB Output is correct
41 Correct 267 ms 44884 KB Output is correct
42 Correct 288 ms 48260 KB Output is correct
43 Correct 181 ms 50832 KB Output is correct
44 Correct 259 ms 53584 KB Output is correct
45 Correct 223 ms 56344 KB Output is correct
46 Correct 198 ms 59060 KB Output is correct
47 Correct 235 ms 61632 KB Output is correct
48 Correct 188 ms 64064 KB Output is correct
49 Correct 244 ms 67204 KB Output is correct
50 Correct 268 ms 70676 KB Output is correct
51 Correct 219 ms 73072 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1181 ms 118144 KB Output is correct
2 Correct 1629 ms 126836 KB Output is correct
3 Correct 1244 ms 149856 KB Output is correct
4 Correct 1106 ms 158596 KB Output is correct
5 Correct 2461 ms 178296 KB Output is correct
6 Correct 1893 ms 179720 KB Output is correct
7 Correct 1225 ms 198492 KB Output is correct
8 Correct 1025 ms 205376 KB Output is correct
9 Correct 1103 ms 215920 KB Output is correct
10 Correct 1046 ms 225432 KB Output is correct
11 Correct 1093 ms 234780 KB Output is correct
12 Correct 1026 ms 246928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1563 ms 258108 KB Output is correct
2 Correct 1733 ms 259840 KB Output is correct
3 Correct 2279 ms 270236 KB Output is correct
4 Correct 1910 ms 286852 KB Output is correct
5 Correct 1643 ms 293124 KB Output is correct
6 Correct 1606 ms 304768 KB Output is correct
7 Correct 3564 ms 322924 KB Output is correct
8 Correct 2435 ms 324088 KB Output is correct
9 Correct 1390 ms 340920 KB Output is correct
10 Correct 1426 ms 347140 KB Output is correct
11 Correct 1372 ms 352620 KB Output is correct
12 Correct 1442 ms 353528 KB Output is correct
13 Correct 1008 ms 353528 KB Output is correct
14 Correct 1041 ms 353868 KB Output is correct
15 Correct 1050 ms 353868 KB Output is correct
16 Correct 1166 ms 354432 KB Output is correct
17 Correct 1337 ms 354432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 12 ms 7588 KB Output is correct
4 Correct 12 ms 7588 KB Output is correct
5 Correct 13 ms 7700 KB Output is correct
6 Correct 13 ms 7776 KB Output is correct
7 Correct 14 ms 7832 KB Output is correct
8 Correct 13 ms 7852 KB Output is correct
9 Correct 13 ms 7872 KB Output is correct
10 Correct 13 ms 7892 KB Output is correct
11 Correct 13 ms 7912 KB Output is correct
12 Correct 14 ms 7932 KB Output is correct
13 Correct 14 ms 7932 KB Output is correct
14 Correct 10 ms 7932 KB Output is correct
15 Correct 14 ms 7932 KB Output is correct
16 Correct 14 ms 8012 KB Output is correct
17 Correct 13 ms 8152 KB Output is correct
18 Correct 13 ms 8152 KB Output is correct
19 Correct 14 ms 8188 KB Output is correct
20 Correct 12 ms 8188 KB Output is correct
21 Correct 12 ms 8188 KB Output is correct
22 Correct 13 ms 8188 KB Output is correct
23 Correct 14 ms 8188 KB Output is correct
24 Correct 17 ms 8188 KB Output is correct
25 Correct 14 ms 8188 KB Output is correct
26 Correct 14 ms 8212 KB Output is correct
27 Correct 13 ms 8212 KB Output is correct
28 Correct 10 ms 8212 KB Output is correct
29 Correct 13 ms 8256 KB Output is correct
30 Correct 14 ms 8272 KB Output is correct
31 Correct 347 ms 18692 KB Output is correct
32 Correct 275 ms 18956 KB Output is correct
33 Correct 369 ms 22168 KB Output is correct
34 Correct 334 ms 25548 KB Output is correct
35 Correct 377 ms 27888 KB Output is correct
36 Correct 381 ms 30944 KB Output is correct
37 Correct 322 ms 33800 KB Output is correct
38 Correct 284 ms 36272 KB Output is correct
39 Correct 268 ms 39044 KB Output is correct
40 Correct 264 ms 41956 KB Output is correct
41 Correct 267 ms 44884 KB Output is correct
42 Correct 288 ms 48260 KB Output is correct
43 Correct 181 ms 50832 KB Output is correct
44 Correct 259 ms 53584 KB Output is correct
45 Correct 223 ms 56344 KB Output is correct
46 Correct 198 ms 59060 KB Output is correct
47 Correct 235 ms 61632 KB Output is correct
48 Correct 188 ms 64064 KB Output is correct
49 Correct 244 ms 67204 KB Output is correct
50 Correct 268 ms 70676 KB Output is correct
51 Correct 219 ms 73072 KB Output is correct
52 Correct 379 ms 354432 KB Output is correct
53 Correct 320 ms 354432 KB Output is correct
54 Correct 309 ms 354432 KB Output is correct
55 Correct 229 ms 354432 KB Output is correct
56 Correct 256 ms 354432 KB Output is correct
57 Correct 254 ms 354432 KB Output is correct
58 Correct 301 ms 354432 KB Output is correct
59 Correct 325 ms 354432 KB Output is correct
60 Correct 272 ms 354432 KB Output is correct
61 Correct 177 ms 354432 KB Output is correct
62 Correct 310 ms 354432 KB Output is correct
63 Correct 266 ms 354432 KB Output is correct
64 Correct 263 ms 354432 KB Output is correct
65 Correct 241 ms 354432 KB Output is correct
66 Correct 254 ms 354432 KB Output is correct
67 Correct 225 ms 354432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 7416 KB Output is correct
2 Correct 10 ms 7416 KB Output is correct
3 Correct 12 ms 7588 KB Output is correct
4 Correct 12 ms 7588 KB Output is correct
5 Correct 13 ms 7700 KB Output is correct
6 Correct 13 ms 7776 KB Output is correct
7 Correct 14 ms 7832 KB Output is correct
8 Correct 13 ms 7852 KB Output is correct
9 Correct 13 ms 7872 KB Output is correct
10 Correct 13 ms 7892 KB Output is correct
11 Correct 13 ms 7912 KB Output is correct
12 Correct 14 ms 7932 KB Output is correct
13 Correct 14 ms 7932 KB Output is correct
14 Correct 10 ms 7932 KB Output is correct
15 Correct 14 ms 7932 KB Output is correct
16 Correct 14 ms 8012 KB Output is correct
17 Correct 13 ms 8152 KB Output is correct
18 Correct 13 ms 8152 KB Output is correct
19 Correct 14 ms 8188 KB Output is correct
20 Correct 12 ms 8188 KB Output is correct
21 Correct 12 ms 8188 KB Output is correct
22 Correct 13 ms 8188 KB Output is correct
23 Correct 14 ms 8188 KB Output is correct
24 Correct 17 ms 8188 KB Output is correct
25 Correct 14 ms 8188 KB Output is correct
26 Correct 14 ms 8212 KB Output is correct
27 Correct 13 ms 8212 KB Output is correct
28 Correct 10 ms 8212 KB Output is correct
29 Correct 13 ms 8256 KB Output is correct
30 Correct 14 ms 8272 KB Output is correct
31 Correct 347 ms 18692 KB Output is correct
32 Correct 275 ms 18956 KB Output is correct
33 Correct 369 ms 22168 KB Output is correct
34 Correct 334 ms 25548 KB Output is correct
35 Correct 377 ms 27888 KB Output is correct
36 Correct 381 ms 30944 KB Output is correct
37 Correct 322 ms 33800 KB Output is correct
38 Correct 284 ms 36272 KB Output is correct
39 Correct 268 ms 39044 KB Output is correct
40 Correct 264 ms 41956 KB Output is correct
41 Correct 267 ms 44884 KB Output is correct
42 Correct 288 ms 48260 KB Output is correct
43 Correct 181 ms 50832 KB Output is correct
44 Correct 259 ms 53584 KB Output is correct
45 Correct 223 ms 56344 KB Output is correct
46 Correct 198 ms 59060 KB Output is correct
47 Correct 235 ms 61632 KB Output is correct
48 Correct 188 ms 64064 KB Output is correct
49 Correct 244 ms 67204 KB Output is correct
50 Correct 268 ms 70676 KB Output is correct
51 Correct 219 ms 73072 KB Output is correct
52 Correct 1181 ms 118144 KB Output is correct
53 Correct 1629 ms 126836 KB Output is correct
54 Correct 1244 ms 149856 KB Output is correct
55 Correct 1106 ms 158596 KB Output is correct
56 Correct 2461 ms 178296 KB Output is correct
57 Correct 1893 ms 179720 KB Output is correct
58 Correct 1225 ms 198492 KB Output is correct
59 Correct 1025 ms 205376 KB Output is correct
60 Correct 1103 ms 215920 KB Output is correct
61 Correct 1046 ms 225432 KB Output is correct
62 Correct 1093 ms 234780 KB Output is correct
63 Correct 1026 ms 246928 KB Output is correct
64 Correct 1563 ms 258108 KB Output is correct
65 Correct 1733 ms 259840 KB Output is correct
66 Correct 2279 ms 270236 KB Output is correct
67 Correct 1910 ms 286852 KB Output is correct
68 Correct 1643 ms 293124 KB Output is correct
69 Correct 1606 ms 304768 KB Output is correct
70 Correct 3564 ms 322924 KB Output is correct
71 Correct 2435 ms 324088 KB Output is correct
72 Correct 1390 ms 340920 KB Output is correct
73 Correct 1426 ms 347140 KB Output is correct
74 Correct 1372 ms 352620 KB Output is correct
75 Correct 1442 ms 353528 KB Output is correct
76 Correct 1008 ms 353528 KB Output is correct
77 Correct 1041 ms 353868 KB Output is correct
78 Correct 1050 ms 353868 KB Output is correct
79 Correct 1166 ms 354432 KB Output is correct
80 Correct 1337 ms 354432 KB Output is correct
81 Correct 379 ms 354432 KB Output is correct
82 Correct 320 ms 354432 KB Output is correct
83 Correct 309 ms 354432 KB Output is correct
84 Correct 229 ms 354432 KB Output is correct
85 Correct 256 ms 354432 KB Output is correct
86 Correct 254 ms 354432 KB Output is correct
87 Correct 301 ms 354432 KB Output is correct
88 Correct 325 ms 354432 KB Output is correct
89 Correct 272 ms 354432 KB Output is correct
90 Correct 177 ms 354432 KB Output is correct
91 Correct 310 ms 354432 KB Output is correct
92 Correct 266 ms 354432 KB Output is correct
93 Correct 263 ms 354432 KB Output is correct
94 Correct 241 ms 354432 KB Output is correct
95 Correct 254 ms 354432 KB Output is correct
96 Correct 225 ms 354432 KB Output is correct
97 Correct 2180 ms 359460 KB Output is correct
98 Correct 1640 ms 359460 KB Output is correct
99 Correct 2478 ms 359460 KB Output is correct
100 Correct 2025 ms 360860 KB Output is correct
101 Correct 2024 ms 360860 KB Output is correct
102 Correct 2467 ms 360860 KB Output is correct
103 Correct 1626 ms 360860 KB Output is correct
104 Correct 1840 ms 360860 KB Output is correct
105 Correct 1309 ms 360860 KB Output is correct
106 Correct 1416 ms 360860 KB Output is correct
107 Correct 1463 ms 360860 KB Output is correct
108 Correct 1578 ms 360860 KB Output is correct
109 Correct 1550 ms 360860 KB Output is correct
110 Correct 1434 ms 360860 KB Output is correct
111 Correct 1525 ms 360860 KB Output is correct
112 Correct 1544 ms 360860 KB Output is correct
113 Correct 948 ms 362312 KB Output is correct
114 Correct 1716 ms 362312 KB Output is correct
115 Correct 1627 ms 362312 KB Output is correct
116 Correct 1526 ms 362312 KB Output is correct
117 Correct 1496 ms 362312 KB Output is correct
118 Correct 1554 ms 362312 KB Output is correct
119 Correct 1329 ms 362312 KB Output is correct
120 Correct 871 ms 362312 KB Output is correct
121 Correct 858 ms 362312 KB Output is correct
122 Correct 988 ms 362312 KB Output is correct
123 Correct 1054 ms 362312 KB Output is correct
124 Correct 1049 ms 362312 KB Output is correct
125 Correct 1155 ms 362312 KB Output is correct
126 Correct 1115 ms 362312 KB Output is correct