Submission #634248

# Submission time Handle Problem Language Result Execution time Memory
634248 2022-08-24T07:49:35 Z drkarlicio2107 Segments (IZhO18_segments) C++14
75 / 100
5000 ms 13548 KB
#include <bits/stdc++.h>
using namespace std;
const int b=500, 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[siz], maxi[siz]; 
vector<pair <int, int> > dulj[siz]; vector<pair <int, int> > answer[siz]; 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 5 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 8 ms 9756 KB Output is correct
4 Correct 8 ms 9684 KB Output is correct
5 Correct 14 ms 9944 KB Output is correct
6 Correct 16 ms 9968 KB Output is correct
7 Correct 12 ms 9684 KB Output is correct
8 Correct 13 ms 9812 KB Output is correct
9 Correct 12 ms 9812 KB Output is correct
10 Correct 13 ms 9940 KB Output is correct
11 Correct 17 ms 9868 KB Output is correct
12 Correct 16 ms 9812 KB Output is correct
13 Correct 12 ms 9908 KB Output is correct
14 Correct 13 ms 9804 KB Output is correct
15 Correct 8 ms 9684 KB Output is correct
16 Correct 9 ms 9776 KB Output is correct
17 Correct 13 ms 9812 KB Output is correct
18 Correct 12 ms 9792 KB Output is correct
19 Correct 12 ms 9820 KB Output is correct
20 Correct 13 ms 9812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1920 ms 11876 KB Output is correct
2 Correct 1896 ms 11988 KB Output is correct
3 Correct 1888 ms 11984 KB Output is correct
4 Correct 1965 ms 12192 KB Output is correct
5 Correct 1884 ms 13192 KB Output is correct
6 Correct 1839 ms 13248 KB Output is correct
7 Correct 1923 ms 12020 KB Output is correct
8 Correct 1904 ms 11720 KB Output is correct
9 Correct 1924 ms 11820 KB Output is correct
10 Correct 1128 ms 10740 KB Output is correct
11 Correct 1379 ms 11096 KB Output is correct
12 Correct 2063 ms 12568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 115 ms 10152 KB Output is correct
2 Correct 72 ms 10068 KB Output is correct
3 Correct 131 ms 10072 KB Output is correct
4 Correct 77 ms 10016 KB Output is correct
5 Correct 1979 ms 12720 KB Output is correct
6 Correct 1865 ms 12144 KB Output is correct
7 Correct 1919 ms 12552 KB Output is correct
8 Correct 1861 ms 13072 KB Output is correct
9 Correct 1863 ms 13128 KB Output is correct
10 Correct 1785 ms 12428 KB Output is correct
11 Correct 272 ms 10244 KB Output is correct
12 Correct 1727 ms 12684 KB Output is correct
13 Correct 1654 ms 12076 KB Output is correct
14 Correct 1032 ms 11040 KB Output is correct
15 Correct 928 ms 11060 KB Output is correct
16 Correct 666 ms 10736 KB Output is correct
17 Correct 1749 ms 12004 KB Output is correct
18 Correct 1739 ms 11968 KB Output is correct
19 Correct 1802 ms 11912 KB Output is correct
20 Correct 1798 ms 11828 KB Output is correct
21 Correct 349 ms 10376 KB Output is correct
22 Correct 1291 ms 11280 KB Output is correct
23 Correct 1528 ms 11720 KB Output is correct
24 Correct 1395 ms 11472 KB Output is correct
25 Correct 108 ms 10048 KB Output is correct
26 Correct 86 ms 10100 KB Output is correct
27 Correct 102 ms 10052 KB Output is correct
28 Correct 111 ms 10152 KB Output is correct
29 Correct 1620 ms 11968 KB Output is correct
30 Correct 1711 ms 11948 KB Output is correct
31 Correct 2078 ms 13168 KB Output is correct
32 Correct 1911 ms 12552 KB Output is correct
33 Correct 1613 ms 12100 KB Output is correct
34 Correct 876 ms 11112 KB Output is correct
35 Correct 1427 ms 11888 KB Output is correct
36 Correct 1653 ms 12368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 85 ms 10064 KB Output is correct
2 Correct 81 ms 10008 KB Output is correct
3 Correct 86 ms 10072 KB Output is correct
4 Correct 94 ms 10060 KB Output is correct
5 Correct 2047 ms 12724 KB Output is correct
6 Correct 905 ms 10848 KB Output is correct
7 Correct 2035 ms 13096 KB Output is correct
8 Correct 1167 ms 10908 KB Output is correct
9 Correct 1241 ms 11344 KB Output is correct
10 Correct 1827 ms 12692 KB Output is correct
11 Correct 614 ms 10620 KB Output is correct
12 Correct 1812 ms 13312 KB Output is correct
13 Correct 1656 ms 12068 KB Output is correct
14 Correct 1124 ms 11140 KB Output is correct
15 Correct 1834 ms 13176 KB Output is correct
16 Correct 1708 ms 12324 KB Output is correct
17 Correct 1893 ms 11904 KB Output is correct
18 Correct 1889 ms 11904 KB Output is correct
19 Correct 1886 ms 11756 KB Output is correct
20 Correct 1885 ms 11876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 8 ms 9756 KB Output is correct
4 Correct 8 ms 9684 KB Output is correct
5 Correct 14 ms 9944 KB Output is correct
6 Correct 16 ms 9968 KB Output is correct
7 Correct 12 ms 9684 KB Output is correct
8 Correct 13 ms 9812 KB Output is correct
9 Correct 12 ms 9812 KB Output is correct
10 Correct 13 ms 9940 KB Output is correct
11 Correct 17 ms 9868 KB Output is correct
12 Correct 16 ms 9812 KB Output is correct
13 Correct 12 ms 9908 KB Output is correct
14 Correct 13 ms 9804 KB Output is correct
15 Correct 8 ms 9684 KB Output is correct
16 Correct 9 ms 9776 KB Output is correct
17 Correct 13 ms 9812 KB Output is correct
18 Correct 12 ms 9792 KB Output is correct
19 Correct 12 ms 9820 KB Output is correct
20 Correct 13 ms 9812 KB Output is correct
21 Correct 1920 ms 11876 KB Output is correct
22 Correct 1896 ms 11988 KB Output is correct
23 Correct 1888 ms 11984 KB Output is correct
24 Correct 1965 ms 12192 KB Output is correct
25 Correct 1884 ms 13192 KB Output is correct
26 Correct 1839 ms 13248 KB Output is correct
27 Correct 1923 ms 12020 KB Output is correct
28 Correct 1904 ms 11720 KB Output is correct
29 Correct 1924 ms 11820 KB Output is correct
30 Correct 1128 ms 10740 KB Output is correct
31 Correct 1379 ms 11096 KB Output is correct
32 Correct 2063 ms 12568 KB Output is correct
33 Correct 85 ms 10064 KB Output is correct
34 Correct 81 ms 10008 KB Output is correct
35 Correct 86 ms 10072 KB Output is correct
36 Correct 94 ms 10060 KB Output is correct
37 Correct 2047 ms 12724 KB Output is correct
38 Correct 905 ms 10848 KB Output is correct
39 Correct 2035 ms 13096 KB Output is correct
40 Correct 1167 ms 10908 KB Output is correct
41 Correct 1241 ms 11344 KB Output is correct
42 Correct 1827 ms 12692 KB Output is correct
43 Correct 614 ms 10620 KB Output is correct
44 Correct 1812 ms 13312 KB Output is correct
45 Correct 1656 ms 12068 KB Output is correct
46 Correct 1124 ms 11140 KB Output is correct
47 Correct 1834 ms 13176 KB Output is correct
48 Correct 1708 ms 12324 KB Output is correct
49 Correct 1893 ms 11904 KB Output is correct
50 Correct 1889 ms 11904 KB Output is correct
51 Correct 1886 ms 11756 KB Output is correct
52 Correct 1885 ms 11876 KB Output is correct
53 Correct 96 ms 10072 KB Output is correct
54 Correct 97 ms 10124 KB Output is correct
55 Correct 84 ms 10036 KB Output is correct
56 Correct 86 ms 10028 KB Output is correct
57 Correct 1522 ms 11432 KB Output is correct
58 Correct 706 ms 10644 KB Output is correct
59 Correct 2074 ms 12312 KB Output is correct
60 Correct 661 ms 10544 KB Output is correct
61 Correct 1681 ms 12196 KB Output is correct
62 Correct 1872 ms 12972 KB Output is correct
63 Correct 1829 ms 13336 KB Output is correct
64 Correct 1829 ms 13108 KB Output is correct
65 Correct 789 ms 10984 KB Output is correct
66 Correct 675 ms 10804 KB Output is correct
67 Correct 1735 ms 12508 KB Output is correct
68 Correct 1474 ms 11828 KB Output is correct
69 Correct 1859 ms 11812 KB Output is correct
70 Correct 1891 ms 12016 KB Output is correct
71 Correct 1898 ms 11800 KB Output is correct
72 Correct 1878 ms 12000 KB Output is correct
73 Correct 918 ms 10868 KB Output is correct
74 Correct 1475 ms 11644 KB Output is correct
75 Correct 1835 ms 13276 KB Output is correct
76 Correct 1848 ms 13256 KB Output is correct
77 Correct 94 ms 10072 KB Output is correct
78 Correct 85 ms 10060 KB Output is correct
79 Correct 96 ms 10180 KB Output is correct
80 Correct 85 ms 10092 KB Output is correct
81 Correct 1432 ms 11604 KB Output is correct
82 Correct 926 ms 11056 KB Output is correct
83 Correct 576 ms 10764 KB Output is correct
84 Correct 1488 ms 11764 KB Output is correct
85 Correct 1731 ms 12236 KB Output is correct
86 Correct 1721 ms 12632 KB Output is correct
87 Correct 1236 ms 11672 KB Output is correct
88 Correct 596 ms 10608 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9684 KB Output is correct
2 Correct 4 ms 9684 KB Output is correct
3 Correct 8 ms 9756 KB Output is correct
4 Correct 8 ms 9684 KB Output is correct
5 Correct 14 ms 9944 KB Output is correct
6 Correct 16 ms 9968 KB Output is correct
7 Correct 12 ms 9684 KB Output is correct
8 Correct 13 ms 9812 KB Output is correct
9 Correct 12 ms 9812 KB Output is correct
10 Correct 13 ms 9940 KB Output is correct
11 Correct 17 ms 9868 KB Output is correct
12 Correct 16 ms 9812 KB Output is correct
13 Correct 12 ms 9908 KB Output is correct
14 Correct 13 ms 9804 KB Output is correct
15 Correct 8 ms 9684 KB Output is correct
16 Correct 9 ms 9776 KB Output is correct
17 Correct 13 ms 9812 KB Output is correct
18 Correct 12 ms 9792 KB Output is correct
19 Correct 12 ms 9820 KB Output is correct
20 Correct 13 ms 9812 KB Output is correct
21 Correct 1920 ms 11876 KB Output is correct
22 Correct 1896 ms 11988 KB Output is correct
23 Correct 1888 ms 11984 KB Output is correct
24 Correct 1965 ms 12192 KB Output is correct
25 Correct 1884 ms 13192 KB Output is correct
26 Correct 1839 ms 13248 KB Output is correct
27 Correct 1923 ms 12020 KB Output is correct
28 Correct 1904 ms 11720 KB Output is correct
29 Correct 1924 ms 11820 KB Output is correct
30 Correct 1128 ms 10740 KB Output is correct
31 Correct 1379 ms 11096 KB Output is correct
32 Correct 2063 ms 12568 KB Output is correct
33 Correct 115 ms 10152 KB Output is correct
34 Correct 72 ms 10068 KB Output is correct
35 Correct 131 ms 10072 KB Output is correct
36 Correct 77 ms 10016 KB Output is correct
37 Correct 1979 ms 12720 KB Output is correct
38 Correct 1865 ms 12144 KB Output is correct
39 Correct 1919 ms 12552 KB Output is correct
40 Correct 1861 ms 13072 KB Output is correct
41 Correct 1863 ms 13128 KB Output is correct
42 Correct 1785 ms 12428 KB Output is correct
43 Correct 272 ms 10244 KB Output is correct
44 Correct 1727 ms 12684 KB Output is correct
45 Correct 1654 ms 12076 KB Output is correct
46 Correct 1032 ms 11040 KB Output is correct
47 Correct 928 ms 11060 KB Output is correct
48 Correct 666 ms 10736 KB Output is correct
49 Correct 1749 ms 12004 KB Output is correct
50 Correct 1739 ms 11968 KB Output is correct
51 Correct 1802 ms 11912 KB Output is correct
52 Correct 1798 ms 11828 KB Output is correct
53 Correct 349 ms 10376 KB Output is correct
54 Correct 1291 ms 11280 KB Output is correct
55 Correct 1528 ms 11720 KB Output is correct
56 Correct 1395 ms 11472 KB Output is correct
57 Correct 108 ms 10048 KB Output is correct
58 Correct 86 ms 10100 KB Output is correct
59 Correct 102 ms 10052 KB Output is correct
60 Correct 111 ms 10152 KB Output is correct
61 Correct 1620 ms 11968 KB Output is correct
62 Correct 1711 ms 11948 KB Output is correct
63 Correct 2078 ms 13168 KB Output is correct
64 Correct 1911 ms 12552 KB Output is correct
65 Correct 1613 ms 12100 KB Output is correct
66 Correct 876 ms 11112 KB Output is correct
67 Correct 1427 ms 11888 KB Output is correct
68 Correct 1653 ms 12368 KB Output is correct
69 Correct 85 ms 10064 KB Output is correct
70 Correct 81 ms 10008 KB Output is correct
71 Correct 86 ms 10072 KB Output is correct
72 Correct 94 ms 10060 KB Output is correct
73 Correct 2047 ms 12724 KB Output is correct
74 Correct 905 ms 10848 KB Output is correct
75 Correct 2035 ms 13096 KB Output is correct
76 Correct 1167 ms 10908 KB Output is correct
77 Correct 1241 ms 11344 KB Output is correct
78 Correct 1827 ms 12692 KB Output is correct
79 Correct 614 ms 10620 KB Output is correct
80 Correct 1812 ms 13312 KB Output is correct
81 Correct 1656 ms 12068 KB Output is correct
82 Correct 1124 ms 11140 KB Output is correct
83 Correct 1834 ms 13176 KB Output is correct
84 Correct 1708 ms 12324 KB Output is correct
85 Correct 1893 ms 11904 KB Output is correct
86 Correct 1889 ms 11904 KB Output is correct
87 Correct 1886 ms 11756 KB Output is correct
88 Correct 1885 ms 11876 KB Output is correct
89 Correct 96 ms 10072 KB Output is correct
90 Correct 97 ms 10124 KB Output is correct
91 Correct 84 ms 10036 KB Output is correct
92 Correct 86 ms 10028 KB Output is correct
93 Correct 1522 ms 11432 KB Output is correct
94 Correct 706 ms 10644 KB Output is correct
95 Correct 2074 ms 12312 KB Output is correct
96 Correct 661 ms 10544 KB Output is correct
97 Correct 1681 ms 12196 KB Output is correct
98 Correct 1872 ms 12972 KB Output is correct
99 Correct 1829 ms 13336 KB Output is correct
100 Correct 1829 ms 13108 KB Output is correct
101 Correct 789 ms 10984 KB Output is correct
102 Correct 675 ms 10804 KB Output is correct
103 Correct 1735 ms 12508 KB Output is correct
104 Correct 1474 ms 11828 KB Output is correct
105 Correct 1859 ms 11812 KB Output is correct
106 Correct 1891 ms 12016 KB Output is correct
107 Correct 1898 ms 11800 KB Output is correct
108 Correct 1878 ms 12000 KB Output is correct
109 Correct 918 ms 10868 KB Output is correct
110 Correct 1475 ms 11644 KB Output is correct
111 Correct 1835 ms 13276 KB Output is correct
112 Correct 1848 ms 13256 KB Output is correct
113 Correct 94 ms 10072 KB Output is correct
114 Correct 85 ms 10060 KB Output is correct
115 Correct 96 ms 10180 KB Output is correct
116 Correct 85 ms 10092 KB Output is correct
117 Correct 1432 ms 11604 KB Output is correct
118 Correct 926 ms 11056 KB Output is correct
119 Correct 576 ms 10764 KB Output is correct
120 Correct 1488 ms 11764 KB Output is correct
121 Correct 1731 ms 12236 KB Output is correct
122 Correct 1721 ms 12632 KB Output is correct
123 Correct 1236 ms 11672 KB Output is correct
124 Correct 596 ms 10608 KB Output is correct
125 Correct 184 ms 10508 KB Output is correct
126 Correct 198 ms 10536 KB Output is correct
127 Correct 293 ms 10540 KB Output is correct
128 Correct 221 ms 10480 KB Output is correct
129 Correct 177 ms 10504 KB Output is correct
130 Correct 215 ms 10528 KB Output is correct
131 Correct 2480 ms 11432 KB Output is correct
132 Execution timed out 5076 ms 13548 KB Time limit exceeded
133 Halted 0 ms 0 KB -