Submission #634266

# Submission time Handle Problem Language Result Execution time Memory
634266 2022-08-24T08:09:53 Z drkarlicio2107 Segments (IZhO18_segments) C++14
75 / 100
5000 ms 8264 KB
#include <bits/stdc++.h>
using namespace std;
const int b=1000, m= ((2e5+10)+b-1)/b, siz=2e5+10; 
int q, t, ids, n, bc; int l[siz], r[siz]; bool unutra[siz];  
vector< pair <int, int> > TRE;  int mini[1000], maxi[1000]; 
vector<pair <int, int> > dulj[1010]; vector<pair <int, int> > answer[1010]; vector<pair <int, int> > tre;  
int num(int val) {
	return lower_bound(TRE.begin(), TRE.end(), make_pair (val, (int)-1e9))-TRE.begin(); 
}
int LESS(int rr, int k) {
	if (bc<=0) return 0; 
	int ind=0, ans=0; 
	while (ind<bc && maxi[ind]<=rr) {
		ans+=lower_bound(dulj[ind].begin(), dulj[ind].end(), make_pair(k, -1))-dulj[ind].begin(); ind+=1; 
	}
	for (int i=0; i<dulj [ind].size(); i++) if (dulj [ind][i].second<=rr && dulj [ind][i].first<k) ans++; 
	return ans; 
}
int MORE(int ll, int rr) {
	if (bc<=0) return 0; 
	int ans=0, ind=bc-1; 
	while (ind>0 && mini[ind]>rr) {
		ans+=(int)answer[ind].size()-(upper_bound(answer[ind].begin(), answer[ind].end(), make_pair(ll, (int)1e9))-answer[ind].begin()); ind-=1; 
	}
	for (int i=0; i<answer[ind].size(); i++) if (answer[ind][i].first>ll && answer[ind][i].second>rr) ans++; 
	return ans; 
}
int convert(int ll, int rr, int k) {
	return LESS(rr, k)-LESS(ll-1, k); 
}
int not_ok(int a1, int b1, int a2, int b2) {
	return b1<a2 ||  b2<a1; 
}
int query(int l1, int r1, int k) {
	if (r1-l1+1<k) return 0; 
	int ans=n-(convert(l1+k-1, r1, k)+MORE(r1-k+1, r1)+num(l1+k-1)); 
	for (int i=0; i<tre.size(); i++) 
		if (!k || (!not_ok(l[tre [i].first], r[tre [i].first], l1, r1) && min(r1, r[tre [i].first])-max(l1, l[tre [i].first])>=k-1)){
			if (tre [i].second) ans--;
			else ans++;
		}
	return ans; 
}
void did() {
	for (int i=0; i<tre.size(); i++) if (tre [i].second) unutra[tre [i].first]=1; 
	TRE.clear(); tre.clear(); 
	for (int i=1; i<ids+1; i++) if (!unutra[i]) TRE.push_back({r[i], i}); 
	sort(TRE.begin(), TRE.end()); n=TRE.size(); bc=(n+m-1)/m; 
	for (int b=0; b<=bc; b++) {
		dulj[b].clear(); answer[b].clear(); 
	}
	for (int b=0; b<bc; b++) {
		for (int i=b*m; i<min(n, (b+1)*m); i++){
			int ind=TRE[i].second; 
			dulj[b].push_back({r[ind]-l[ind]+1, r[ind]}); 
			answer[b].push_back({l[ind], r[ind]}); 
			maxi[b]=r[ind]; if (i==b*m) mini[b]=r[ind];  
 		}	
 		sort(dulj[b].begin(), dulj[b].end()); sort(answer[b].begin(), answer[b].end()); 
	}
	return ;
}
int main() {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);  
	cin >> q >> t; int lA=0;
	for (int i=1; i<=q; i++) {
		if (!(i % b)) did(); 
		int ty; cin >> ty; 
		if (ty==1) {
			ids++; cin >> l[ids] >> r[ids]; l[ids]^=t*lA; r[ids]^=t*lA; 
			if (l[ids]>r[ids]) swap(l[ids], r[ids]);
			tre.push_back({ids, 0}); 
		}
		else if (ty==2) {
			int j; cin >> j; tre.push_back({j, 1}); 
		}
		else {
			int l1, r1, k; cin >> l1 >> r1 >> k;  l1^=t*lA; r1^=t*lA; 
			if (l1>r1) swap(l1, r1);
			int ans=query(l1, r1, k); lA=ans;
			cout << ans << '\n'; 
		}
	}
	return 0;
}

Compilation message

segments.cpp: In function 'int LESS(int, int)':
segments.cpp:16:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   16 |  for (int i=0; i<dulj [ind].size(); i++) if (dulj [ind][i].second<=rr && dulj [ind][i].first<k) ans++;
      |                ~^~~~~~~~~~~~~~~~~~
segments.cpp: In function 'int MORE(int, int)':
segments.cpp:25:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |  for (int i=0; i<answer[ind].size(); i++) if (answer[ind][i].first>ll && answer[ind][i].second>rr) ans++;
      |                ~^~~~~~~~~~~~~~~~~~~
segments.cpp: In function 'int query(int, int, int)':
segments.cpp:37:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |  for (int i=0; i<tre.size(); i++)
      |                ~^~~~~~~~~~~
segments.cpp: In function 'void did()':
segments.cpp:45:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |  for (int i=0; i<tre.size(); i++) if (tre [i].second) unutra[tre [i].first]=1;
      |                ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 6 ms 420 KB Output is correct
4 Correct 5 ms 416 KB Output is correct
5 Correct 7 ms 468 KB Output is correct
6 Correct 7 ms 556 KB Output is correct
7 Correct 7 ms 340 KB Output is correct
8 Correct 7 ms 524 KB Output is correct
9 Correct 7 ms 468 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 10 ms 468 KB Output is correct
12 Correct 12 ms 516 KB Output is correct
13 Correct 6 ms 596 KB Output is correct
14 Correct 7 ms 508 KB Output is correct
15 Correct 5 ms 340 KB Output is correct
16 Correct 5 ms 340 KB Output is correct
17 Correct 8 ms 468 KB Output is correct
18 Correct 5 ms 468 KB Output is correct
19 Correct 7 ms 468 KB Output is correct
20 Correct 9 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1314 ms 2476 KB Output is correct
2 Correct 1329 ms 2720 KB Output is correct
3 Correct 1340 ms 2516 KB Output is correct
4 Correct 1386 ms 2548 KB Output is correct
5 Correct 995 ms 3900 KB Output is correct
6 Correct 923 ms 3892 KB Output is correct
7 Correct 1324 ms 2580 KB Output is correct
8 Correct 1339 ms 2616 KB Output is correct
9 Correct 1323 ms 2456 KB Output is correct
10 Correct 822 ms 1468 KB Output is correct
11 Correct 1008 ms 1736 KB Output is correct
12 Correct 1323 ms 3216 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 112 ms 700 KB Output is correct
2 Correct 97 ms 708 KB Output is correct
3 Correct 125 ms 908 KB Output is correct
4 Correct 102 ms 716 KB Output is correct
5 Correct 1139 ms 3224 KB Output is correct
6 Correct 1142 ms 3084 KB Output is correct
7 Correct 1166 ms 3428 KB Output is correct
8 Correct 926 ms 3796 KB Output is correct
9 Correct 892 ms 3840 KB Output is correct
10 Correct 921 ms 2972 KB Output is correct
11 Correct 202 ms 956 KB Output is correct
12 Correct 914 ms 3236 KB Output is correct
13 Correct 853 ms 2800 KB Output is correct
14 Correct 587 ms 1812 KB Output is correct
15 Correct 528 ms 1612 KB Output is correct
16 Correct 411 ms 1436 KB Output is correct
17 Correct 1112 ms 2468 KB Output is correct
18 Correct 1100 ms 2496 KB Output is correct
19 Correct 1085 ms 2472 KB Output is correct
20 Correct 1098 ms 2612 KB Output is correct
21 Correct 240 ms 1056 KB Output is correct
22 Correct 697 ms 1980 KB Output is correct
23 Correct 819 ms 2628 KB Output is correct
24 Correct 730 ms 2296 KB Output is correct
25 Correct 113 ms 748 KB Output is correct
26 Correct 99 ms 876 KB Output is correct
27 Correct 111 ms 728 KB Output is correct
28 Correct 101 ms 708 KB Output is correct
29 Correct 846 ms 2580 KB Output is correct
30 Correct 864 ms 2672 KB Output is correct
31 Correct 899 ms 3772 KB Output is correct
32 Correct 910 ms 3056 KB Output is correct
33 Correct 857 ms 2884 KB Output is correct
34 Correct 510 ms 1620 KB Output is correct
35 Correct 774 ms 2404 KB Output is correct
36 Correct 873 ms 2824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 108 ms 684 KB Output is correct
2 Correct 115 ms 712 KB Output is correct
3 Correct 113 ms 680 KB Output is correct
4 Correct 119 ms 664 KB Output is correct
5 Correct 1262 ms 3352 KB Output is correct
6 Correct 665 ms 1484 KB Output is correct
7 Correct 1175 ms 3464 KB Output is correct
8 Correct 845 ms 1480 KB Output is correct
9 Correct 748 ms 2064 KB Output is correct
10 Correct 975 ms 3344 KB Output is correct
11 Correct 419 ms 1228 KB Output is correct
12 Correct 888 ms 3860 KB Output is correct
13 Correct 913 ms 2800 KB Output is correct
14 Correct 686 ms 1876 KB Output is correct
15 Correct 915 ms 3624 KB Output is correct
16 Correct 944 ms 2916 KB Output is correct
17 Correct 1336 ms 2588 KB Output is correct
18 Correct 1313 ms 2552 KB Output is correct
19 Correct 1337 ms 2584 KB Output is correct
20 Correct 1317 ms 2720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 6 ms 420 KB Output is correct
4 Correct 5 ms 416 KB Output is correct
5 Correct 7 ms 468 KB Output is correct
6 Correct 7 ms 556 KB Output is correct
7 Correct 7 ms 340 KB Output is correct
8 Correct 7 ms 524 KB Output is correct
9 Correct 7 ms 468 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 10 ms 468 KB Output is correct
12 Correct 12 ms 516 KB Output is correct
13 Correct 6 ms 596 KB Output is correct
14 Correct 7 ms 508 KB Output is correct
15 Correct 5 ms 340 KB Output is correct
16 Correct 5 ms 340 KB Output is correct
17 Correct 8 ms 468 KB Output is correct
18 Correct 5 ms 468 KB Output is correct
19 Correct 7 ms 468 KB Output is correct
20 Correct 9 ms 596 KB Output is correct
21 Correct 1314 ms 2476 KB Output is correct
22 Correct 1329 ms 2720 KB Output is correct
23 Correct 1340 ms 2516 KB Output is correct
24 Correct 1386 ms 2548 KB Output is correct
25 Correct 995 ms 3900 KB Output is correct
26 Correct 923 ms 3892 KB Output is correct
27 Correct 1324 ms 2580 KB Output is correct
28 Correct 1339 ms 2616 KB Output is correct
29 Correct 1323 ms 2456 KB Output is correct
30 Correct 822 ms 1468 KB Output is correct
31 Correct 1008 ms 1736 KB Output is correct
32 Correct 1323 ms 3216 KB Output is correct
33 Correct 108 ms 684 KB Output is correct
34 Correct 115 ms 712 KB Output is correct
35 Correct 113 ms 680 KB Output is correct
36 Correct 119 ms 664 KB Output is correct
37 Correct 1262 ms 3352 KB Output is correct
38 Correct 665 ms 1484 KB Output is correct
39 Correct 1175 ms 3464 KB Output is correct
40 Correct 845 ms 1480 KB Output is correct
41 Correct 748 ms 2064 KB Output is correct
42 Correct 975 ms 3344 KB Output is correct
43 Correct 419 ms 1228 KB Output is correct
44 Correct 888 ms 3860 KB Output is correct
45 Correct 913 ms 2800 KB Output is correct
46 Correct 686 ms 1876 KB Output is correct
47 Correct 915 ms 3624 KB Output is correct
48 Correct 944 ms 2916 KB Output is correct
49 Correct 1336 ms 2588 KB Output is correct
50 Correct 1313 ms 2552 KB Output is correct
51 Correct 1337 ms 2584 KB Output is correct
52 Correct 1317 ms 2720 KB Output is correct
53 Correct 126 ms 680 KB Output is correct
54 Correct 122 ms 676 KB Output is correct
55 Correct 111 ms 744 KB Output is correct
56 Correct 112 ms 752 KB Output is correct
57 Correct 1096 ms 1976 KB Output is correct
58 Correct 510 ms 1204 KB Output is correct
59 Correct 1364 ms 3016 KB Output is correct
60 Correct 458 ms 1056 KB Output is correct
61 Correct 946 ms 2836 KB Output is correct
62 Correct 940 ms 3672 KB Output is correct
63 Correct 918 ms 3772 KB Output is correct
64 Correct 937 ms 3668 KB Output is correct
65 Correct 507 ms 1364 KB Output is correct
66 Correct 447 ms 1280 KB Output is correct
67 Correct 946 ms 3092 KB Output is correct
68 Correct 864 ms 2400 KB Output is correct
69 Correct 1323 ms 2592 KB Output is correct
70 Correct 1317 ms 2560 KB Output is correct
71 Correct 1318 ms 2456 KB Output is correct
72 Correct 1338 ms 2520 KB Output is correct
73 Correct 599 ms 1668 KB Output is correct
74 Correct 885 ms 2452 KB Output is correct
75 Correct 857 ms 4156 KB Output is correct
76 Correct 893 ms 4028 KB Output is correct
77 Correct 115 ms 712 KB Output is correct
78 Correct 110 ms 712 KB Output is correct
79 Correct 123 ms 744 KB Output is correct
80 Correct 115 ms 716 KB Output is correct
81 Correct 861 ms 2416 KB Output is correct
82 Correct 601 ms 1672 KB Output is correct
83 Correct 406 ms 1228 KB Output is correct
84 Correct 877 ms 2452 KB Output is correct
85 Correct 956 ms 3016 KB Output is correct
86 Correct 964 ms 3312 KB Output is correct
87 Correct 748 ms 2084 KB Output is correct
88 Correct 413 ms 1192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 6 ms 420 KB Output is correct
4 Correct 5 ms 416 KB Output is correct
5 Correct 7 ms 468 KB Output is correct
6 Correct 7 ms 556 KB Output is correct
7 Correct 7 ms 340 KB Output is correct
8 Correct 7 ms 524 KB Output is correct
9 Correct 7 ms 468 KB Output is correct
10 Correct 4 ms 468 KB Output is correct
11 Correct 10 ms 468 KB Output is correct
12 Correct 12 ms 516 KB Output is correct
13 Correct 6 ms 596 KB Output is correct
14 Correct 7 ms 508 KB Output is correct
15 Correct 5 ms 340 KB Output is correct
16 Correct 5 ms 340 KB Output is correct
17 Correct 8 ms 468 KB Output is correct
18 Correct 5 ms 468 KB Output is correct
19 Correct 7 ms 468 KB Output is correct
20 Correct 9 ms 596 KB Output is correct
21 Correct 1314 ms 2476 KB Output is correct
22 Correct 1329 ms 2720 KB Output is correct
23 Correct 1340 ms 2516 KB Output is correct
24 Correct 1386 ms 2548 KB Output is correct
25 Correct 995 ms 3900 KB Output is correct
26 Correct 923 ms 3892 KB Output is correct
27 Correct 1324 ms 2580 KB Output is correct
28 Correct 1339 ms 2616 KB Output is correct
29 Correct 1323 ms 2456 KB Output is correct
30 Correct 822 ms 1468 KB Output is correct
31 Correct 1008 ms 1736 KB Output is correct
32 Correct 1323 ms 3216 KB Output is correct
33 Correct 112 ms 700 KB Output is correct
34 Correct 97 ms 708 KB Output is correct
35 Correct 125 ms 908 KB Output is correct
36 Correct 102 ms 716 KB Output is correct
37 Correct 1139 ms 3224 KB Output is correct
38 Correct 1142 ms 3084 KB Output is correct
39 Correct 1166 ms 3428 KB Output is correct
40 Correct 926 ms 3796 KB Output is correct
41 Correct 892 ms 3840 KB Output is correct
42 Correct 921 ms 2972 KB Output is correct
43 Correct 202 ms 956 KB Output is correct
44 Correct 914 ms 3236 KB Output is correct
45 Correct 853 ms 2800 KB Output is correct
46 Correct 587 ms 1812 KB Output is correct
47 Correct 528 ms 1612 KB Output is correct
48 Correct 411 ms 1436 KB Output is correct
49 Correct 1112 ms 2468 KB Output is correct
50 Correct 1100 ms 2496 KB Output is correct
51 Correct 1085 ms 2472 KB Output is correct
52 Correct 1098 ms 2612 KB Output is correct
53 Correct 240 ms 1056 KB Output is correct
54 Correct 697 ms 1980 KB Output is correct
55 Correct 819 ms 2628 KB Output is correct
56 Correct 730 ms 2296 KB Output is correct
57 Correct 113 ms 748 KB Output is correct
58 Correct 99 ms 876 KB Output is correct
59 Correct 111 ms 728 KB Output is correct
60 Correct 101 ms 708 KB Output is correct
61 Correct 846 ms 2580 KB Output is correct
62 Correct 864 ms 2672 KB Output is correct
63 Correct 899 ms 3772 KB Output is correct
64 Correct 910 ms 3056 KB Output is correct
65 Correct 857 ms 2884 KB Output is correct
66 Correct 510 ms 1620 KB Output is correct
67 Correct 774 ms 2404 KB Output is correct
68 Correct 873 ms 2824 KB Output is correct
69 Correct 108 ms 684 KB Output is correct
70 Correct 115 ms 712 KB Output is correct
71 Correct 113 ms 680 KB Output is correct
72 Correct 119 ms 664 KB Output is correct
73 Correct 1262 ms 3352 KB Output is correct
74 Correct 665 ms 1484 KB Output is correct
75 Correct 1175 ms 3464 KB Output is correct
76 Correct 845 ms 1480 KB Output is correct
77 Correct 748 ms 2064 KB Output is correct
78 Correct 975 ms 3344 KB Output is correct
79 Correct 419 ms 1228 KB Output is correct
80 Correct 888 ms 3860 KB Output is correct
81 Correct 913 ms 2800 KB Output is correct
82 Correct 686 ms 1876 KB Output is correct
83 Correct 915 ms 3624 KB Output is correct
84 Correct 944 ms 2916 KB Output is correct
85 Correct 1336 ms 2588 KB Output is correct
86 Correct 1313 ms 2552 KB Output is correct
87 Correct 1337 ms 2584 KB Output is correct
88 Correct 1317 ms 2720 KB Output is correct
89 Correct 126 ms 680 KB Output is correct
90 Correct 122 ms 676 KB Output is correct
91 Correct 111 ms 744 KB Output is correct
92 Correct 112 ms 752 KB Output is correct
93 Correct 1096 ms 1976 KB Output is correct
94 Correct 510 ms 1204 KB Output is correct
95 Correct 1364 ms 3016 KB Output is correct
96 Correct 458 ms 1056 KB Output is correct
97 Correct 946 ms 2836 KB Output is correct
98 Correct 940 ms 3672 KB Output is correct
99 Correct 918 ms 3772 KB Output is correct
100 Correct 937 ms 3668 KB Output is correct
101 Correct 507 ms 1364 KB Output is correct
102 Correct 447 ms 1280 KB Output is correct
103 Correct 946 ms 3092 KB Output is correct
104 Correct 864 ms 2400 KB Output is correct
105 Correct 1323 ms 2592 KB Output is correct
106 Correct 1317 ms 2560 KB Output is correct
107 Correct 1318 ms 2456 KB Output is correct
108 Correct 1338 ms 2520 KB Output is correct
109 Correct 599 ms 1668 KB Output is correct
110 Correct 885 ms 2452 KB Output is correct
111 Correct 857 ms 4156 KB Output is correct
112 Correct 893 ms 4028 KB Output is correct
113 Correct 115 ms 712 KB Output is correct
114 Correct 110 ms 712 KB Output is correct
115 Correct 123 ms 744 KB Output is correct
116 Correct 115 ms 716 KB Output is correct
117 Correct 861 ms 2416 KB Output is correct
118 Correct 601 ms 1672 KB Output is correct
119 Correct 406 ms 1228 KB Output is correct
120 Correct 877 ms 2452 KB Output is correct
121 Correct 956 ms 3016 KB Output is correct
122 Correct 964 ms 3312 KB Output is correct
123 Correct 748 ms 2084 KB Output is correct
124 Correct 413 ms 1192 KB Output is correct
125 Correct 243 ms 1200 KB Output is correct
126 Correct 244 ms 1148 KB Output is correct
127 Correct 275 ms 1228 KB Output is correct
128 Correct 256 ms 1092 KB Output is correct
129 Correct 233 ms 1052 KB Output is correct
130 Correct 250 ms 1264 KB Output is correct
131 Correct 1834 ms 2092 KB Output is correct
132 Correct 4865 ms 4236 KB Output is correct
133 Execution timed out 5070 ms 8264 KB Time limit exceeded
134 Halted 0 ms 0 KB -