답안 #128484

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
128484 2019-07-11T03:02:04 Z qkxwsm 새 집 (APIO18_new_home) C++14
100 / 100
2288 ms 66636 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";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 12 ms 7416 KB Output is correct
6 Correct 9 ms 7544 KB Output is correct
7 Correct 10 ms 7548 KB Output is correct
8 Correct 10 ms 7544 KB Output is correct
9 Correct 9 ms 7544 KB Output is correct
10 Correct 10 ms 7544 KB Output is correct
11 Correct 9 ms 7416 KB Output is correct
12 Correct 9 ms 7544 KB Output is correct
13 Correct 9 ms 7544 KB Output is correct
14 Correct 9 ms 7416 KB Output is correct
15 Correct 9 ms 7416 KB Output is correct
16 Correct 10 ms 7544 KB Output is correct
17 Correct 9 ms 7416 KB Output is correct
18 Correct 9 ms 7544 KB Output is correct
19 Correct 9 ms 7416 KB Output is correct
20 Correct 9 ms 7544 KB Output is correct
21 Correct 9 ms 7548 KB Output is correct
22 Correct 9 ms 7544 KB Output is correct
23 Correct 9 ms 7416 KB Output is correct
24 Correct 9 ms 7544 KB Output is correct
25 Correct 9 ms 7416 KB Output is correct
26 Correct 9 ms 7416 KB Output is correct
27 Correct 9 ms 7544 KB Output is correct
28 Correct 9 ms 7416 KB Output is correct
29 Correct 9 ms 7416 KB Output is correct
30 Correct 9 ms 7544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 12 ms 7416 KB Output is correct
6 Correct 9 ms 7544 KB Output is correct
7 Correct 10 ms 7548 KB Output is correct
8 Correct 10 ms 7544 KB Output is correct
9 Correct 9 ms 7544 KB Output is correct
10 Correct 10 ms 7544 KB Output is correct
11 Correct 9 ms 7416 KB Output is correct
12 Correct 9 ms 7544 KB Output is correct
13 Correct 9 ms 7544 KB Output is correct
14 Correct 9 ms 7416 KB Output is correct
15 Correct 9 ms 7416 KB Output is correct
16 Correct 10 ms 7544 KB Output is correct
17 Correct 9 ms 7416 KB Output is correct
18 Correct 9 ms 7544 KB Output is correct
19 Correct 9 ms 7416 KB Output is correct
20 Correct 9 ms 7544 KB Output is correct
21 Correct 9 ms 7548 KB Output is correct
22 Correct 9 ms 7544 KB Output is correct
23 Correct 9 ms 7416 KB Output is correct
24 Correct 9 ms 7544 KB Output is correct
25 Correct 9 ms 7416 KB Output is correct
26 Correct 9 ms 7416 KB Output is correct
27 Correct 9 ms 7544 KB Output is correct
28 Correct 9 ms 7416 KB Output is correct
29 Correct 9 ms 7416 KB Output is correct
30 Correct 9 ms 7544 KB Output is correct
31 Correct 264 ms 15012 KB Output is correct
32 Correct 222 ms 14080 KB Output is correct
33 Correct 285 ms 14556 KB Output is correct
34 Correct 257 ms 15096 KB Output is correct
35 Correct 270 ms 14548 KB Output is correct
36 Correct 300 ms 14584 KB Output is correct
37 Correct 244 ms 14584 KB Output is correct
38 Correct 258 ms 14520 KB Output is correct
39 Correct 217 ms 14304 KB Output is correct
40 Correct 237 ms 14304 KB Output is correct
41 Correct 198 ms 14584 KB Output is correct
42 Correct 200 ms 14668 KB Output is correct
43 Correct 139 ms 14968 KB Output is correct
44 Correct 198 ms 14812 KB Output is correct
45 Correct 188 ms 14840 KB Output is correct
46 Correct 174 ms 14592 KB Output is correct
47 Correct 165 ms 14156 KB Output is correct
48 Correct 157 ms 14188 KB Output is correct
49 Correct 181 ms 14400 KB Output is correct
50 Correct 195 ms 14860 KB Output is correct
51 Correct 171 ms 14456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 909 ms 45820 KB Output is correct
2 Correct 1249 ms 42052 KB Output is correct
3 Correct 1047 ms 51320 KB Output is correct
4 Correct 932 ms 46528 KB Output is correct
5 Correct 1726 ms 54232 KB Output is correct
6 Correct 1360 ms 43608 KB Output is correct
7 Correct 865 ms 51320 KB Output is correct
8 Correct 806 ms 45432 KB Output is correct
9 Correct 815 ms 44336 KB Output is correct
10 Correct 947 ms 42488 KB Output is correct
11 Correct 878 ms 41416 KB Output is correct
12 Correct 862 ms 43044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1234 ms 43788 KB Output is correct
2 Correct 1103 ms 45512 KB Output is correct
3 Correct 1647 ms 54536 KB Output is correct
4 Correct 1306 ms 62972 KB Output is correct
5 Correct 1197 ms 57396 KB Output is correct
6 Correct 1194 ms 58088 KB Output is correct
7 Correct 2288 ms 66636 KB Output is correct
8 Correct 1822 ms 55800 KB Output is correct
9 Correct 1107 ms 64380 KB Output is correct
10 Correct 1076 ms 58524 KB Output is correct
11 Correct 1143 ms 56952 KB Output is correct
12 Correct 1252 ms 55032 KB Output is correct
13 Correct 941 ms 53316 KB Output is correct
14 Correct 954 ms 54200 KB Output is correct
15 Correct 1027 ms 53436 KB Output is correct
16 Correct 1044 ms 55456 KB Output is correct
17 Correct 1083 ms 53728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 12 ms 7416 KB Output is correct
6 Correct 9 ms 7544 KB Output is correct
7 Correct 10 ms 7548 KB Output is correct
8 Correct 10 ms 7544 KB Output is correct
9 Correct 9 ms 7544 KB Output is correct
10 Correct 10 ms 7544 KB Output is correct
11 Correct 9 ms 7416 KB Output is correct
12 Correct 9 ms 7544 KB Output is correct
13 Correct 9 ms 7544 KB Output is correct
14 Correct 9 ms 7416 KB Output is correct
15 Correct 9 ms 7416 KB Output is correct
16 Correct 10 ms 7544 KB Output is correct
17 Correct 9 ms 7416 KB Output is correct
18 Correct 9 ms 7544 KB Output is correct
19 Correct 9 ms 7416 KB Output is correct
20 Correct 9 ms 7544 KB Output is correct
21 Correct 9 ms 7548 KB Output is correct
22 Correct 9 ms 7544 KB Output is correct
23 Correct 9 ms 7416 KB Output is correct
24 Correct 9 ms 7544 KB Output is correct
25 Correct 9 ms 7416 KB Output is correct
26 Correct 9 ms 7416 KB Output is correct
27 Correct 9 ms 7544 KB Output is correct
28 Correct 9 ms 7416 KB Output is correct
29 Correct 9 ms 7416 KB Output is correct
30 Correct 9 ms 7544 KB Output is correct
31 Correct 264 ms 15012 KB Output is correct
32 Correct 222 ms 14080 KB Output is correct
33 Correct 285 ms 14556 KB Output is correct
34 Correct 257 ms 15096 KB Output is correct
35 Correct 270 ms 14548 KB Output is correct
36 Correct 300 ms 14584 KB Output is correct
37 Correct 244 ms 14584 KB Output is correct
38 Correct 258 ms 14520 KB Output is correct
39 Correct 217 ms 14304 KB Output is correct
40 Correct 237 ms 14304 KB Output is correct
41 Correct 198 ms 14584 KB Output is correct
42 Correct 200 ms 14668 KB Output is correct
43 Correct 139 ms 14968 KB Output is correct
44 Correct 198 ms 14812 KB Output is correct
45 Correct 188 ms 14840 KB Output is correct
46 Correct 174 ms 14592 KB Output is correct
47 Correct 165 ms 14156 KB Output is correct
48 Correct 157 ms 14188 KB Output is correct
49 Correct 181 ms 14400 KB Output is correct
50 Correct 195 ms 14860 KB Output is correct
51 Correct 171 ms 14456 KB Output is correct
52 Correct 273 ms 16012 KB Output is correct
53 Correct 271 ms 15812 KB Output is correct
54 Correct 246 ms 14972 KB Output is correct
55 Correct 218 ms 15128 KB Output is correct
56 Correct 229 ms 15528 KB Output is correct
57 Correct 203 ms 14608 KB Output is correct
58 Correct 217 ms 15096 KB Output is correct
59 Correct 225 ms 15224 KB Output is correct
60 Correct 206 ms 14900 KB Output is correct
61 Correct 158 ms 16120 KB Output is correct
62 Correct 251 ms 15992 KB Output is correct
63 Correct 236 ms 15096 KB Output is correct
64 Correct 233 ms 14924 KB Output is correct
65 Correct 225 ms 14712 KB Output is correct
66 Correct 218 ms 14840 KB Output is correct
67 Correct 210 ms 14456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB Output is correct
2 Correct 8 ms 7416 KB Output is correct
3 Correct 8 ms 7416 KB Output is correct
4 Correct 8 ms 7416 KB Output is correct
5 Correct 12 ms 7416 KB Output is correct
6 Correct 9 ms 7544 KB Output is correct
7 Correct 10 ms 7548 KB Output is correct
8 Correct 10 ms 7544 KB Output is correct
9 Correct 9 ms 7544 KB Output is correct
10 Correct 10 ms 7544 KB Output is correct
11 Correct 9 ms 7416 KB Output is correct
12 Correct 9 ms 7544 KB Output is correct
13 Correct 9 ms 7544 KB Output is correct
14 Correct 9 ms 7416 KB Output is correct
15 Correct 9 ms 7416 KB Output is correct
16 Correct 10 ms 7544 KB Output is correct
17 Correct 9 ms 7416 KB Output is correct
18 Correct 9 ms 7544 KB Output is correct
19 Correct 9 ms 7416 KB Output is correct
20 Correct 9 ms 7544 KB Output is correct
21 Correct 9 ms 7548 KB Output is correct
22 Correct 9 ms 7544 KB Output is correct
23 Correct 9 ms 7416 KB Output is correct
24 Correct 9 ms 7544 KB Output is correct
25 Correct 9 ms 7416 KB Output is correct
26 Correct 9 ms 7416 KB Output is correct
27 Correct 9 ms 7544 KB Output is correct
28 Correct 9 ms 7416 KB Output is correct
29 Correct 9 ms 7416 KB Output is correct
30 Correct 9 ms 7544 KB Output is correct
31 Correct 264 ms 15012 KB Output is correct
32 Correct 222 ms 14080 KB Output is correct
33 Correct 285 ms 14556 KB Output is correct
34 Correct 257 ms 15096 KB Output is correct
35 Correct 270 ms 14548 KB Output is correct
36 Correct 300 ms 14584 KB Output is correct
37 Correct 244 ms 14584 KB Output is correct
38 Correct 258 ms 14520 KB Output is correct
39 Correct 217 ms 14304 KB Output is correct
40 Correct 237 ms 14304 KB Output is correct
41 Correct 198 ms 14584 KB Output is correct
42 Correct 200 ms 14668 KB Output is correct
43 Correct 139 ms 14968 KB Output is correct
44 Correct 198 ms 14812 KB Output is correct
45 Correct 188 ms 14840 KB Output is correct
46 Correct 174 ms 14592 KB Output is correct
47 Correct 165 ms 14156 KB Output is correct
48 Correct 157 ms 14188 KB Output is correct
49 Correct 181 ms 14400 KB Output is correct
50 Correct 195 ms 14860 KB Output is correct
51 Correct 171 ms 14456 KB Output is correct
52 Correct 909 ms 45820 KB Output is correct
53 Correct 1249 ms 42052 KB Output is correct
54 Correct 1047 ms 51320 KB Output is correct
55 Correct 932 ms 46528 KB Output is correct
56 Correct 1726 ms 54232 KB Output is correct
57 Correct 1360 ms 43608 KB Output is correct
58 Correct 865 ms 51320 KB Output is correct
59 Correct 806 ms 45432 KB Output is correct
60 Correct 815 ms 44336 KB Output is correct
61 Correct 947 ms 42488 KB Output is correct
62 Correct 878 ms 41416 KB Output is correct
63 Correct 862 ms 43044 KB Output is correct
64 Correct 1234 ms 43788 KB Output is correct
65 Correct 1103 ms 45512 KB Output is correct
66 Correct 1647 ms 54536 KB Output is correct
67 Correct 1306 ms 62972 KB Output is correct
68 Correct 1197 ms 57396 KB Output is correct
69 Correct 1194 ms 58088 KB Output is correct
70 Correct 2288 ms 66636 KB Output is correct
71 Correct 1822 ms 55800 KB Output is correct
72 Correct 1107 ms 64380 KB Output is correct
73 Correct 1076 ms 58524 KB Output is correct
74 Correct 1143 ms 56952 KB Output is correct
75 Correct 1252 ms 55032 KB Output is correct
76 Correct 941 ms 53316 KB Output is correct
77 Correct 954 ms 54200 KB Output is correct
78 Correct 1027 ms 53436 KB Output is correct
79 Correct 1044 ms 55456 KB Output is correct
80 Correct 1083 ms 53728 KB Output is correct
81 Correct 273 ms 16012 KB Output is correct
82 Correct 271 ms 15812 KB Output is correct
83 Correct 246 ms 14972 KB Output is correct
84 Correct 218 ms 15128 KB Output is correct
85 Correct 229 ms 15528 KB Output is correct
86 Correct 203 ms 14608 KB Output is correct
87 Correct 217 ms 15096 KB Output is correct
88 Correct 225 ms 15224 KB Output is correct
89 Correct 206 ms 14900 KB Output is correct
90 Correct 158 ms 16120 KB Output is correct
91 Correct 251 ms 15992 KB Output is correct
92 Correct 236 ms 15096 KB Output is correct
93 Correct 233 ms 14924 KB Output is correct
94 Correct 225 ms 14712 KB Output is correct
95 Correct 218 ms 14840 KB Output is correct
96 Correct 210 ms 14456 KB Output is correct
97 Correct 1606 ms 65012 KB Output is correct
98 Correct 1215 ms 45672 KB Output is correct
99 Correct 1797 ms 55904 KB Output is correct
100 Correct 1636 ms 65144 KB Output is correct
101 Correct 1440 ms 60080 KB Output is correct
102 Correct 1886 ms 56516 KB Output is correct
103 Correct 1407 ms 55836 KB Output is correct
104 Correct 1571 ms 55360 KB Output is correct
105 Correct 1224 ms 55160 KB Output is correct
106 Correct 1283 ms 55104 KB Output is correct
107 Correct 1162 ms 61056 KB Output is correct
108 Correct 1220 ms 62584 KB Output is correct
109 Correct 1139 ms 60164 KB Output is correct
110 Correct 1204 ms 61064 KB Output is correct
111 Correct 1277 ms 62136 KB Output is correct
112 Correct 1145 ms 59200 KB Output is correct
113 Correct 837 ms 63608 KB Output is correct
114 Correct 1390 ms 65656 KB Output is correct
115 Correct 1403 ms 61688 KB Output is correct
116 Correct 1313 ms 60024 KB Output is correct
117 Correct 1242 ms 59480 KB Output is correct
118 Correct 1165 ms 59128 KB Output is correct
119 Correct 1002 ms 48888 KB Output is correct
120 Correct 783 ms 51888 KB Output is correct
121 Correct 840 ms 53740 KB Output is correct
122 Correct 814 ms 53516 KB Output is correct
123 Correct 884 ms 54696 KB Output is correct
124 Correct 994 ms 57144 KB Output is correct
125 Correct 889 ms 54968 KB Output is correct
126 Correct 1069 ms 59324 KB Output is correct