Submission #41726

# Submission time Handle Problem Language Result Execution time Memory
41726 2018-02-21T04:26:52 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 = 1250;

int n, t, sz, lastans;
int cnt;
int L[N], R[N];
bool del[N];
vector<int> buf_add;
vector<int> buf_del;
vector<int> block_l[500];
vector<int> block_r[500];
vector< pair<int, int> > go;

void prep() {
	go.clear();
	for (int i = 1; i <= sz; ++i) {
		if (!del[i]) go.push_back(make_pair(R[i] - L[i] + 1, i));
	}
	sort(go.begin(), go.end());
	buf_add.clear(), buf_del.clear();
	int m = go.size();
	for (int i = 0; i <= m / B; ++i) block_l[i].clear(), block_r[i].clear();
	for (int i = 0; i < m; ++i) block_l[i / B].push_back(L[go[i].second]);
	for (int i = 0; i < m; ++i) block_r[i / B].push_back(R[go[i].second]); 
	for (int i = 0; i <= m / B; ++i) {
		sort(block_l[i].begin(), block_l[i].end());
		sort(block_r[i].begin(), block_r[i].end());
	}
}

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].begin(), block_l[i].end(), x + 1) - block_l[i].begin();
		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].begin(), block_r[i].end(), x) - block_r[i].begin();
		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() {
	ios::sync_with_stdio(false);
	cin >> n >> t;
	for (int i = 1; i <= n; ++i) {
		if (i % B == 0) prep();

		int type; cin >> type;

		if (type == 1) {
			int l, r; cin >> 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.push_back(sz), cnt++;
		}

		if (type == 2) {
			int x; cin >> x, buf_del.push_back(x), del[x] = 1, cnt--;
		}

		if (type == 3) {
			int l, r, k; 
			cin >> 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, cout << "0\n"; continue;
			} 

			int res = 0;	

			// cout << "#add\n";
			// for (auto j : buf_add) cout << j << ' '; cout << '\n';
			// cout << "#del\n";
			// for (auto j : buf_del) cout << j << ' '; cout << '\n';

			for (auto j : buf_add) res += calc(j, l, r) < k;
			for (auto j : buf_del) res -= calc(j, l, r) < k;
			int p = lower_bound(go.begin(), go.end(), make_pair(k, 0)) - go.begin();

			// cout << "#go\n";
			// for (auto i : go) cout << i.second << ' '; cout << '\n';
			// cout << "#p " << p << '\n';

			// 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, go.size() - 1, r - k + 1);
			// count number of segments R < l + k - 1
			res += calR(p, go.size() - 1, l + k - 1);

			// cout << "#l-r " << l << ' ' << r << '\n';
			// cout << "# " << res << '\n';

			res = cnt - res, lastans = res;
			cout << res << '\n';
		}
	}
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 10 ms 552 KB Output is correct
4 Correct 9 ms 552 KB Output is correct
5 Correct 12 ms 740 KB Output is correct
6 Correct 12 ms 740 KB Output is correct
7 Correct 10 ms 740 KB Output is correct
8 Correct 10 ms 740 KB Output is correct
9 Correct 10 ms 740 KB Output is correct
10 Correct 7 ms 740 KB Output is correct
11 Correct 18 ms 740 KB Output is correct
12 Correct 20 ms 740 KB Output is correct
13 Correct 8 ms 864 KB Output is correct
14 Correct 11 ms 864 KB Output is correct
15 Correct 9 ms 864 KB Output is correct
16 Correct 9 ms 864 KB Output is correct
17 Correct 11 ms 864 KB Output is correct
18 Correct 8 ms 864 KB Output is correct
19 Correct 11 ms 864 KB Output is correct
20 Correct 13 ms 864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1462 ms 2732 KB Output is correct
2 Correct 1490 ms 5604 KB Output is correct
3 Correct 1480 ms 8176 KB Output is correct
4 Correct 1441 ms 10952 KB Output is correct
5 Correct 1000 ms 14132 KB Output is correct
6 Correct 947 ms 16296 KB Output is correct
7 Correct 1414 ms 18080 KB Output is correct
8 Correct 1453 ms 20740 KB Output is correct
9 Correct 1458 ms 23560 KB Output is correct
10 Correct 1044 ms 25620 KB Output is correct
11 Correct 1314 ms 28668 KB Output is correct
12 Correct 1223 ms 32300 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 174 ms 32300 KB Output is correct
2 Correct 161 ms 32300 KB Output is correct
3 Correct 202 ms 32300 KB Output is correct
4 Correct 170 ms 32300 KB Output is correct
5 Correct 1369 ms 32404 KB Output is correct
6 Correct 1550 ms 34412 KB Output is correct
7 Correct 1483 ms 36672 KB Output is correct
8 Correct 1072 ms 39668 KB Output is correct
9 Correct 972 ms 40960 KB Output is correct
10 Correct 1055 ms 40960 KB Output is correct
11 Correct 495 ms 40960 KB Output is correct
12 Correct 1079 ms 40960 KB Output is correct
13 Correct 1043 ms 40960 KB Output is correct
14 Correct 864 ms 40960 KB Output is correct
15 Correct 784 ms 40960 KB Output is correct
16 Correct 736 ms 40960 KB Output is correct
17 Correct 1759 ms 40960 KB Output is correct
18 Correct 1726 ms 40960 KB Output is correct
19 Correct 1717 ms 40960 KB Output is correct
20 Correct 1739 ms 40960 KB Output is correct
21 Correct 449 ms 40960 KB Output is correct
22 Correct 952 ms 40960 KB Output is correct
23 Correct 1022 ms 40960 KB Output is correct
24 Correct 999 ms 40960 KB Output is correct
25 Correct 182 ms 40960 KB Output is correct
26 Correct 170 ms 40960 KB Output is correct
27 Correct 199 ms 40960 KB Output is correct
28 Correct 181 ms 40960 KB Output is correct
29 Correct 1059 ms 40960 KB Output is correct
30 Correct 1098 ms 40960 KB Output is correct
31 Correct 1000 ms 40960 KB Output is correct
32 Correct 1057 ms 40960 KB Output is correct
33 Correct 1004 ms 40960 KB Output is correct
34 Correct 748 ms 40960 KB Output is correct
35 Correct 943 ms 40960 KB Output is correct
36 Correct 1020 ms 40960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 159 ms 40960 KB Output is correct
2 Correct 167 ms 40960 KB Output is correct
3 Correct 173 ms 40960 KB Output is correct
4 Correct 177 ms 40960 KB Output is correct
5 Correct 1244 ms 40960 KB Output is correct
6 Correct 752 ms 40960 KB Output is correct
7 Correct 1163 ms 40960 KB Output is correct
8 Correct 1050 ms 40960 KB Output is correct
9 Correct 822 ms 40960 KB Output is correct
10 Correct 1045 ms 40960 KB Output is correct
11 Correct 543 ms 40960 KB Output is correct
12 Correct 962 ms 40960 KB Output is correct
13 Correct 1020 ms 40960 KB Output is correct
14 Correct 796 ms 40960 KB Output is correct
15 Correct 990 ms 40960 KB Output is correct
16 Correct 1088 ms 40960 KB Output is correct
17 Correct 1546 ms 40960 KB Output is correct
18 Correct 1538 ms 40960 KB Output is correct
19 Correct 1602 ms 40960 KB Output is correct
20 Correct 1502 ms 40960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 10 ms 552 KB Output is correct
4 Correct 9 ms 552 KB Output is correct
5 Correct 12 ms 740 KB Output is correct
6 Correct 12 ms 740 KB Output is correct
7 Correct 10 ms 740 KB Output is correct
8 Correct 10 ms 740 KB Output is correct
9 Correct 10 ms 740 KB Output is correct
10 Correct 7 ms 740 KB Output is correct
11 Correct 18 ms 740 KB Output is correct
12 Correct 20 ms 740 KB Output is correct
13 Correct 8 ms 864 KB Output is correct
14 Correct 11 ms 864 KB Output is correct
15 Correct 9 ms 864 KB Output is correct
16 Correct 9 ms 864 KB Output is correct
17 Correct 11 ms 864 KB Output is correct
18 Correct 8 ms 864 KB Output is correct
19 Correct 11 ms 864 KB Output is correct
20 Correct 13 ms 864 KB Output is correct
21 Correct 1462 ms 2732 KB Output is correct
22 Correct 1490 ms 5604 KB Output is correct
23 Correct 1480 ms 8176 KB Output is correct
24 Correct 1441 ms 10952 KB Output is correct
25 Correct 1000 ms 14132 KB Output is correct
26 Correct 947 ms 16296 KB Output is correct
27 Correct 1414 ms 18080 KB Output is correct
28 Correct 1453 ms 20740 KB Output is correct
29 Correct 1458 ms 23560 KB Output is correct
30 Correct 1044 ms 25620 KB Output is correct
31 Correct 1314 ms 28668 KB Output is correct
32 Correct 1223 ms 32300 KB Output is correct
33 Correct 159 ms 40960 KB Output is correct
34 Correct 167 ms 40960 KB Output is correct
35 Correct 173 ms 40960 KB Output is correct
36 Correct 177 ms 40960 KB Output is correct
37 Correct 1244 ms 40960 KB Output is correct
38 Correct 752 ms 40960 KB Output is correct
39 Correct 1163 ms 40960 KB Output is correct
40 Correct 1050 ms 40960 KB Output is correct
41 Correct 822 ms 40960 KB Output is correct
42 Correct 1045 ms 40960 KB Output is correct
43 Correct 543 ms 40960 KB Output is correct
44 Correct 962 ms 40960 KB Output is correct
45 Correct 1020 ms 40960 KB Output is correct
46 Correct 796 ms 40960 KB Output is correct
47 Correct 990 ms 40960 KB Output is correct
48 Correct 1088 ms 40960 KB Output is correct
49 Correct 1546 ms 40960 KB Output is correct
50 Correct 1538 ms 40960 KB Output is correct
51 Correct 1602 ms 40960 KB Output is correct
52 Correct 1502 ms 40960 KB Output is correct
53 Correct 174 ms 40960 KB Output is correct
54 Correct 177 ms 40960 KB Output is correct
55 Correct 173 ms 40960 KB Output is correct
56 Correct 177 ms 40960 KB Output is correct
57 Correct 1234 ms 40960 KB Output is correct
58 Correct 679 ms 40960 KB Output is correct
59 Correct 1216 ms 40960 KB Output is correct
60 Correct 834 ms 40960 KB Output is correct
61 Correct 1063 ms 40960 KB Output is correct
62 Correct 1012 ms 40960 KB Output is correct
63 Correct 975 ms 40960 KB Output is correct
64 Correct 997 ms 40960 KB Output is correct
65 Correct 669 ms 40960 KB Output is correct
66 Correct 607 ms 40960 KB Output is correct
67 Correct 1041 ms 40960 KB Output is correct
68 Correct 930 ms 40960 KB Output is correct
69 Correct 1522 ms 40960 KB Output is correct
70 Correct 1529 ms 40960 KB Output is correct
71 Correct 1505 ms 40960 KB Output is correct
72 Correct 1495 ms 40960 KB Output is correct
73 Correct 699 ms 40960 KB Output is correct
74 Correct 904 ms 40960 KB Output is correct
75 Correct 933 ms 40960 KB Output is correct
76 Correct 968 ms 40960 KB Output is correct
77 Correct 171 ms 40960 KB Output is correct
78 Correct 171 ms 40960 KB Output is correct
79 Correct 178 ms 40960 KB Output is correct
80 Correct 174 ms 40960 KB Output is correct
81 Correct 893 ms 40960 KB Output is correct
82 Correct 665 ms 40960 KB Output is correct
83 Correct 509 ms 40960 KB Output is correct
84 Correct 877 ms 40960 KB Output is correct
85 Correct 1039 ms 40960 KB Output is correct
86 Correct 1038 ms 40960 KB Output is correct
87 Correct 856 ms 40960 KB Output is correct
88 Correct 622 ms 40960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 1 ms 376 KB Output is correct
3 Correct 10 ms 552 KB Output is correct
4 Correct 9 ms 552 KB Output is correct
5 Correct 12 ms 740 KB Output is correct
6 Correct 12 ms 740 KB Output is correct
7 Correct 10 ms 740 KB Output is correct
8 Correct 10 ms 740 KB Output is correct
9 Correct 10 ms 740 KB Output is correct
10 Correct 7 ms 740 KB Output is correct
11 Correct 18 ms 740 KB Output is correct
12 Correct 20 ms 740 KB Output is correct
13 Correct 8 ms 864 KB Output is correct
14 Correct 11 ms 864 KB Output is correct
15 Correct 9 ms 864 KB Output is correct
16 Correct 9 ms 864 KB Output is correct
17 Correct 11 ms 864 KB Output is correct
18 Correct 8 ms 864 KB Output is correct
19 Correct 11 ms 864 KB Output is correct
20 Correct 13 ms 864 KB Output is correct
21 Correct 1462 ms 2732 KB Output is correct
22 Correct 1490 ms 5604 KB Output is correct
23 Correct 1480 ms 8176 KB Output is correct
24 Correct 1441 ms 10952 KB Output is correct
25 Correct 1000 ms 14132 KB Output is correct
26 Correct 947 ms 16296 KB Output is correct
27 Correct 1414 ms 18080 KB Output is correct
28 Correct 1453 ms 20740 KB Output is correct
29 Correct 1458 ms 23560 KB Output is correct
30 Correct 1044 ms 25620 KB Output is correct
31 Correct 1314 ms 28668 KB Output is correct
32 Correct 1223 ms 32300 KB Output is correct
33 Correct 174 ms 32300 KB Output is correct
34 Correct 161 ms 32300 KB Output is correct
35 Correct 202 ms 32300 KB Output is correct
36 Correct 170 ms 32300 KB Output is correct
37 Correct 1369 ms 32404 KB Output is correct
38 Correct 1550 ms 34412 KB Output is correct
39 Correct 1483 ms 36672 KB Output is correct
40 Correct 1072 ms 39668 KB Output is correct
41 Correct 972 ms 40960 KB Output is correct
42 Correct 1055 ms 40960 KB Output is correct
43 Correct 495 ms 40960 KB Output is correct
44 Correct 1079 ms 40960 KB Output is correct
45 Correct 1043 ms 40960 KB Output is correct
46 Correct 864 ms 40960 KB Output is correct
47 Correct 784 ms 40960 KB Output is correct
48 Correct 736 ms 40960 KB Output is correct
49 Correct 1759 ms 40960 KB Output is correct
50 Correct 1726 ms 40960 KB Output is correct
51 Correct 1717 ms 40960 KB Output is correct
52 Correct 1739 ms 40960 KB Output is correct
53 Correct 449 ms 40960 KB Output is correct
54 Correct 952 ms 40960 KB Output is correct
55 Correct 1022 ms 40960 KB Output is correct
56 Correct 999 ms 40960 KB Output is correct
57 Correct 182 ms 40960 KB Output is correct
58 Correct 170 ms 40960 KB Output is correct
59 Correct 199 ms 40960 KB Output is correct
60 Correct 181 ms 40960 KB Output is correct
61 Correct 1059 ms 40960 KB Output is correct
62 Correct 1098 ms 40960 KB Output is correct
63 Correct 1000 ms 40960 KB Output is correct
64 Correct 1057 ms 40960 KB Output is correct
65 Correct 1004 ms 40960 KB Output is correct
66 Correct 748 ms 40960 KB Output is correct
67 Correct 943 ms 40960 KB Output is correct
68 Correct 1020 ms 40960 KB Output is correct
69 Correct 159 ms 40960 KB Output is correct
70 Correct 167 ms 40960 KB Output is correct
71 Correct 173 ms 40960 KB Output is correct
72 Correct 177 ms 40960 KB Output is correct
73 Correct 1244 ms 40960 KB Output is correct
74 Correct 752 ms 40960 KB Output is correct
75 Correct 1163 ms 40960 KB Output is correct
76 Correct 1050 ms 40960 KB Output is correct
77 Correct 822 ms 40960 KB Output is correct
78 Correct 1045 ms 40960 KB Output is correct
79 Correct 543 ms 40960 KB Output is correct
80 Correct 962 ms 40960 KB Output is correct
81 Correct 1020 ms 40960 KB Output is correct
82 Correct 796 ms 40960 KB Output is correct
83 Correct 990 ms 40960 KB Output is correct
84 Correct 1088 ms 40960 KB Output is correct
85 Correct 1546 ms 40960 KB Output is correct
86 Correct 1538 ms 40960 KB Output is correct
87 Correct 1602 ms 40960 KB Output is correct
88 Correct 1502 ms 40960 KB Output is correct
89 Correct 174 ms 40960 KB Output is correct
90 Correct 177 ms 40960 KB Output is correct
91 Correct 173 ms 40960 KB Output is correct
92 Correct 177 ms 40960 KB Output is correct
93 Correct 1234 ms 40960 KB Output is correct
94 Correct 679 ms 40960 KB Output is correct
95 Correct 1216 ms 40960 KB Output is correct
96 Correct 834 ms 40960 KB Output is correct
97 Correct 1063 ms 40960 KB Output is correct
98 Correct 1012 ms 40960 KB Output is correct
99 Correct 975 ms 40960 KB Output is correct
100 Correct 997 ms 40960 KB Output is correct
101 Correct 669 ms 40960 KB Output is correct
102 Correct 607 ms 40960 KB Output is correct
103 Correct 1041 ms 40960 KB Output is correct
104 Correct 930 ms 40960 KB Output is correct
105 Correct 1522 ms 40960 KB Output is correct
106 Correct 1529 ms 40960 KB Output is correct
107 Correct 1505 ms 40960 KB Output is correct
108 Correct 1495 ms 40960 KB Output is correct
109 Correct 699 ms 40960 KB Output is correct
110 Correct 904 ms 40960 KB Output is correct
111 Correct 933 ms 40960 KB Output is correct
112 Correct 968 ms 40960 KB Output is correct
113 Correct 171 ms 40960 KB Output is correct
114 Correct 171 ms 40960 KB Output is correct
115 Correct 178 ms 40960 KB Output is correct
116 Correct 174 ms 40960 KB Output is correct
117 Correct 893 ms 40960 KB Output is correct
118 Correct 665 ms 40960 KB Output is correct
119 Correct 509 ms 40960 KB Output is correct
120 Correct 877 ms 40960 KB Output is correct
121 Correct 1039 ms 40960 KB Output is correct
122 Correct 1038 ms 40960 KB Output is correct
123 Correct 856 ms 40960 KB Output is correct
124 Correct 622 ms 40960 KB Output is correct
125 Correct 342 ms 40960 KB Output is correct
126 Correct 345 ms 40960 KB Output is correct
127 Correct 397 ms 40960 KB Output is correct
128 Correct 351 ms 40960 KB Output is correct
129 Correct 336 ms 40960 KB Output is correct
130 Correct 370 ms 40960 KB Output is correct
131 Correct 2631 ms 40960 KB Output is correct
132 Correct 4363 ms 40960 KB Output is correct
133 Correct 4733 ms 40960 KB Output is correct
134 Correct 2581 ms 40960 KB Output is correct
135 Execution timed out 5059 ms 40960 KB Time limit exceeded
136 Halted 0 ms 0 KB -