Submission #908928

# Submission time Handle Problem Language Result Execution time Memory
908928 2024-01-17T02:15:03 Z daoquanglinh2007 Segments (IZhO18_segments) C++17
75 / 100
5000 ms 22724 KB
#include <bits/stdc++.h>
using namespace std;
 
#define pii pair <int, int>
#define fi first
#define se second
#define mp make_pair
#define isz(a) (int)(a).size()
 
const int NM = 2e5, BL = 2e4, S = 450, inf = 2e9+11;
 
int n, t, type[NM+5], a[NM+5], b[NM+5], id[NM+5], k[NM+5], lastans = 0;
int num = 0, l[NM+5], r[NM+5];
bool del[NM+5];
int sz, sz1, sz2;
vector <pii> v;
vector <int> arr, arr1, arr2;
vector <pii> f[NM+5], g[NM+5], sf[S+5], sg[S+5];
int cnt[NM+5];
 
void update(vector <pii> f[NM+5], vector <pii> sf[S+5], int x, int y){
	if (f[x].empty()) f[x].push_back(mp(y, 1));
	else if (f[x].back().fi < y) f[x].push_back(mp(y, f[x].back().se+1));
	else f[x].back().se++;
	
	int sx = x/S;
	if (sf[sx].empty()) sf[sx].push_back(mp(y, 1));
	else if (sf[sx].back().fi < y) sf[sx].push_back(mp(y, sf[sx].back().se+1));
	else sf[sx].back().se++;
}
 
int get(vector <pii> f[NM+5], vector <pii> sf[S+5], int x, int y){
	int res = 0, z;
	for (int i = 0; i < x/S; i++){
		if (sf[i].empty() || y < sf[i][0].fi);
		else if (y >= sf[i].back().fi) res += sf[i].back().se;
		else{
			z = upper_bound(sf[i].begin(), sf[i].end(), mp(y, +inf))-sf[i].begin();
			res += sf[i][z-1].se;
		}
	}
	for (int i = x/S*S; i <= x; i++){
		if (f[i].empty() || y < f[i][0].fi);
		else if (y >= f[i].back().fi) res += f[i].back().se;
		else{
			z = upper_bound(f[i].begin(), f[i].end(), mp(y, +inf))-f[i].begin();
			res += f[i][z-1].se;
		}
	}
	return res;
}
 
void process(){
	v.clear();
	arr.clear();
	arr1.clear();
	arr2.clear();
	for (int i = 1; i <= num; i++)
		if (!del[i]){
			v.push_back(mp(l[i], r[i]));
			arr.push_back(-(r[i]-l[i]+1));
			arr1.push_back(-l[i]);
			arr2.push_back(r[i]);
		}
	sort(v.begin(), v.end(), [&](pii a, pii b){
		return a.se-a.fi+1 > b.se-b.fi+1;
	});	
	sort(arr.begin(), arr.end()); arr.erase(unique(arr.begin(), arr.end()), arr.end());
	sort(arr1.begin(), arr1.end()); arr1.erase(unique(arr1.begin(), arr1.end()), arr1.end());
	sort(arr2.begin(), arr2.end()); arr2.erase(unique(arr2.begin(), arr2.end()), arr2.end());
	
	sz = isz(arr), sz1 = isz(arr1), sz2 = isz(arr2);
	
	assert(sz <= NM);
	assert(sz1 <= NM);
	assert(sz2 <= NM);
	
	for (int i = 1; i <= sz1; i++) f[i].clear();
	for (int i = 1; i <= sz2; i++) g[i].clear();
	
	for (int i = 0; i <= S; i++){
		sf[i].clear();
		sg[i].clear();
	}
	
	memset(cnt, 0, sizeof(cnt));
	int j = 0;
	for (pii P : v){
		update(f, sf, lower_bound(arr1.begin(), arr1.end(), -P.fi)-arr1.begin()+1, -(P.se-P.fi+1));
		update(g, sg, lower_bound(arr2.begin(), arr2.end(), P.se)-arr2.begin()+1, -(P.se-P.fi+1));
		while (arr[j] < -(P.se-P.fi+1)) j++;
		cnt[j+1]++;
	}
	
	for (int i = 1; i <= sz; i++) cnt[i] += cnt[i-1];
}
 
int find_pos(vector <int> &v, int x){
	if (v.empty()) return 0;
	if (x < v[0]) return 0;
	if (x >= v.back()) return isz(v);
	return upper_bound(v.begin(), v.end(), x)-v.begin();
}
 
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	cin >> n >> t;
	for (int i = 0; i < n; i++){
		cin >> type[i];
		if (type[i] == 1){
			cin >> a[i] >> b[i];
			a[i] ^= (t*lastans), b[i] ^= (t*lastans);
			if (a[i] > b[i]) swap(a[i], b[i]);
			l[++num] = a[i], r[num] = b[i];
		}
		else if (type[i] == 2){
			cin >> id[i];
			del[id[i]] = 1;
		}
		else{
			cin >> a[i] >> b[i] >> k[i];
			a[i] ^= (t*lastans), b[i] ^= (t*lastans);
			if (a[i] > b[i]) swap(a[i], b[i]);
			if (b[i]-a[i]+1 < k[i]) lastans = 0;
			else{
				lastans = cnt[find_pos(arr, -k[i])]-get(f, sf, find_pos(arr1, -b[i]+k[i]-2), -k[i])
			          -get(g, sg, find_pos(arr2, a[i] < +inf-(k[i]-2) ? a[i]+k[i]-2 : +inf), -k[i]);
			          
				for (int j = i-i%BL; j < i; j++){
					if (type[j] == 1){
						int lo = max(a[j], a[i]), hi = min(b[j], b[i]);
						if (hi-lo+1 >= k[i]) lastans++;
					}
					else if (type[j] == 2){
						int lo = max(l[id[j]], a[i]), hi = min(r[id[j]], b[i]);
						if (hi-lo+1 >= k[i]) lastans--;
					}
				}
			}
			cout << lastans << '\n';
		}
		if (i%BL == BL-1 && i < n-1){
			process();
		}
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12636 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 32 ms 13088 KB Output is correct
4 Correct 32 ms 12996 KB Output is correct
5 Correct 22 ms 12636 KB Output is correct
6 Correct 30 ms 12836 KB Output is correct
7 Correct 29 ms 12832 KB Output is correct
8 Correct 20 ms 12636 KB Output is correct
9 Correct 24 ms 12636 KB Output is correct
10 Correct 9 ms 12636 KB Output is correct
11 Correct 35 ms 12828 KB Output is correct
12 Correct 38 ms 12824 KB Output is correct
13 Correct 11 ms 12832 KB Output is correct
14 Correct 21 ms 12820 KB Output is correct
15 Correct 28 ms 12636 KB Output is correct
16 Correct 29 ms 12824 KB Output is correct
17 Correct 28 ms 12820 KB Output is correct
18 Correct 11 ms 12636 KB Output is correct
19 Correct 29 ms 12836 KB Output is correct
20 Correct 28 ms 12840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1173 ms 19356 KB Output is correct
2 Correct 1163 ms 19376 KB Output is correct
3 Correct 1176 ms 19160 KB Output is correct
4 Correct 1041 ms 19916 KB Output is correct
5 Correct 603 ms 22472 KB Output is correct
6 Correct 381 ms 22720 KB Output is correct
7 Correct 1112 ms 19168 KB Output is correct
8 Correct 1109 ms 19368 KB Output is correct
9 Correct 1114 ms 19292 KB Output is correct
10 Correct 893 ms 16224 KB Output is correct
11 Correct 1186 ms 17004 KB Output is correct
12 Correct 916 ms 21408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2819 ms 14264 KB Output is correct
2 Correct 2802 ms 14456 KB Output is correct
3 Correct 2844 ms 14252 KB Output is correct
4 Correct 2810 ms 14204 KB Output is correct
5 Correct 827 ms 21712 KB Output is correct
6 Correct 470 ms 20364 KB Output is correct
7 Correct 788 ms 21024 KB Output is correct
8 Correct 565 ms 22468 KB Output is correct
9 Correct 481 ms 22464 KB Output is correct
10 Correct 1312 ms 21284 KB Output is correct
11 Correct 2821 ms 15012 KB Output is correct
12 Correct 1249 ms 21476 KB Output is correct
13 Correct 1328 ms 20176 KB Output is correct
14 Correct 2057 ms 17196 KB Output is correct
15 Correct 2135 ms 16724 KB Output is correct
16 Correct 2275 ms 16152 KB Output is correct
17 Correct 973 ms 19448 KB Output is correct
18 Correct 963 ms 19440 KB Output is correct
19 Correct 962 ms 19360 KB Output is correct
20 Correct 954 ms 19444 KB Output is correct
21 Correct 2792 ms 14748 KB Output is correct
22 Correct 2114 ms 18192 KB Output is correct
23 Correct 1800 ms 19664 KB Output is correct
24 Correct 2063 ms 18220 KB Output is correct
25 Correct 2803 ms 14248 KB Output is correct
26 Correct 2795 ms 14112 KB Output is correct
27 Correct 2790 ms 14156 KB Output is correct
28 Correct 2829 ms 14232 KB Output is correct
29 Correct 1645 ms 19568 KB Output is correct
30 Correct 1619 ms 19448 KB Output is correct
31 Correct 438 ms 22500 KB Output is correct
32 Correct 1284 ms 21068 KB Output is correct
33 Correct 1283 ms 20032 KB Output is correct
34 Correct 2159 ms 16500 KB Output is correct
35 Correct 1634 ms 19228 KB Output is correct
36 Correct 1189 ms 20780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2550 ms 14148 KB Output is correct
2 Correct 2551 ms 14364 KB Output is correct
3 Correct 2563 ms 14376 KB Output is correct
4 Correct 2577 ms 14112 KB Output is correct
5 Correct 693 ms 22008 KB Output is correct
6 Correct 1181 ms 15940 KB Output is correct
7 Correct 592 ms 22324 KB Output is correct
8 Correct 896 ms 16724 KB Output is correct
9 Correct 2028 ms 17748 KB Output is correct
10 Correct 1062 ms 21700 KB Output is correct
11 Correct 2459 ms 15404 KB Output is correct
12 Correct 290 ms 22508 KB Output is correct
13 Correct 1536 ms 19964 KB Output is correct
14 Correct 2218 ms 17624 KB Output is correct
15 Correct 543 ms 22724 KB Output is correct
16 Correct 1416 ms 20424 KB Output is correct
17 Correct 1110 ms 19412 KB Output is correct
18 Correct 1097 ms 19404 KB Output is correct
19 Correct 1126 ms 19332 KB Output is correct
20 Correct 1147 ms 19148 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12636 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 32 ms 13088 KB Output is correct
4 Correct 32 ms 12996 KB Output is correct
5 Correct 22 ms 12636 KB Output is correct
6 Correct 30 ms 12836 KB Output is correct
7 Correct 29 ms 12832 KB Output is correct
8 Correct 20 ms 12636 KB Output is correct
9 Correct 24 ms 12636 KB Output is correct
10 Correct 9 ms 12636 KB Output is correct
11 Correct 35 ms 12828 KB Output is correct
12 Correct 38 ms 12824 KB Output is correct
13 Correct 11 ms 12832 KB Output is correct
14 Correct 21 ms 12820 KB Output is correct
15 Correct 28 ms 12636 KB Output is correct
16 Correct 29 ms 12824 KB Output is correct
17 Correct 28 ms 12820 KB Output is correct
18 Correct 11 ms 12636 KB Output is correct
19 Correct 29 ms 12836 KB Output is correct
20 Correct 28 ms 12840 KB Output is correct
21 Correct 1173 ms 19356 KB Output is correct
22 Correct 1163 ms 19376 KB Output is correct
23 Correct 1176 ms 19160 KB Output is correct
24 Correct 1041 ms 19916 KB Output is correct
25 Correct 603 ms 22472 KB Output is correct
26 Correct 381 ms 22720 KB Output is correct
27 Correct 1112 ms 19168 KB Output is correct
28 Correct 1109 ms 19368 KB Output is correct
29 Correct 1114 ms 19292 KB Output is correct
30 Correct 893 ms 16224 KB Output is correct
31 Correct 1186 ms 17004 KB Output is correct
32 Correct 916 ms 21408 KB Output is correct
33 Correct 2550 ms 14148 KB Output is correct
34 Correct 2551 ms 14364 KB Output is correct
35 Correct 2563 ms 14376 KB Output is correct
36 Correct 2577 ms 14112 KB Output is correct
37 Correct 693 ms 22008 KB Output is correct
38 Correct 1181 ms 15940 KB Output is correct
39 Correct 592 ms 22324 KB Output is correct
40 Correct 896 ms 16724 KB Output is correct
41 Correct 2028 ms 17748 KB Output is correct
42 Correct 1062 ms 21700 KB Output is correct
43 Correct 2459 ms 15404 KB Output is correct
44 Correct 290 ms 22508 KB Output is correct
45 Correct 1536 ms 19964 KB Output is correct
46 Correct 2218 ms 17624 KB Output is correct
47 Correct 543 ms 22724 KB Output is correct
48 Correct 1416 ms 20424 KB Output is correct
49 Correct 1110 ms 19412 KB Output is correct
50 Correct 1097 ms 19404 KB Output is correct
51 Correct 1126 ms 19332 KB Output is correct
52 Correct 1147 ms 19148 KB Output is correct
53 Correct 2580 ms 14208 KB Output is correct
54 Correct 2585 ms 14368 KB Output is correct
55 Correct 2588 ms 14024 KB Output is correct
56 Correct 2581 ms 14372 KB Output is correct
57 Correct 1187 ms 17476 KB Output is correct
58 Correct 1217 ms 15304 KB Output is correct
59 Correct 732 ms 20424 KB Output is correct
60 Correct 1182 ms 14896 KB Output is correct
61 Correct 1458 ms 20284 KB Output is correct
62 Correct 610 ms 22504 KB Output is correct
63 Correct 374 ms 22496 KB Output is correct
64 Correct 584 ms 22500 KB Output is correct
65 Correct 2497 ms 16212 KB Output is correct
66 Correct 2579 ms 15696 KB Output is correct
67 Correct 1395 ms 20424 KB Output is correct
68 Correct 1823 ms 19064 KB Output is correct
69 Correct 1134 ms 19232 KB Output is correct
70 Correct 1117 ms 19144 KB Output is correct
71 Correct 1093 ms 19356 KB Output is correct
72 Correct 1121 ms 19300 KB Output is correct
73 Correct 2290 ms 16584 KB Output is correct
74 Correct 1716 ms 18848 KB Output is correct
75 Correct 202 ms 22588 KB Output is correct
76 Correct 381 ms 22652 KB Output is correct
77 Correct 2562 ms 14424 KB Output is correct
78 Correct 2593 ms 14108 KB Output is correct
79 Correct 2596 ms 14164 KB Output is correct
80 Correct 2541 ms 14092 KB Output is correct
81 Correct 1813 ms 18796 KB Output is correct
82 Correct 2319 ms 16588 KB Output is correct
83 Correct 2502 ms 16072 KB Output is correct
84 Correct 1818 ms 19308 KB Output is correct
85 Correct 1362 ms 20744 KB Output is correct
86 Correct 1288 ms 21372 KB Output is correct
87 Correct 2141 ms 18052 KB Output is correct
88 Correct 2582 ms 15412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 12636 KB Output is correct
2 Correct 3 ms 12636 KB Output is correct
3 Correct 32 ms 13088 KB Output is correct
4 Correct 32 ms 12996 KB Output is correct
5 Correct 22 ms 12636 KB Output is correct
6 Correct 30 ms 12836 KB Output is correct
7 Correct 29 ms 12832 KB Output is correct
8 Correct 20 ms 12636 KB Output is correct
9 Correct 24 ms 12636 KB Output is correct
10 Correct 9 ms 12636 KB Output is correct
11 Correct 35 ms 12828 KB Output is correct
12 Correct 38 ms 12824 KB Output is correct
13 Correct 11 ms 12832 KB Output is correct
14 Correct 21 ms 12820 KB Output is correct
15 Correct 28 ms 12636 KB Output is correct
16 Correct 29 ms 12824 KB Output is correct
17 Correct 28 ms 12820 KB Output is correct
18 Correct 11 ms 12636 KB Output is correct
19 Correct 29 ms 12836 KB Output is correct
20 Correct 28 ms 12840 KB Output is correct
21 Correct 1173 ms 19356 KB Output is correct
22 Correct 1163 ms 19376 KB Output is correct
23 Correct 1176 ms 19160 KB Output is correct
24 Correct 1041 ms 19916 KB Output is correct
25 Correct 603 ms 22472 KB Output is correct
26 Correct 381 ms 22720 KB Output is correct
27 Correct 1112 ms 19168 KB Output is correct
28 Correct 1109 ms 19368 KB Output is correct
29 Correct 1114 ms 19292 KB Output is correct
30 Correct 893 ms 16224 KB Output is correct
31 Correct 1186 ms 17004 KB Output is correct
32 Correct 916 ms 21408 KB Output is correct
33 Correct 2819 ms 14264 KB Output is correct
34 Correct 2802 ms 14456 KB Output is correct
35 Correct 2844 ms 14252 KB Output is correct
36 Correct 2810 ms 14204 KB Output is correct
37 Correct 827 ms 21712 KB Output is correct
38 Correct 470 ms 20364 KB Output is correct
39 Correct 788 ms 21024 KB Output is correct
40 Correct 565 ms 22468 KB Output is correct
41 Correct 481 ms 22464 KB Output is correct
42 Correct 1312 ms 21284 KB Output is correct
43 Correct 2821 ms 15012 KB Output is correct
44 Correct 1249 ms 21476 KB Output is correct
45 Correct 1328 ms 20176 KB Output is correct
46 Correct 2057 ms 17196 KB Output is correct
47 Correct 2135 ms 16724 KB Output is correct
48 Correct 2275 ms 16152 KB Output is correct
49 Correct 973 ms 19448 KB Output is correct
50 Correct 963 ms 19440 KB Output is correct
51 Correct 962 ms 19360 KB Output is correct
52 Correct 954 ms 19444 KB Output is correct
53 Correct 2792 ms 14748 KB Output is correct
54 Correct 2114 ms 18192 KB Output is correct
55 Correct 1800 ms 19664 KB Output is correct
56 Correct 2063 ms 18220 KB Output is correct
57 Correct 2803 ms 14248 KB Output is correct
58 Correct 2795 ms 14112 KB Output is correct
59 Correct 2790 ms 14156 KB Output is correct
60 Correct 2829 ms 14232 KB Output is correct
61 Correct 1645 ms 19568 KB Output is correct
62 Correct 1619 ms 19448 KB Output is correct
63 Correct 438 ms 22500 KB Output is correct
64 Correct 1284 ms 21068 KB Output is correct
65 Correct 1283 ms 20032 KB Output is correct
66 Correct 2159 ms 16500 KB Output is correct
67 Correct 1634 ms 19228 KB Output is correct
68 Correct 1189 ms 20780 KB Output is correct
69 Correct 2550 ms 14148 KB Output is correct
70 Correct 2551 ms 14364 KB Output is correct
71 Correct 2563 ms 14376 KB Output is correct
72 Correct 2577 ms 14112 KB Output is correct
73 Correct 693 ms 22008 KB Output is correct
74 Correct 1181 ms 15940 KB Output is correct
75 Correct 592 ms 22324 KB Output is correct
76 Correct 896 ms 16724 KB Output is correct
77 Correct 2028 ms 17748 KB Output is correct
78 Correct 1062 ms 21700 KB Output is correct
79 Correct 2459 ms 15404 KB Output is correct
80 Correct 290 ms 22508 KB Output is correct
81 Correct 1536 ms 19964 KB Output is correct
82 Correct 2218 ms 17624 KB Output is correct
83 Correct 543 ms 22724 KB Output is correct
84 Correct 1416 ms 20424 KB Output is correct
85 Correct 1110 ms 19412 KB Output is correct
86 Correct 1097 ms 19404 KB Output is correct
87 Correct 1126 ms 19332 KB Output is correct
88 Correct 1147 ms 19148 KB Output is correct
89 Correct 2580 ms 14208 KB Output is correct
90 Correct 2585 ms 14368 KB Output is correct
91 Correct 2588 ms 14024 KB Output is correct
92 Correct 2581 ms 14372 KB Output is correct
93 Correct 1187 ms 17476 KB Output is correct
94 Correct 1217 ms 15304 KB Output is correct
95 Correct 732 ms 20424 KB Output is correct
96 Correct 1182 ms 14896 KB Output is correct
97 Correct 1458 ms 20284 KB Output is correct
98 Correct 610 ms 22504 KB Output is correct
99 Correct 374 ms 22496 KB Output is correct
100 Correct 584 ms 22500 KB Output is correct
101 Correct 2497 ms 16212 KB Output is correct
102 Correct 2579 ms 15696 KB Output is correct
103 Correct 1395 ms 20424 KB Output is correct
104 Correct 1823 ms 19064 KB Output is correct
105 Correct 1134 ms 19232 KB Output is correct
106 Correct 1117 ms 19144 KB Output is correct
107 Correct 1093 ms 19356 KB Output is correct
108 Correct 1121 ms 19300 KB Output is correct
109 Correct 2290 ms 16584 KB Output is correct
110 Correct 1716 ms 18848 KB Output is correct
111 Correct 202 ms 22588 KB Output is correct
112 Correct 381 ms 22652 KB Output is correct
113 Correct 2562 ms 14424 KB Output is correct
114 Correct 2593 ms 14108 KB Output is correct
115 Correct 2596 ms 14164 KB Output is correct
116 Correct 2541 ms 14092 KB Output is correct
117 Correct 1813 ms 18796 KB Output is correct
118 Correct 2319 ms 16588 KB Output is correct
119 Correct 2502 ms 16072 KB Output is correct
120 Correct 1818 ms 19308 KB Output is correct
121 Correct 1362 ms 20744 KB Output is correct
122 Correct 1288 ms 21372 KB Output is correct
123 Correct 2141 ms 18052 KB Output is correct
124 Correct 2582 ms 15412 KB Output is correct
125 Execution timed out 5101 ms 15372 KB Time limit exceeded
126 Halted 0 ms 0 KB -