Submission #62446

# Submission time Handle Problem Language Result Execution time Memory
62446 2018-07-28T13:26:18 Z tmwilliamlin168 New Home (APIO18_new_home) C++14
100 / 100
3517 ms 141328 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 10 ms 7416 KB Output is correct
2 Correct 12 ms 7528 KB Output is correct
3 Correct 9 ms 7616 KB Output is correct
4 Correct 11 ms 7616 KB Output is correct
5 Correct 13 ms 7720 KB Output is correct
6 Correct 12 ms 7732 KB Output is correct
7 Correct 12 ms 7796 KB Output is correct
8 Correct 12 ms 7816 KB Output is correct
9 Correct 12 ms 7872 KB Output is correct
10 Correct 11 ms 7892 KB Output is correct
11 Correct 15 ms 7908 KB Output is correct
12 Correct 14 ms 7928 KB Output is correct
13 Correct 12 ms 8068 KB Output is correct
14 Correct 13 ms 8068 KB Output is correct
15 Correct 13 ms 8068 KB Output is correct
16 Correct 12 ms 8068 KB Output is correct
17 Correct 13 ms 8068 KB Output is correct
18 Correct 12 ms 8068 KB Output is correct
19 Correct 12 ms 8088 KB Output is correct
20 Correct 13 ms 8108 KB Output is correct
21 Correct 13 ms 8128 KB Output is correct
22 Correct 12 ms 8144 KB Output is correct
23 Correct 13 ms 8164 KB Output is correct
24 Correct 15 ms 8164 KB Output is correct
25 Correct 11 ms 8164 KB Output is correct
26 Correct 10 ms 8224 KB Output is correct
27 Correct 10 ms 8224 KB Output is correct
28 Correct 11 ms 8224 KB Output is correct
29 Correct 11 ms 8272 KB Output is correct
30 Correct 11 ms 8272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 7416 KB Output is correct
2 Correct 12 ms 7528 KB Output is correct
3 Correct 9 ms 7616 KB Output is correct
4 Correct 11 ms 7616 KB Output is correct
5 Correct 13 ms 7720 KB Output is correct
6 Correct 12 ms 7732 KB Output is correct
7 Correct 12 ms 7796 KB Output is correct
8 Correct 12 ms 7816 KB Output is correct
9 Correct 12 ms 7872 KB Output is correct
10 Correct 11 ms 7892 KB Output is correct
11 Correct 15 ms 7908 KB Output is correct
12 Correct 14 ms 7928 KB Output is correct
13 Correct 12 ms 8068 KB Output is correct
14 Correct 13 ms 8068 KB Output is correct
15 Correct 13 ms 8068 KB Output is correct
16 Correct 12 ms 8068 KB Output is correct
17 Correct 13 ms 8068 KB Output is correct
18 Correct 12 ms 8068 KB Output is correct
19 Correct 12 ms 8088 KB Output is correct
20 Correct 13 ms 8108 KB Output is correct
21 Correct 13 ms 8128 KB Output is correct
22 Correct 12 ms 8144 KB Output is correct
23 Correct 13 ms 8164 KB Output is correct
24 Correct 15 ms 8164 KB Output is correct
25 Correct 11 ms 8164 KB Output is correct
26 Correct 10 ms 8224 KB Output is correct
27 Correct 10 ms 8224 KB Output is correct
28 Correct 11 ms 8224 KB Output is correct
29 Correct 11 ms 8272 KB Output is correct
30 Correct 11 ms 8272 KB Output is correct
31 Correct 280 ms 18808 KB Output is correct
32 Correct 249 ms 18844 KB Output is correct
33 Correct 320 ms 22340 KB Output is correct
34 Correct 322 ms 25552 KB Output is correct
35 Correct 316 ms 28044 KB Output is correct
36 Correct 358 ms 30968 KB Output is correct
37 Correct 289 ms 33952 KB Output is correct
38 Correct 353 ms 36420 KB Output is correct
39 Correct 266 ms 39220 KB Output is correct
40 Correct 320 ms 42008 KB Output is correct
41 Correct 278 ms 44968 KB Output is correct
42 Correct 242 ms 48152 KB Output is correct
43 Correct 207 ms 50912 KB Output is correct
44 Correct 256 ms 53560 KB Output is correct
45 Correct 197 ms 56360 KB Output is correct
46 Correct 220 ms 59208 KB Output is correct
47 Correct 169 ms 61452 KB Output is correct
48 Correct 173 ms 64076 KB Output is correct
49 Correct 218 ms 67232 KB Output is correct
50 Correct 241 ms 70628 KB Output is correct
51 Correct 206 ms 72976 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1227 ms 110320 KB Output is correct
2 Correct 1565 ms 110320 KB Output is correct
3 Correct 1364 ms 115676 KB Output is correct
4 Correct 1258 ms 115676 KB Output is correct
5 Correct 2514 ms 118828 KB Output is correct
6 Correct 1625 ms 118828 KB Output is correct
7 Correct 996 ms 118828 KB Output is correct
8 Correct 897 ms 118828 KB Output is correct
9 Correct 955 ms 118828 KB Output is correct
10 Correct 1167 ms 118828 KB Output is correct
11 Correct 986 ms 118828 KB Output is correct
12 Correct 1081 ms 118828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1548 ms 118828 KB Output is correct
2 Correct 1428 ms 118828 KB Output is correct
3 Correct 2023 ms 118828 KB Output is correct
4 Correct 1628 ms 118828 KB Output is correct
5 Correct 1538 ms 118828 KB Output is correct
6 Correct 1590 ms 118828 KB Output is correct
7 Correct 3517 ms 118868 KB Output is correct
8 Correct 2536 ms 118868 KB Output is correct
9 Correct 1225 ms 118868 KB Output is correct
10 Correct 1256 ms 118868 KB Output is correct
11 Correct 1431 ms 118868 KB Output is correct
12 Correct 1475 ms 121276 KB Output is correct
13 Correct 1136 ms 131388 KB Output is correct
14 Correct 1038 ms 132376 KB Output is correct
15 Correct 1241 ms 132376 KB Output is correct
16 Correct 1193 ms 132996 KB Output is correct
17 Correct 1213 ms 132996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 7416 KB Output is correct
2 Correct 12 ms 7528 KB Output is correct
3 Correct 9 ms 7616 KB Output is correct
4 Correct 11 ms 7616 KB Output is correct
5 Correct 13 ms 7720 KB Output is correct
6 Correct 12 ms 7732 KB Output is correct
7 Correct 12 ms 7796 KB Output is correct
8 Correct 12 ms 7816 KB Output is correct
9 Correct 12 ms 7872 KB Output is correct
10 Correct 11 ms 7892 KB Output is correct
11 Correct 15 ms 7908 KB Output is correct
12 Correct 14 ms 7928 KB Output is correct
13 Correct 12 ms 8068 KB Output is correct
14 Correct 13 ms 8068 KB Output is correct
15 Correct 13 ms 8068 KB Output is correct
16 Correct 12 ms 8068 KB Output is correct
17 Correct 13 ms 8068 KB Output is correct
18 Correct 12 ms 8068 KB Output is correct
19 Correct 12 ms 8088 KB Output is correct
20 Correct 13 ms 8108 KB Output is correct
21 Correct 13 ms 8128 KB Output is correct
22 Correct 12 ms 8144 KB Output is correct
23 Correct 13 ms 8164 KB Output is correct
24 Correct 15 ms 8164 KB Output is correct
25 Correct 11 ms 8164 KB Output is correct
26 Correct 10 ms 8224 KB Output is correct
27 Correct 10 ms 8224 KB Output is correct
28 Correct 11 ms 8224 KB Output is correct
29 Correct 11 ms 8272 KB Output is correct
30 Correct 11 ms 8272 KB Output is correct
31 Correct 280 ms 18808 KB Output is correct
32 Correct 249 ms 18844 KB Output is correct
33 Correct 320 ms 22340 KB Output is correct
34 Correct 322 ms 25552 KB Output is correct
35 Correct 316 ms 28044 KB Output is correct
36 Correct 358 ms 30968 KB Output is correct
37 Correct 289 ms 33952 KB Output is correct
38 Correct 353 ms 36420 KB Output is correct
39 Correct 266 ms 39220 KB Output is correct
40 Correct 320 ms 42008 KB Output is correct
41 Correct 278 ms 44968 KB Output is correct
42 Correct 242 ms 48152 KB Output is correct
43 Correct 207 ms 50912 KB Output is correct
44 Correct 256 ms 53560 KB Output is correct
45 Correct 197 ms 56360 KB Output is correct
46 Correct 220 ms 59208 KB Output is correct
47 Correct 169 ms 61452 KB Output is correct
48 Correct 173 ms 64076 KB Output is correct
49 Correct 218 ms 67232 KB Output is correct
50 Correct 241 ms 70628 KB Output is correct
51 Correct 206 ms 72976 KB Output is correct
52 Correct 367 ms 132996 KB Output is correct
53 Correct 305 ms 132996 KB Output is correct
54 Correct 275 ms 132996 KB Output is correct
55 Correct 308 ms 132996 KB Output is correct
56 Correct 253 ms 132996 KB Output is correct
57 Correct 250 ms 132996 KB Output is correct
58 Correct 276 ms 132996 KB Output is correct
59 Correct 266 ms 132996 KB Output is correct
60 Correct 232 ms 132996 KB Output is correct
61 Correct 198 ms 132996 KB Output is correct
62 Correct 300 ms 132996 KB Output is correct
63 Correct 349 ms 132996 KB Output is correct
64 Correct 271 ms 132996 KB Output is correct
65 Correct 268 ms 132996 KB Output is correct
66 Correct 225 ms 132996 KB Output is correct
67 Correct 223 ms 132996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 7416 KB Output is correct
2 Correct 12 ms 7528 KB Output is correct
3 Correct 9 ms 7616 KB Output is correct
4 Correct 11 ms 7616 KB Output is correct
5 Correct 13 ms 7720 KB Output is correct
6 Correct 12 ms 7732 KB Output is correct
7 Correct 12 ms 7796 KB Output is correct
8 Correct 12 ms 7816 KB Output is correct
9 Correct 12 ms 7872 KB Output is correct
10 Correct 11 ms 7892 KB Output is correct
11 Correct 15 ms 7908 KB Output is correct
12 Correct 14 ms 7928 KB Output is correct
13 Correct 12 ms 8068 KB Output is correct
14 Correct 13 ms 8068 KB Output is correct
15 Correct 13 ms 8068 KB Output is correct
16 Correct 12 ms 8068 KB Output is correct
17 Correct 13 ms 8068 KB Output is correct
18 Correct 12 ms 8068 KB Output is correct
19 Correct 12 ms 8088 KB Output is correct
20 Correct 13 ms 8108 KB Output is correct
21 Correct 13 ms 8128 KB Output is correct
22 Correct 12 ms 8144 KB Output is correct
23 Correct 13 ms 8164 KB Output is correct
24 Correct 15 ms 8164 KB Output is correct
25 Correct 11 ms 8164 KB Output is correct
26 Correct 10 ms 8224 KB Output is correct
27 Correct 10 ms 8224 KB Output is correct
28 Correct 11 ms 8224 KB Output is correct
29 Correct 11 ms 8272 KB Output is correct
30 Correct 11 ms 8272 KB Output is correct
31 Correct 280 ms 18808 KB Output is correct
32 Correct 249 ms 18844 KB Output is correct
33 Correct 320 ms 22340 KB Output is correct
34 Correct 322 ms 25552 KB Output is correct
35 Correct 316 ms 28044 KB Output is correct
36 Correct 358 ms 30968 KB Output is correct
37 Correct 289 ms 33952 KB Output is correct
38 Correct 353 ms 36420 KB Output is correct
39 Correct 266 ms 39220 KB Output is correct
40 Correct 320 ms 42008 KB Output is correct
41 Correct 278 ms 44968 KB Output is correct
42 Correct 242 ms 48152 KB Output is correct
43 Correct 207 ms 50912 KB Output is correct
44 Correct 256 ms 53560 KB Output is correct
45 Correct 197 ms 56360 KB Output is correct
46 Correct 220 ms 59208 KB Output is correct
47 Correct 169 ms 61452 KB Output is correct
48 Correct 173 ms 64076 KB Output is correct
49 Correct 218 ms 67232 KB Output is correct
50 Correct 241 ms 70628 KB Output is correct
51 Correct 206 ms 72976 KB Output is correct
52 Correct 1227 ms 110320 KB Output is correct
53 Correct 1565 ms 110320 KB Output is correct
54 Correct 1364 ms 115676 KB Output is correct
55 Correct 1258 ms 115676 KB Output is correct
56 Correct 2514 ms 118828 KB Output is correct
57 Correct 1625 ms 118828 KB Output is correct
58 Correct 996 ms 118828 KB Output is correct
59 Correct 897 ms 118828 KB Output is correct
60 Correct 955 ms 118828 KB Output is correct
61 Correct 1167 ms 118828 KB Output is correct
62 Correct 986 ms 118828 KB Output is correct
63 Correct 1081 ms 118828 KB Output is correct
64 Correct 1548 ms 118828 KB Output is correct
65 Correct 1428 ms 118828 KB Output is correct
66 Correct 2023 ms 118828 KB Output is correct
67 Correct 1628 ms 118828 KB Output is correct
68 Correct 1538 ms 118828 KB Output is correct
69 Correct 1590 ms 118828 KB Output is correct
70 Correct 3517 ms 118868 KB Output is correct
71 Correct 2536 ms 118868 KB Output is correct
72 Correct 1225 ms 118868 KB Output is correct
73 Correct 1256 ms 118868 KB Output is correct
74 Correct 1431 ms 118868 KB Output is correct
75 Correct 1475 ms 121276 KB Output is correct
76 Correct 1136 ms 131388 KB Output is correct
77 Correct 1038 ms 132376 KB Output is correct
78 Correct 1241 ms 132376 KB Output is correct
79 Correct 1193 ms 132996 KB Output is correct
80 Correct 1213 ms 132996 KB Output is correct
81 Correct 367 ms 132996 KB Output is correct
82 Correct 305 ms 132996 KB Output is correct
83 Correct 275 ms 132996 KB Output is correct
84 Correct 308 ms 132996 KB Output is correct
85 Correct 253 ms 132996 KB Output is correct
86 Correct 250 ms 132996 KB Output is correct
87 Correct 276 ms 132996 KB Output is correct
88 Correct 266 ms 132996 KB Output is correct
89 Correct 232 ms 132996 KB Output is correct
90 Correct 198 ms 132996 KB Output is correct
91 Correct 300 ms 132996 KB Output is correct
92 Correct 349 ms 132996 KB Output is correct
93 Correct 271 ms 132996 KB Output is correct
94 Correct 268 ms 132996 KB Output is correct
95 Correct 225 ms 132996 KB Output is correct
96 Correct 223 ms 132996 KB Output is correct
97 Correct 2105 ms 139624 KB Output is correct
98 Correct 1529 ms 139624 KB Output is correct
99 Correct 2273 ms 139624 KB Output is correct
100 Correct 1998 ms 139624 KB Output is correct
101 Correct 1882 ms 139624 KB Output is correct
102 Correct 2427 ms 139624 KB Output is correct
103 Correct 1608 ms 139624 KB Output is correct
104 Correct 1969 ms 139624 KB Output is correct
105 Correct 1403 ms 139624 KB Output is correct
106 Correct 1433 ms 139624 KB Output is correct
107 Correct 1366 ms 139624 KB Output is correct
108 Correct 1580 ms 139624 KB Output is correct
109 Correct 1346 ms 139624 KB Output is correct
110 Correct 1534 ms 139624 KB Output is correct
111 Correct 1628 ms 139624 KB Output is correct
112 Correct 1452 ms 139624 KB Output is correct
113 Correct 1131 ms 141328 KB Output is correct
114 Correct 1717 ms 141328 KB Output is correct
115 Correct 1752 ms 141328 KB Output is correct
116 Correct 1717 ms 141328 KB Output is correct
117 Correct 1626 ms 141328 KB Output is correct
118 Correct 1456 ms 141328 KB Output is correct
119 Correct 1142 ms 141328 KB Output is correct
120 Correct 863 ms 141328 KB Output is correct
121 Correct 917 ms 141328 KB Output is correct
122 Correct 986 ms 141328 KB Output is correct
123 Correct 1074 ms 141328 KB Output is correct
124 Correct 1212 ms 141328 KB Output is correct
125 Correct 1126 ms 141328 KB Output is correct
126 Correct 1277 ms 141328 KB Output is correct