Submission #41727

# Submission time Handle Problem Language Result Execution time Memory
41727 2018-02-21T04:36:29 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 = 1111;

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);
                                 ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 8 ms 552 KB Output is correct
4 Correct 7 ms 552 KB Output is correct
5 Correct 14 ms 568 KB Output is correct
6 Correct 12 ms 568 KB Output is correct
7 Correct 9 ms 568 KB Output is correct
8 Correct 15 ms 568 KB Output is correct
9 Correct 10 ms 568 KB Output is correct
10 Correct 7 ms 656 KB Output is correct
11 Correct 14 ms 656 KB Output is correct
12 Correct 16 ms 656 KB Output is correct
13 Correct 7 ms 708 KB Output is correct
14 Correct 9 ms 708 KB Output is correct
15 Correct 7 ms 708 KB Output is correct
16 Correct 7 ms 708 KB Output is correct
17 Correct 11 ms 708 KB Output is correct
18 Correct 11 ms 796 KB Output is correct
19 Correct 10 ms 796 KB Output is correct
20 Correct 10 ms 796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1198 ms 2456 KB Output is correct
2 Correct 1202 ms 5092 KB Output is correct
3 Correct 1146 ms 7932 KB Output is correct
4 Correct 1275 ms 10744 KB Output is correct
5 Correct 1109 ms 13496 KB Output is correct
6 Correct 1016 ms 15812 KB Output is correct
7 Correct 1153 ms 17748 KB Output is correct
8 Correct 1402 ms 20428 KB Output is correct
9 Correct 1444 ms 23076 KB Output is correct
10 Correct 959 ms 25360 KB Output is correct
11 Correct 1022 ms 28424 KB Output is correct
12 Correct 1225 ms 31724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 131 ms 31724 KB Output is correct
2 Correct 119 ms 31724 KB Output is correct
3 Correct 154 ms 31724 KB Output is correct
4 Correct 120 ms 31724 KB Output is correct
5 Correct 1448 ms 31996 KB Output is correct
6 Correct 1459 ms 34000 KB Output is correct
7 Correct 1604 ms 36284 KB Output is correct
8 Correct 1120 ms 39188 KB Output is correct
9 Correct 1033 ms 40960 KB Output is correct
10 Correct 1091 ms 40960 KB Output is correct
11 Correct 336 ms 40960 KB Output is correct
12 Correct 1143 ms 40960 KB Output is correct
13 Correct 1093 ms 40960 KB Output is correct
14 Correct 844 ms 40960 KB Output is correct
15 Correct 787 ms 40960 KB Output is correct
16 Correct 584 ms 40960 KB Output is correct
17 Correct 1357 ms 40960 KB Output is correct
18 Correct 1402 ms 40960 KB Output is correct
19 Correct 1360 ms 40960 KB Output is correct
20 Correct 1334 ms 40960 KB Output is correct
21 Correct 459 ms 40960 KB Output is correct
22 Correct 926 ms 40960 KB Output is correct
23 Correct 1026 ms 40960 KB Output is correct
24 Correct 1010 ms 40960 KB Output is correct
25 Correct 142 ms 40960 KB Output is correct
26 Correct 124 ms 40960 KB Output is correct
27 Correct 144 ms 40960 KB Output is correct
28 Correct 147 ms 40960 KB Output is correct
29 Correct 1055 ms 40960 KB Output is correct
30 Correct 1014 ms 40960 KB Output is correct
31 Correct 1020 ms 40960 KB Output is correct
32 Correct 1082 ms 40960 KB Output is correct
33 Correct 1026 ms 40960 KB Output is correct
34 Correct 781 ms 40960 KB Output is correct
35 Correct 1032 ms 40960 KB Output is correct
36 Correct 1096 ms 40960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 125 ms 40960 KB Output is correct
2 Correct 126 ms 40960 KB Output is correct
3 Correct 125 ms 40960 KB Output is correct
4 Correct 135 ms 40960 KB Output is correct
5 Correct 1224 ms 40960 KB Output is correct
6 Correct 764 ms 40960 KB Output is correct
7 Correct 1246 ms 40960 KB Output is correct
8 Correct 983 ms 40960 KB Output is correct
9 Correct 910 ms 40960 KB Output is correct
10 Correct 1089 ms 40960 KB Output is correct
11 Correct 499 ms 40960 KB Output is correct
12 Correct 1014 ms 40960 KB Output is correct
13 Correct 986 ms 40960 KB Output is correct
14 Correct 779 ms 40960 KB Output is correct
15 Correct 1022 ms 40960 KB Output is correct
16 Correct 1010 ms 40960 KB Output is correct
17 Correct 1433 ms 40960 KB Output is correct
18 Correct 1388 ms 40960 KB Output is correct
19 Correct 1425 ms 40960 KB Output is correct
20 Correct 1372 ms 40960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 8 ms 552 KB Output is correct
4 Correct 7 ms 552 KB Output is correct
5 Correct 14 ms 568 KB Output is correct
6 Correct 12 ms 568 KB Output is correct
7 Correct 9 ms 568 KB Output is correct
8 Correct 15 ms 568 KB Output is correct
9 Correct 10 ms 568 KB Output is correct
10 Correct 7 ms 656 KB Output is correct
11 Correct 14 ms 656 KB Output is correct
12 Correct 16 ms 656 KB Output is correct
13 Correct 7 ms 708 KB Output is correct
14 Correct 9 ms 708 KB Output is correct
15 Correct 7 ms 708 KB Output is correct
16 Correct 7 ms 708 KB Output is correct
17 Correct 11 ms 708 KB Output is correct
18 Correct 11 ms 796 KB Output is correct
19 Correct 10 ms 796 KB Output is correct
20 Correct 10 ms 796 KB Output is correct
21 Correct 1198 ms 2456 KB Output is correct
22 Correct 1202 ms 5092 KB Output is correct
23 Correct 1146 ms 7932 KB Output is correct
24 Correct 1275 ms 10744 KB Output is correct
25 Correct 1109 ms 13496 KB Output is correct
26 Correct 1016 ms 15812 KB Output is correct
27 Correct 1153 ms 17748 KB Output is correct
28 Correct 1402 ms 20428 KB Output is correct
29 Correct 1444 ms 23076 KB Output is correct
30 Correct 959 ms 25360 KB Output is correct
31 Correct 1022 ms 28424 KB Output is correct
32 Correct 1225 ms 31724 KB Output is correct
33 Correct 125 ms 40960 KB Output is correct
34 Correct 126 ms 40960 KB Output is correct
35 Correct 125 ms 40960 KB Output is correct
36 Correct 135 ms 40960 KB Output is correct
37 Correct 1224 ms 40960 KB Output is correct
38 Correct 764 ms 40960 KB Output is correct
39 Correct 1246 ms 40960 KB Output is correct
40 Correct 983 ms 40960 KB Output is correct
41 Correct 910 ms 40960 KB Output is correct
42 Correct 1089 ms 40960 KB Output is correct
43 Correct 499 ms 40960 KB Output is correct
44 Correct 1014 ms 40960 KB Output is correct
45 Correct 986 ms 40960 KB Output is correct
46 Correct 779 ms 40960 KB Output is correct
47 Correct 1022 ms 40960 KB Output is correct
48 Correct 1010 ms 40960 KB Output is correct
49 Correct 1433 ms 40960 KB Output is correct
50 Correct 1388 ms 40960 KB Output is correct
51 Correct 1425 ms 40960 KB Output is correct
52 Correct 1372 ms 40960 KB Output is correct
53 Correct 132 ms 40960 KB Output is correct
54 Correct 168 ms 40960 KB Output is correct
55 Correct 123 ms 40960 KB Output is correct
56 Correct 127 ms 40960 KB Output is correct
57 Correct 1256 ms 40960 KB Output is correct
58 Correct 543 ms 40960 KB Output is correct
59 Correct 1254 ms 40960 KB Output is correct
60 Correct 601 ms 40960 KB Output is correct
61 Correct 1062 ms 40960 KB Output is correct
62 Correct 1026 ms 40960 KB Output is correct
63 Correct 966 ms 40960 KB Output is correct
64 Correct 1018 ms 40960 KB Output is correct
65 Correct 603 ms 40960 KB Output is correct
66 Correct 572 ms 40960 KB Output is correct
67 Correct 1025 ms 40960 KB Output is correct
68 Correct 999 ms 40960 KB Output is correct
69 Correct 1465 ms 40960 KB Output is correct
70 Correct 1453 ms 40960 KB Output is correct
71 Correct 1428 ms 40960 KB Output is correct
72 Correct 1413 ms 40960 KB Output is correct
73 Correct 670 ms 40960 KB Output is correct
74 Correct 951 ms 40960 KB Output is correct
75 Correct 1002 ms 40960 KB Output is correct
76 Correct 1020 ms 40960 KB Output is correct
77 Correct 127 ms 40960 KB Output is correct
78 Correct 121 ms 40960 KB Output is correct
79 Correct 141 ms 40960 KB Output is correct
80 Correct 134 ms 40960 KB Output is correct
81 Correct 923 ms 40960 KB Output is correct
82 Correct 643 ms 40960 KB Output is correct
83 Correct 473 ms 40960 KB Output is correct
84 Correct 943 ms 40960 KB Output is correct
85 Correct 1036 ms 40960 KB Output is correct
86 Correct 1039 ms 40960 KB Output is correct
87 Correct 784 ms 40960 KB Output is correct
88 Correct 496 ms 40960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 248 KB Output is correct
2 Correct 2 ms 352 KB Output is correct
3 Correct 8 ms 552 KB Output is correct
4 Correct 7 ms 552 KB Output is correct
5 Correct 14 ms 568 KB Output is correct
6 Correct 12 ms 568 KB Output is correct
7 Correct 9 ms 568 KB Output is correct
8 Correct 15 ms 568 KB Output is correct
9 Correct 10 ms 568 KB Output is correct
10 Correct 7 ms 656 KB Output is correct
11 Correct 14 ms 656 KB Output is correct
12 Correct 16 ms 656 KB Output is correct
13 Correct 7 ms 708 KB Output is correct
14 Correct 9 ms 708 KB Output is correct
15 Correct 7 ms 708 KB Output is correct
16 Correct 7 ms 708 KB Output is correct
17 Correct 11 ms 708 KB Output is correct
18 Correct 11 ms 796 KB Output is correct
19 Correct 10 ms 796 KB Output is correct
20 Correct 10 ms 796 KB Output is correct
21 Correct 1198 ms 2456 KB Output is correct
22 Correct 1202 ms 5092 KB Output is correct
23 Correct 1146 ms 7932 KB Output is correct
24 Correct 1275 ms 10744 KB Output is correct
25 Correct 1109 ms 13496 KB Output is correct
26 Correct 1016 ms 15812 KB Output is correct
27 Correct 1153 ms 17748 KB Output is correct
28 Correct 1402 ms 20428 KB Output is correct
29 Correct 1444 ms 23076 KB Output is correct
30 Correct 959 ms 25360 KB Output is correct
31 Correct 1022 ms 28424 KB Output is correct
32 Correct 1225 ms 31724 KB Output is correct
33 Correct 131 ms 31724 KB Output is correct
34 Correct 119 ms 31724 KB Output is correct
35 Correct 154 ms 31724 KB Output is correct
36 Correct 120 ms 31724 KB Output is correct
37 Correct 1448 ms 31996 KB Output is correct
38 Correct 1459 ms 34000 KB Output is correct
39 Correct 1604 ms 36284 KB Output is correct
40 Correct 1120 ms 39188 KB Output is correct
41 Correct 1033 ms 40960 KB Output is correct
42 Correct 1091 ms 40960 KB Output is correct
43 Correct 336 ms 40960 KB Output is correct
44 Correct 1143 ms 40960 KB Output is correct
45 Correct 1093 ms 40960 KB Output is correct
46 Correct 844 ms 40960 KB Output is correct
47 Correct 787 ms 40960 KB Output is correct
48 Correct 584 ms 40960 KB Output is correct
49 Correct 1357 ms 40960 KB Output is correct
50 Correct 1402 ms 40960 KB Output is correct
51 Correct 1360 ms 40960 KB Output is correct
52 Correct 1334 ms 40960 KB Output is correct
53 Correct 459 ms 40960 KB Output is correct
54 Correct 926 ms 40960 KB Output is correct
55 Correct 1026 ms 40960 KB Output is correct
56 Correct 1010 ms 40960 KB Output is correct
57 Correct 142 ms 40960 KB Output is correct
58 Correct 124 ms 40960 KB Output is correct
59 Correct 144 ms 40960 KB Output is correct
60 Correct 147 ms 40960 KB Output is correct
61 Correct 1055 ms 40960 KB Output is correct
62 Correct 1014 ms 40960 KB Output is correct
63 Correct 1020 ms 40960 KB Output is correct
64 Correct 1082 ms 40960 KB Output is correct
65 Correct 1026 ms 40960 KB Output is correct
66 Correct 781 ms 40960 KB Output is correct
67 Correct 1032 ms 40960 KB Output is correct
68 Correct 1096 ms 40960 KB Output is correct
69 Correct 125 ms 40960 KB Output is correct
70 Correct 126 ms 40960 KB Output is correct
71 Correct 125 ms 40960 KB Output is correct
72 Correct 135 ms 40960 KB Output is correct
73 Correct 1224 ms 40960 KB Output is correct
74 Correct 764 ms 40960 KB Output is correct
75 Correct 1246 ms 40960 KB Output is correct
76 Correct 983 ms 40960 KB Output is correct
77 Correct 910 ms 40960 KB Output is correct
78 Correct 1089 ms 40960 KB Output is correct
79 Correct 499 ms 40960 KB Output is correct
80 Correct 1014 ms 40960 KB Output is correct
81 Correct 986 ms 40960 KB Output is correct
82 Correct 779 ms 40960 KB Output is correct
83 Correct 1022 ms 40960 KB Output is correct
84 Correct 1010 ms 40960 KB Output is correct
85 Correct 1433 ms 40960 KB Output is correct
86 Correct 1388 ms 40960 KB Output is correct
87 Correct 1425 ms 40960 KB Output is correct
88 Correct 1372 ms 40960 KB Output is correct
89 Correct 132 ms 40960 KB Output is correct
90 Correct 168 ms 40960 KB Output is correct
91 Correct 123 ms 40960 KB Output is correct
92 Correct 127 ms 40960 KB Output is correct
93 Correct 1256 ms 40960 KB Output is correct
94 Correct 543 ms 40960 KB Output is correct
95 Correct 1254 ms 40960 KB Output is correct
96 Correct 601 ms 40960 KB Output is correct
97 Correct 1062 ms 40960 KB Output is correct
98 Correct 1026 ms 40960 KB Output is correct
99 Correct 966 ms 40960 KB Output is correct
100 Correct 1018 ms 40960 KB Output is correct
101 Correct 603 ms 40960 KB Output is correct
102 Correct 572 ms 40960 KB Output is correct
103 Correct 1025 ms 40960 KB Output is correct
104 Correct 999 ms 40960 KB Output is correct
105 Correct 1465 ms 40960 KB Output is correct
106 Correct 1453 ms 40960 KB Output is correct
107 Correct 1428 ms 40960 KB Output is correct
108 Correct 1413 ms 40960 KB Output is correct
109 Correct 670 ms 40960 KB Output is correct
110 Correct 951 ms 40960 KB Output is correct
111 Correct 1002 ms 40960 KB Output is correct
112 Correct 1020 ms 40960 KB Output is correct
113 Correct 127 ms 40960 KB Output is correct
114 Correct 121 ms 40960 KB Output is correct
115 Correct 141 ms 40960 KB Output is correct
116 Correct 134 ms 40960 KB Output is correct
117 Correct 923 ms 40960 KB Output is correct
118 Correct 643 ms 40960 KB Output is correct
119 Correct 473 ms 40960 KB Output is correct
120 Correct 943 ms 40960 KB Output is correct
121 Correct 1036 ms 40960 KB Output is correct
122 Correct 1039 ms 40960 KB Output is correct
123 Correct 784 ms 40960 KB Output is correct
124 Correct 496 ms 40960 KB Output is correct
125 Correct 283 ms 40960 KB Output is correct
126 Correct 288 ms 40960 KB Output is correct
127 Correct 329 ms 40960 KB Output is correct
128 Correct 317 ms 40960 KB Output is correct
129 Correct 254 ms 40960 KB Output is correct
130 Correct 280 ms 40960 KB Output is correct
131 Correct 2275 ms 40960 KB Output is correct
132 Correct 4852 ms 40960 KB Output is correct
133 Correct 4735 ms 40960 KB Output is correct
134 Correct 2506 ms 40960 KB Output is correct
135 Execution timed out 5094 ms 40960 KB Time limit exceeded
136 Halted 0 ms 0 KB -