답안 #41728

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
41728 2018-02-21T04:45:45 Z aome Segments (IZhO18_segments) C++14
75 / 100
5000 ms 40960 KB
#include <bits/stdc++.h>
using namespace std;

const int N = 200005;
const int B = 900;

int n, t, sz, lastans;
int cnt;
int L[N], R[N];
bool del[N];
int sz_add, sz_del;
int buf_add[B];
int buf_del[B];
int sz_l[500], sz_r[500];
int block_l[500][B];
int block_r[500][B];
int sz_go;
pair<int, int> go[N];

void prep() {
	sz_go = 0;
	for (int i = 1; i <= sz; ++i) {
		if (!del[i]) go[sz_go++] = make_pair(R[i] - L[i] + 1, i);
	}
	sort(go, go + sz_go);
	sz_add = sz_del = 0;
	int m = sz_go;
	for (int i = 0; i <= m / B; ++i) sz_l[i] = 0, sz_r[i] = 0;
	for (int i = 0; i < m; ++i) block_l[i / B][sz_l[i / B]++] = L[go[i].second];
	for (int i = 0; i < m; ++i) block_r[i / B][sz_r[i / B]++] = R[go[i].second]; 
	for (int i = 0; i <= m / B; ++i) {
		sort(block_l[i], block_l[i] + sz_l[i]);
		sort(block_r[i], block_r[i] + sz_r[i]);
	}
}

int calc(int id, int l, int r) {
	// count number of commont points betweeen L[id], R[id] and l, r
	if (L[id] > l) return max(0, min(r, R[id]) - L[id] + 1);
	return max(0, min(R[id], r) - l + 1);
}

int calL(int l, int r, int x) {
	// count number of segments from l -> r which has L > x
	int res = 0;
	int bl = l / B, br = r / B;
	if (bl == br) {
		for (int i = l; i <= r; ++i) res += L[go[i].second] > x;
		return res;
	}
	for (int i = bl + 1; i < br; ++i) {
		int tmp = lower_bound(block_l[i], block_l[i] + sz_l[i], x + 1) - block_l[i];
		res += B - tmp;
	}
	for (int i = l; i < (bl + 1) * B; ++i) res += L[go[i].second] > x;
	for (int i = br * B; i <= r; ++i) res += L[go[i].second] > x;
	return res;
}

int calR(int l, int r, int x) {
	// count number of segments from l -> r which has R < x
	int res = 0;
	int bl = l / B, br = r / B;
	if (bl == br) {
		for (int i = l; i <= r; ++i) res += R[go[i].second] < x;
		return res;
	}
	for (int i = bl + 1; i < br; ++i) {
		int tmp = lower_bound(block_r[i], block_r[i] + sz_r[i], x) - block_r[i];
		res += tmp;
	}
	for (int i = l; i < (bl + 1) * B; ++i) res += R[go[i].second] < x;
	for (int i = br * B; i <= r; ++i) res += R[go[i].second] < x;
	return res;
}

int main() {
	scanf("%d %d", &n, &t);
	for (int i = 1; i <= n; ++i) {
		if (i % B == 0) prep();

		int type; scanf("%d", &type);

		if (type == 1) {
			int l, r; scanf("%d %d", &l, &r);
			l = l ^ (1LL * t * lastans);
			r = r ^ (1LL * t * lastans);
			if (l > r) swap(l, r);
			++sz, L[sz] = l, R[sz] = r, buf_add[sz_add++] = sz, cnt++;
		}

		if (type == 2) {
			int x; scanf("%d", &x), buf_del[sz_del++] = x, del[x] = 1, cnt--;
		}

		if (type == 3) {
			int l, r, k; 
			scanf("%d %d %d", &l, &r, &k);
			l = l ^ (1LL * t * lastans);
			r = r ^ (1LL * t * lastans);
			if (l > r) swap(l, r);

			if (r - l + 1 < k) {
				lastans = 0, printf("0\n"); continue;
			} 

			int res = 0;	

			for (int j = 0; j < sz_add; ++j) res += calc(buf_add[j], l, r) < k;
			for (int j = 0; j < sz_del; ++j) res -= calc(buf_del[j], l, r) < k;
				
			int p = lower_bound(go, go + sz_go, make_pair(k, 0)) - go;

			// number of segments r - l + 1 < k
			res += p;

			// query p -> go.size() - 1 (segments with size >= k)

			// count number of segments L > r - k + 1
			res += calL(p, sz_go - 1, r - k + 1);
			// count number of segments R < l + k - 1
			res += calR(p, sz_go - 1, l + k - 1);

			res = cnt - res, lastans = res;
			printf("%d\n", res);
		}
	}
}

Compilation message

segments.cpp: In function 'int main()':
segments.cpp:78:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d", &n, &t);
                        ^
segments.cpp:82:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   int type; scanf("%d", &type);
                               ^
segments.cpp:85:36: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int l, r; scanf("%d %d", &l, &r);
                                    ^
segments.cpp:93:68: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    int x; scanf("%d", &x), buf_del[sz_del++] = x, del[x] = 1, cnt--;
                                                                    ^
segments.cpp:98:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    scanf("%d %d %d", &l, &r, &k);
                                 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 6 ms 424 KB Output is correct
4 Correct 8 ms 496 KB Output is correct
5 Correct 11 ms 696 KB Output is correct
6 Correct 13 ms 696 KB Output is correct
7 Correct 9 ms 696 KB Output is correct
8 Correct 9 ms 696 KB Output is correct
9 Correct 10 ms 696 KB Output is correct
10 Correct 7 ms 748 KB Output is correct
11 Correct 15 ms 748 KB Output is correct
12 Correct 15 ms 748 KB Output is correct
13 Correct 8 ms 780 KB Output is correct
14 Correct 11 ms 780 KB Output is correct
15 Correct 7 ms 780 KB Output is correct
16 Correct 8 ms 780 KB Output is correct
17 Correct 10 ms 780 KB Output is correct
18 Correct 8 ms 796 KB Output is correct
19 Correct 10 ms 796 KB Output is correct
20 Correct 11 ms 796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1414 ms 2556 KB Output is correct
2 Correct 1415 ms 5064 KB Output is correct
3 Correct 1445 ms 7752 KB Output is correct
4 Correct 1372 ms 10508 KB Output is correct
5 Correct 1342 ms 13528 KB Output is correct
6 Correct 1227 ms 16012 KB Output is correct
7 Correct 1420 ms 17760 KB Output is correct
8 Correct 1439 ms 20368 KB Output is correct
9 Correct 1497 ms 23100 KB Output is correct
10 Correct 950 ms 25488 KB Output is correct
11 Correct 1020 ms 28576 KB Output is correct
12 Correct 1465 ms 31852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 31852 KB Output is correct
2 Correct 111 ms 31852 KB Output is correct
3 Correct 158 ms 31852 KB Output is correct
4 Correct 111 ms 31852 KB Output is correct
5 Correct 1688 ms 31852 KB Output is correct
6 Correct 1642 ms 34096 KB Output is correct
7 Correct 1728 ms 36540 KB Output is correct
8 Correct 1298 ms 39144 KB Output is correct
9 Correct 1257 ms 40960 KB Output is correct
10 Correct 1227 ms 40960 KB Output is correct
11 Correct 372 ms 40960 KB Output is correct
12 Correct 1270 ms 40960 KB Output is correct
13 Correct 1214 ms 40960 KB Output is correct
14 Correct 877 ms 40960 KB Output is correct
15 Correct 837 ms 40960 KB Output is correct
16 Correct 681 ms 40960 KB Output is correct
17 Correct 1655 ms 40960 KB Output is correct
18 Correct 1683 ms 40960 KB Output is correct
19 Correct 1677 ms 40960 KB Output is correct
20 Correct 1663 ms 40960 KB Output is correct
21 Correct 403 ms 40960 KB Output is correct
22 Correct 1074 ms 40960 KB Output is correct
23 Correct 1178 ms 40960 KB Output is correct
24 Correct 1081 ms 40960 KB Output is correct
25 Correct 137 ms 40960 KB Output is correct
26 Correct 119 ms 40960 KB Output is correct
27 Correct 127 ms 40960 KB Output is correct
28 Correct 120 ms 40960 KB Output is correct
29 Correct 1205 ms 40960 KB Output is correct
30 Correct 1245 ms 40960 KB Output is correct
31 Correct 1239 ms 40960 KB Output is correct
32 Correct 1274 ms 40960 KB Output is correct
33 Correct 1241 ms 40960 KB Output is correct
34 Correct 811 ms 40960 KB Output is correct
35 Correct 1144 ms 40960 KB Output is correct
36 Correct 1285 ms 40960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 105 ms 40960 KB Output is correct
2 Correct 125 ms 40960 KB Output is correct
3 Correct 122 ms 40960 KB Output is correct
4 Correct 111 ms 40960 KB Output is correct
5 Correct 1466 ms 40960 KB Output is correct
6 Correct 701 ms 40960 KB Output is correct
7 Correct 1368 ms 40960 KB Output is correct
8 Correct 1081 ms 40960 KB Output is correct
9 Correct 891 ms 40960 KB Output is correct
10 Correct 1269 ms 40960 KB Output is correct
11 Correct 531 ms 40960 KB Output is correct
12 Correct 1177 ms 40960 KB Output is correct
13 Correct 1117 ms 40960 KB Output is correct
14 Correct 819 ms 40960 KB Output is correct
15 Correct 1250 ms 40960 KB Output is correct
16 Correct 1175 ms 40960 KB Output is correct
17 Correct 1443 ms 40960 KB Output is correct
18 Correct 1427 ms 40960 KB Output is correct
19 Correct 1408 ms 40960 KB Output is correct
20 Correct 1426 ms 40960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 6 ms 424 KB Output is correct
4 Correct 8 ms 496 KB Output is correct
5 Correct 11 ms 696 KB Output is correct
6 Correct 13 ms 696 KB Output is correct
7 Correct 9 ms 696 KB Output is correct
8 Correct 9 ms 696 KB Output is correct
9 Correct 10 ms 696 KB Output is correct
10 Correct 7 ms 748 KB Output is correct
11 Correct 15 ms 748 KB Output is correct
12 Correct 15 ms 748 KB Output is correct
13 Correct 8 ms 780 KB Output is correct
14 Correct 11 ms 780 KB Output is correct
15 Correct 7 ms 780 KB Output is correct
16 Correct 8 ms 780 KB Output is correct
17 Correct 10 ms 780 KB Output is correct
18 Correct 8 ms 796 KB Output is correct
19 Correct 10 ms 796 KB Output is correct
20 Correct 11 ms 796 KB Output is correct
21 Correct 1414 ms 2556 KB Output is correct
22 Correct 1415 ms 5064 KB Output is correct
23 Correct 1445 ms 7752 KB Output is correct
24 Correct 1372 ms 10508 KB Output is correct
25 Correct 1342 ms 13528 KB Output is correct
26 Correct 1227 ms 16012 KB Output is correct
27 Correct 1420 ms 17760 KB Output is correct
28 Correct 1439 ms 20368 KB Output is correct
29 Correct 1497 ms 23100 KB Output is correct
30 Correct 950 ms 25488 KB Output is correct
31 Correct 1020 ms 28576 KB Output is correct
32 Correct 1465 ms 31852 KB Output is correct
33 Correct 105 ms 40960 KB Output is correct
34 Correct 125 ms 40960 KB Output is correct
35 Correct 122 ms 40960 KB Output is correct
36 Correct 111 ms 40960 KB Output is correct
37 Correct 1466 ms 40960 KB Output is correct
38 Correct 701 ms 40960 KB Output is correct
39 Correct 1368 ms 40960 KB Output is correct
40 Correct 1081 ms 40960 KB Output is correct
41 Correct 891 ms 40960 KB Output is correct
42 Correct 1269 ms 40960 KB Output is correct
43 Correct 531 ms 40960 KB Output is correct
44 Correct 1177 ms 40960 KB Output is correct
45 Correct 1117 ms 40960 KB Output is correct
46 Correct 819 ms 40960 KB Output is correct
47 Correct 1250 ms 40960 KB Output is correct
48 Correct 1175 ms 40960 KB Output is correct
49 Correct 1443 ms 40960 KB Output is correct
50 Correct 1427 ms 40960 KB Output is correct
51 Correct 1408 ms 40960 KB Output is correct
52 Correct 1426 ms 40960 KB Output is correct
53 Correct 114 ms 40960 KB Output is correct
54 Correct 112 ms 40960 KB Output is correct
55 Correct 108 ms 40960 KB Output is correct
56 Correct 111 ms 40960 KB Output is correct
57 Correct 1182 ms 40960 KB Output is correct
58 Correct 515 ms 40960 KB Output is correct
59 Correct 1430 ms 40960 KB Output is correct
60 Correct 480 ms 40960 KB Output is correct
61 Correct 1145 ms 40960 KB Output is correct
62 Correct 1211 ms 40960 KB Output is correct
63 Correct 1216 ms 40960 KB Output is correct
64 Correct 1231 ms 40960 KB Output is correct
65 Correct 599 ms 40960 KB Output is correct
66 Correct 565 ms 40960 KB Output is correct
67 Correct 1196 ms 40960 KB Output is correct
68 Correct 1104 ms 40960 KB Output is correct
69 Correct 1423 ms 40960 KB Output is correct
70 Correct 1410 ms 40960 KB Output is correct
71 Correct 1385 ms 40960 KB Output is correct
72 Correct 1430 ms 40960 KB Output is correct
73 Correct 680 ms 40960 KB Output is correct
74 Correct 1094 ms 40960 KB Output is correct
75 Correct 1213 ms 40960 KB Output is correct
76 Correct 1185 ms 40960 KB Output is correct
77 Correct 115 ms 40960 KB Output is correct
78 Correct 109 ms 40960 KB Output is correct
79 Correct 113 ms 40960 KB Output is correct
80 Correct 112 ms 40960 KB Output is correct
81 Correct 1029 ms 40960 KB Output is correct
82 Correct 736 ms 40960 KB Output is correct
83 Correct 533 ms 40960 KB Output is correct
84 Correct 999 ms 40960 KB Output is correct
85 Correct 1156 ms 40960 KB Output is correct
86 Correct 1257 ms 40960 KB Output is correct
87 Correct 895 ms 40960 KB Output is correct
88 Correct 530 ms 40960 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 6 ms 424 KB Output is correct
4 Correct 8 ms 496 KB Output is correct
5 Correct 11 ms 696 KB Output is correct
6 Correct 13 ms 696 KB Output is correct
7 Correct 9 ms 696 KB Output is correct
8 Correct 9 ms 696 KB Output is correct
9 Correct 10 ms 696 KB Output is correct
10 Correct 7 ms 748 KB Output is correct
11 Correct 15 ms 748 KB Output is correct
12 Correct 15 ms 748 KB Output is correct
13 Correct 8 ms 780 KB Output is correct
14 Correct 11 ms 780 KB Output is correct
15 Correct 7 ms 780 KB Output is correct
16 Correct 8 ms 780 KB Output is correct
17 Correct 10 ms 780 KB Output is correct
18 Correct 8 ms 796 KB Output is correct
19 Correct 10 ms 796 KB Output is correct
20 Correct 11 ms 796 KB Output is correct
21 Correct 1414 ms 2556 KB Output is correct
22 Correct 1415 ms 5064 KB Output is correct
23 Correct 1445 ms 7752 KB Output is correct
24 Correct 1372 ms 10508 KB Output is correct
25 Correct 1342 ms 13528 KB Output is correct
26 Correct 1227 ms 16012 KB Output is correct
27 Correct 1420 ms 17760 KB Output is correct
28 Correct 1439 ms 20368 KB Output is correct
29 Correct 1497 ms 23100 KB Output is correct
30 Correct 950 ms 25488 KB Output is correct
31 Correct 1020 ms 28576 KB Output is correct
32 Correct 1465 ms 31852 KB Output is correct
33 Correct 115 ms 31852 KB Output is correct
34 Correct 111 ms 31852 KB Output is correct
35 Correct 158 ms 31852 KB Output is correct
36 Correct 111 ms 31852 KB Output is correct
37 Correct 1688 ms 31852 KB Output is correct
38 Correct 1642 ms 34096 KB Output is correct
39 Correct 1728 ms 36540 KB Output is correct
40 Correct 1298 ms 39144 KB Output is correct
41 Correct 1257 ms 40960 KB Output is correct
42 Correct 1227 ms 40960 KB Output is correct
43 Correct 372 ms 40960 KB Output is correct
44 Correct 1270 ms 40960 KB Output is correct
45 Correct 1214 ms 40960 KB Output is correct
46 Correct 877 ms 40960 KB Output is correct
47 Correct 837 ms 40960 KB Output is correct
48 Correct 681 ms 40960 KB Output is correct
49 Correct 1655 ms 40960 KB Output is correct
50 Correct 1683 ms 40960 KB Output is correct
51 Correct 1677 ms 40960 KB Output is correct
52 Correct 1663 ms 40960 KB Output is correct
53 Correct 403 ms 40960 KB Output is correct
54 Correct 1074 ms 40960 KB Output is correct
55 Correct 1178 ms 40960 KB Output is correct
56 Correct 1081 ms 40960 KB Output is correct
57 Correct 137 ms 40960 KB Output is correct
58 Correct 119 ms 40960 KB Output is correct
59 Correct 127 ms 40960 KB Output is correct
60 Correct 120 ms 40960 KB Output is correct
61 Correct 1205 ms 40960 KB Output is correct
62 Correct 1245 ms 40960 KB Output is correct
63 Correct 1239 ms 40960 KB Output is correct
64 Correct 1274 ms 40960 KB Output is correct
65 Correct 1241 ms 40960 KB Output is correct
66 Correct 811 ms 40960 KB Output is correct
67 Correct 1144 ms 40960 KB Output is correct
68 Correct 1285 ms 40960 KB Output is correct
69 Correct 105 ms 40960 KB Output is correct
70 Correct 125 ms 40960 KB Output is correct
71 Correct 122 ms 40960 KB Output is correct
72 Correct 111 ms 40960 KB Output is correct
73 Correct 1466 ms 40960 KB Output is correct
74 Correct 701 ms 40960 KB Output is correct
75 Correct 1368 ms 40960 KB Output is correct
76 Correct 1081 ms 40960 KB Output is correct
77 Correct 891 ms 40960 KB Output is correct
78 Correct 1269 ms 40960 KB Output is correct
79 Correct 531 ms 40960 KB Output is correct
80 Correct 1177 ms 40960 KB Output is correct
81 Correct 1117 ms 40960 KB Output is correct
82 Correct 819 ms 40960 KB Output is correct
83 Correct 1250 ms 40960 KB Output is correct
84 Correct 1175 ms 40960 KB Output is correct
85 Correct 1443 ms 40960 KB Output is correct
86 Correct 1427 ms 40960 KB Output is correct
87 Correct 1408 ms 40960 KB Output is correct
88 Correct 1426 ms 40960 KB Output is correct
89 Correct 114 ms 40960 KB Output is correct
90 Correct 112 ms 40960 KB Output is correct
91 Correct 108 ms 40960 KB Output is correct
92 Correct 111 ms 40960 KB Output is correct
93 Correct 1182 ms 40960 KB Output is correct
94 Correct 515 ms 40960 KB Output is correct
95 Correct 1430 ms 40960 KB Output is correct
96 Correct 480 ms 40960 KB Output is correct
97 Correct 1145 ms 40960 KB Output is correct
98 Correct 1211 ms 40960 KB Output is correct
99 Correct 1216 ms 40960 KB Output is correct
100 Correct 1231 ms 40960 KB Output is correct
101 Correct 599 ms 40960 KB Output is correct
102 Correct 565 ms 40960 KB Output is correct
103 Correct 1196 ms 40960 KB Output is correct
104 Correct 1104 ms 40960 KB Output is correct
105 Correct 1423 ms 40960 KB Output is correct
106 Correct 1410 ms 40960 KB Output is correct
107 Correct 1385 ms 40960 KB Output is correct
108 Correct 1430 ms 40960 KB Output is correct
109 Correct 680 ms 40960 KB Output is correct
110 Correct 1094 ms 40960 KB Output is correct
111 Correct 1213 ms 40960 KB Output is correct
112 Correct 1185 ms 40960 KB Output is correct
113 Correct 115 ms 40960 KB Output is correct
114 Correct 109 ms 40960 KB Output is correct
115 Correct 113 ms 40960 KB Output is correct
116 Correct 112 ms 40960 KB Output is correct
117 Correct 1029 ms 40960 KB Output is correct
118 Correct 736 ms 40960 KB Output is correct
119 Correct 533 ms 40960 KB Output is correct
120 Correct 999 ms 40960 KB Output is correct
121 Correct 1156 ms 40960 KB Output is correct
122 Correct 1257 ms 40960 KB Output is correct
123 Correct 895 ms 40960 KB Output is correct
124 Correct 530 ms 40960 KB Output is correct
125 Correct 222 ms 40960 KB Output is correct
126 Correct 230 ms 40960 KB Output is correct
127 Correct 304 ms 40960 KB Output is correct
128 Correct 265 ms 40960 KB Output is correct
129 Correct 235 ms 40960 KB Output is correct
130 Correct 249 ms 40960 KB Output is correct
131 Correct 1908 ms 40960 KB Output is correct
132 Correct 4991 ms 40960 KB Output is correct
133 Execution timed out 5052 ms 40960 KB Time limit exceeded
134 Halted 0 ms 0 KB -