Submission #62438

# Submission time Handle Problem Language Result Execution time Memory
62438 2018-07-28T13:05:29 Z tmwilliamlin168 New Home (APIO18_new_home) C++14
100 / 100
3418 ms 709348 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 11 ms 7416 KB Output is correct
2 Correct 11 ms 7528 KB Output is correct
3 Correct 13 ms 7644 KB Output is correct
4 Correct 11 ms 7644 KB Output is correct
5 Correct 12 ms 7756 KB Output is correct
6 Correct 13 ms 7764 KB Output is correct
7 Correct 12 ms 7832 KB Output is correct
8 Correct 10 ms 7868 KB Output is correct
9 Correct 11 ms 7888 KB Output is correct
10 Correct 13 ms 7888 KB Output is correct
11 Correct 12 ms 7932 KB Output is correct
12 Correct 12 ms 8016 KB Output is correct
13 Correct 11 ms 8040 KB Output is correct
14 Correct 12 ms 8040 KB Output is correct
15 Correct 11 ms 8060 KB Output is correct
16 Correct 12 ms 8116 KB Output is correct
17 Correct 11 ms 8116 KB Output is correct
18 Correct 11 ms 8172 KB Output is correct
19 Correct 13 ms 8192 KB Output is correct
20 Correct 13 ms 8212 KB Output is correct
21 Correct 11 ms 8232 KB Output is correct
22 Correct 14 ms 8288 KB Output is correct
23 Correct 12 ms 8288 KB Output is correct
24 Correct 13 ms 8288 KB Output is correct
25 Correct 12 ms 8344 KB Output is correct
26 Correct 13 ms 8368 KB Output is correct
27 Correct 12 ms 8368 KB Output is correct
28 Correct 12 ms 8396 KB Output is correct
29 Correct 10 ms 8412 KB Output is correct
30 Correct 11 ms 8412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 7416 KB Output is correct
2 Correct 11 ms 7528 KB Output is correct
3 Correct 13 ms 7644 KB Output is correct
4 Correct 11 ms 7644 KB Output is correct
5 Correct 12 ms 7756 KB Output is correct
6 Correct 13 ms 7764 KB Output is correct
7 Correct 12 ms 7832 KB Output is correct
8 Correct 10 ms 7868 KB Output is correct
9 Correct 11 ms 7888 KB Output is correct
10 Correct 13 ms 7888 KB Output is correct
11 Correct 12 ms 7932 KB Output is correct
12 Correct 12 ms 8016 KB Output is correct
13 Correct 11 ms 8040 KB Output is correct
14 Correct 12 ms 8040 KB Output is correct
15 Correct 11 ms 8060 KB Output is correct
16 Correct 12 ms 8116 KB Output is correct
17 Correct 11 ms 8116 KB Output is correct
18 Correct 11 ms 8172 KB Output is correct
19 Correct 13 ms 8192 KB Output is correct
20 Correct 13 ms 8212 KB Output is correct
21 Correct 11 ms 8232 KB Output is correct
22 Correct 14 ms 8288 KB Output is correct
23 Correct 12 ms 8288 KB Output is correct
24 Correct 13 ms 8288 KB Output is correct
25 Correct 12 ms 8344 KB Output is correct
26 Correct 13 ms 8368 KB Output is correct
27 Correct 12 ms 8368 KB Output is correct
28 Correct 12 ms 8396 KB Output is correct
29 Correct 10 ms 8412 KB Output is correct
30 Correct 11 ms 8412 KB Output is correct
31 Correct 316 ms 18852 KB Output is correct
32 Correct 304 ms 18936 KB Output is correct
33 Correct 361 ms 22264 KB Output is correct
34 Correct 315 ms 25832 KB Output is correct
35 Correct 303 ms 28012 KB Output is correct
36 Correct 352 ms 31056 KB Output is correct
37 Correct 289 ms 33932 KB Output is correct
38 Correct 339 ms 36404 KB Output is correct
39 Correct 258 ms 39200 KB Output is correct
40 Correct 282 ms 42104 KB Output is correct
41 Correct 220 ms 45176 KB Output is correct
42 Correct 225 ms 48448 KB Output is correct
43 Correct 156 ms 50992 KB Output is correct
44 Correct 239 ms 53732 KB Output is correct
45 Correct 248 ms 56648 KB Output is correct
46 Correct 247 ms 59248 KB Output is correct
47 Correct 236 ms 61828 KB Output is correct
48 Correct 230 ms 64272 KB Output is correct
49 Correct 202 ms 67412 KB Output is correct
50 Correct 237 ms 70884 KB Output is correct
51 Correct 191 ms 73264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1265 ms 118396 KB Output is correct
2 Correct 1608 ms 127156 KB Output is correct
3 Correct 1430 ms 150256 KB Output is correct
4 Correct 1180 ms 158680 KB Output is correct
5 Correct 2520 ms 177560 KB Output is correct
6 Correct 1738 ms 179004 KB Output is correct
7 Correct 1012 ms 198540 KB Output is correct
8 Correct 947 ms 204892 KB Output is correct
9 Correct 1012 ms 215204 KB Output is correct
10 Correct 1142 ms 224284 KB Output is correct
11 Correct 1127 ms 233472 KB Output is correct
12 Correct 1183 ms 245428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1801 ms 256452 KB Output is correct
2 Correct 1613 ms 257492 KB Output is correct
3 Correct 2261 ms 268144 KB Output is correct
4 Correct 1842 ms 286408 KB Output is correct
5 Correct 1607 ms 294344 KB Output is correct
6 Correct 1545 ms 306020 KB Output is correct
7 Correct 3418 ms 322952 KB Output is correct
8 Correct 2509 ms 323688 KB Output is correct
9 Correct 1342 ms 339012 KB Output is correct
10 Correct 1495 ms 344384 KB Output is correct
11 Correct 1441 ms 352504 KB Output is correct
12 Correct 1526 ms 361044 KB Output is correct
13 Correct 1140 ms 369552 KB Output is correct
14 Correct 1158 ms 379324 KB Output is correct
15 Correct 1201 ms 388076 KB Output is correct
16 Correct 1289 ms 397964 KB Output is correct
17 Correct 1320 ms 404772 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 7416 KB Output is correct
2 Correct 11 ms 7528 KB Output is correct
3 Correct 13 ms 7644 KB Output is correct
4 Correct 11 ms 7644 KB Output is correct
5 Correct 12 ms 7756 KB Output is correct
6 Correct 13 ms 7764 KB Output is correct
7 Correct 12 ms 7832 KB Output is correct
8 Correct 10 ms 7868 KB Output is correct
9 Correct 11 ms 7888 KB Output is correct
10 Correct 13 ms 7888 KB Output is correct
11 Correct 12 ms 7932 KB Output is correct
12 Correct 12 ms 8016 KB Output is correct
13 Correct 11 ms 8040 KB Output is correct
14 Correct 12 ms 8040 KB Output is correct
15 Correct 11 ms 8060 KB Output is correct
16 Correct 12 ms 8116 KB Output is correct
17 Correct 11 ms 8116 KB Output is correct
18 Correct 11 ms 8172 KB Output is correct
19 Correct 13 ms 8192 KB Output is correct
20 Correct 13 ms 8212 KB Output is correct
21 Correct 11 ms 8232 KB Output is correct
22 Correct 14 ms 8288 KB Output is correct
23 Correct 12 ms 8288 KB Output is correct
24 Correct 13 ms 8288 KB Output is correct
25 Correct 12 ms 8344 KB Output is correct
26 Correct 13 ms 8368 KB Output is correct
27 Correct 12 ms 8368 KB Output is correct
28 Correct 12 ms 8396 KB Output is correct
29 Correct 10 ms 8412 KB Output is correct
30 Correct 11 ms 8412 KB Output is correct
31 Correct 316 ms 18852 KB Output is correct
32 Correct 304 ms 18936 KB Output is correct
33 Correct 361 ms 22264 KB Output is correct
34 Correct 315 ms 25832 KB Output is correct
35 Correct 303 ms 28012 KB Output is correct
36 Correct 352 ms 31056 KB Output is correct
37 Correct 289 ms 33932 KB Output is correct
38 Correct 339 ms 36404 KB Output is correct
39 Correct 258 ms 39200 KB Output is correct
40 Correct 282 ms 42104 KB Output is correct
41 Correct 220 ms 45176 KB Output is correct
42 Correct 225 ms 48448 KB Output is correct
43 Correct 156 ms 50992 KB Output is correct
44 Correct 239 ms 53732 KB Output is correct
45 Correct 248 ms 56648 KB Output is correct
46 Correct 247 ms 59248 KB Output is correct
47 Correct 236 ms 61828 KB Output is correct
48 Correct 230 ms 64272 KB Output is correct
49 Correct 202 ms 67412 KB Output is correct
50 Correct 237 ms 70884 KB Output is correct
51 Correct 191 ms 73264 KB Output is correct
52 Correct 343 ms 404772 KB Output is correct
53 Correct 349 ms 404772 KB Output is correct
54 Correct 355 ms 404772 KB Output is correct
55 Correct 256 ms 404772 KB Output is correct
56 Correct 271 ms 404772 KB Output is correct
57 Correct 253 ms 404772 KB Output is correct
58 Correct 254 ms 404772 KB Output is correct
59 Correct 288 ms 404772 KB Output is correct
60 Correct 233 ms 404772 KB Output is correct
61 Correct 212 ms 404772 KB Output is correct
62 Correct 309 ms 405064 KB Output is correct
63 Correct 282 ms 406552 KB Output is correct
64 Correct 272 ms 408276 KB Output is correct
65 Correct 236 ms 410208 KB Output is correct
66 Correct 253 ms 411768 KB Output is correct
67 Correct 258 ms 412228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 7416 KB Output is correct
2 Correct 11 ms 7528 KB Output is correct
3 Correct 13 ms 7644 KB Output is correct
4 Correct 11 ms 7644 KB Output is correct
5 Correct 12 ms 7756 KB Output is correct
6 Correct 13 ms 7764 KB Output is correct
7 Correct 12 ms 7832 KB Output is correct
8 Correct 10 ms 7868 KB Output is correct
9 Correct 11 ms 7888 KB Output is correct
10 Correct 13 ms 7888 KB Output is correct
11 Correct 12 ms 7932 KB Output is correct
12 Correct 12 ms 8016 KB Output is correct
13 Correct 11 ms 8040 KB Output is correct
14 Correct 12 ms 8040 KB Output is correct
15 Correct 11 ms 8060 KB Output is correct
16 Correct 12 ms 8116 KB Output is correct
17 Correct 11 ms 8116 KB Output is correct
18 Correct 11 ms 8172 KB Output is correct
19 Correct 13 ms 8192 KB Output is correct
20 Correct 13 ms 8212 KB Output is correct
21 Correct 11 ms 8232 KB Output is correct
22 Correct 14 ms 8288 KB Output is correct
23 Correct 12 ms 8288 KB Output is correct
24 Correct 13 ms 8288 KB Output is correct
25 Correct 12 ms 8344 KB Output is correct
26 Correct 13 ms 8368 KB Output is correct
27 Correct 12 ms 8368 KB Output is correct
28 Correct 12 ms 8396 KB Output is correct
29 Correct 10 ms 8412 KB Output is correct
30 Correct 11 ms 8412 KB Output is correct
31 Correct 316 ms 18852 KB Output is correct
32 Correct 304 ms 18936 KB Output is correct
33 Correct 361 ms 22264 KB Output is correct
34 Correct 315 ms 25832 KB Output is correct
35 Correct 303 ms 28012 KB Output is correct
36 Correct 352 ms 31056 KB Output is correct
37 Correct 289 ms 33932 KB Output is correct
38 Correct 339 ms 36404 KB Output is correct
39 Correct 258 ms 39200 KB Output is correct
40 Correct 282 ms 42104 KB Output is correct
41 Correct 220 ms 45176 KB Output is correct
42 Correct 225 ms 48448 KB Output is correct
43 Correct 156 ms 50992 KB Output is correct
44 Correct 239 ms 53732 KB Output is correct
45 Correct 248 ms 56648 KB Output is correct
46 Correct 247 ms 59248 KB Output is correct
47 Correct 236 ms 61828 KB Output is correct
48 Correct 230 ms 64272 KB Output is correct
49 Correct 202 ms 67412 KB Output is correct
50 Correct 237 ms 70884 KB Output is correct
51 Correct 191 ms 73264 KB Output is correct
52 Correct 1265 ms 118396 KB Output is correct
53 Correct 1608 ms 127156 KB Output is correct
54 Correct 1430 ms 150256 KB Output is correct
55 Correct 1180 ms 158680 KB Output is correct
56 Correct 2520 ms 177560 KB Output is correct
57 Correct 1738 ms 179004 KB Output is correct
58 Correct 1012 ms 198540 KB Output is correct
59 Correct 947 ms 204892 KB Output is correct
60 Correct 1012 ms 215204 KB Output is correct
61 Correct 1142 ms 224284 KB Output is correct
62 Correct 1127 ms 233472 KB Output is correct
63 Correct 1183 ms 245428 KB Output is correct
64 Correct 1801 ms 256452 KB Output is correct
65 Correct 1613 ms 257492 KB Output is correct
66 Correct 2261 ms 268144 KB Output is correct
67 Correct 1842 ms 286408 KB Output is correct
68 Correct 1607 ms 294344 KB Output is correct
69 Correct 1545 ms 306020 KB Output is correct
70 Correct 3418 ms 322952 KB Output is correct
71 Correct 2509 ms 323688 KB Output is correct
72 Correct 1342 ms 339012 KB Output is correct
73 Correct 1495 ms 344384 KB Output is correct
74 Correct 1441 ms 352504 KB Output is correct
75 Correct 1526 ms 361044 KB Output is correct
76 Correct 1140 ms 369552 KB Output is correct
77 Correct 1158 ms 379324 KB Output is correct
78 Correct 1201 ms 388076 KB Output is correct
79 Correct 1289 ms 397964 KB Output is correct
80 Correct 1320 ms 404772 KB Output is correct
81 Correct 343 ms 404772 KB Output is correct
82 Correct 349 ms 404772 KB Output is correct
83 Correct 355 ms 404772 KB Output is correct
84 Correct 256 ms 404772 KB Output is correct
85 Correct 271 ms 404772 KB Output is correct
86 Correct 253 ms 404772 KB Output is correct
87 Correct 254 ms 404772 KB Output is correct
88 Correct 288 ms 404772 KB Output is correct
89 Correct 233 ms 404772 KB Output is correct
90 Correct 212 ms 404772 KB Output is correct
91 Correct 309 ms 405064 KB Output is correct
92 Correct 282 ms 406552 KB Output is correct
93 Correct 272 ms 408276 KB Output is correct
94 Correct 236 ms 410208 KB Output is correct
95 Correct 253 ms 411768 KB Output is correct
96 Correct 258 ms 412228 KB Output is correct
97 Correct 2462 ms 448292 KB Output is correct
98 Correct 1739 ms 448292 KB Output is correct
99 Correct 2716 ms 454540 KB Output is correct
100 Correct 2231 ms 471688 KB Output is correct
101 Correct 2021 ms 479292 KB Output is correct
102 Correct 2588 ms 487520 KB Output is correct
103 Correct 1638 ms 497352 KB Output is correct
104 Correct 1879 ms 511220 KB Output is correct
105 Correct 1368 ms 525528 KB Output is correct
106 Correct 1480 ms 539584 KB Output is correct
107 Correct 1589 ms 556576 KB Output is correct
108 Correct 1628 ms 565144 KB Output is correct
109 Correct 1530 ms 571216 KB Output is correct
110 Correct 1457 ms 579320 KB Output is correct
111 Correct 1678 ms 592304 KB Output is correct
112 Correct 1379 ms 604772 KB Output is correct
113 Correct 1063 ms 616776 KB Output is correct
114 Correct 1786 ms 623488 KB Output is correct
115 Correct 1666 ms 629084 KB Output is correct
116 Correct 1809 ms 635916 KB Output is correct
117 Correct 1550 ms 643496 KB Output is correct
118 Correct 1533 ms 652628 KB Output is correct
119 Correct 1188 ms 656048 KB Output is correct
120 Correct 1125 ms 661956 KB Output is correct
121 Correct 1193 ms 672600 KB Output is correct
122 Correct 1078 ms 679036 KB Output is correct
123 Correct 1140 ms 686520 KB Output is correct
124 Correct 1244 ms 694892 KB Output is correct
125 Correct 1156 ms 700796 KB Output is correct
126 Correct 1313 ms 709348 KB Output is correct