Submission #905239

# Submission time Handle Problem Language Result Execution time Memory
905239 2024-01-12T20:48:00 Z starchan Joker (BOI20_joker) C++17
100 / 100
369 ms 18280 KB
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define in pair<int, int>
#define f first
#define s second
#define pb push_back
#define pob pop_back
#define INF (int)1e17
#define MX (int)2e5+5
#define fast() ios_base::sync_with_stdio(false); cin.tie(NULL)
vector<int> pa(MX, -1);
vector<int> d(MX, 0);
bool works = true;
stack<in> roll;
in leader(int u)
{
	if(pa[u] < 0)
		return {u, 0};
	else
	{
		auto [v, x] = leader(pa[u]);
		return {v, x^d[u]};
	}
}

void undo()
{
	auto [v, w] = roll.top();
	roll.pop();
	if(w == 0)
	{
		works = v;
		return;
	}
	pa[v] = w;
	d[v] = 0;
	return;
}

void merge(int u, int v)
{

	auto [x, dx] = leader(u);
	auto [y, dy] = leader(v);

	if(x == y)
	{
		if(dx^dy^1)
		{
			roll.push({works, false});
			works =  false;
		}
		return;
	}

	if(pa[x] < pa[y])
		swap(x, y);//x has fewer elements now.
	roll.push({x, pa[x]});
	roll.push({y, pa[y]});
	pa[y]+=pa[x];
	pa[x] = y;
	d[x] = dx^dy^1;
	return;
}
//kk bipartite dsu (w rollback) ready.


vector<in> edges;
void add(int i)
{
	merge(edges[i].f, edges[i].s);
}

vector<int> opt;//opt[i] is smallest thing such that 1, 2, .., i-1, opt[i]+1, ..., n is bipartite. 
void dnc(int l, int r, int L, int R)//the DSU currently contains 1, 2, 3, .., l-1 and R+1, R+2, .., n
{
	if(l > r)
		return;
	int m = (l+r)/2;
	int SZ = roll.size();
	for(int i = l; i < m; i++)
		add(i);
	opt[m] = R;
	while(works && (opt[m] >= (m-1)))
	{
		add(opt[m]);
		opt[m]--;
	}
	opt[m]++;
	while(roll.size() > SZ)
		undo();
	for(int i = R; i > opt[m]; i--)
		add(i);
	dnc(l, m-1, L, opt[m]);
	while(roll.size() > SZ)
		undo();
	for(int i = l; i <= m; i++)
		add(i);
	dnc(m+1, r, opt[m], R);
	while(roll.size() > SZ)
		undo();
	return;
}
signed main()
{
	fast();
	int t = 1;
	while(t--)
	{
		int n, m, q;
		cin >> n >> m >> q;
		edges.resize(m+1);
		opt.resize(m+1);
		for(int i = 1; i <= m; i++)
			cin >> edges[i].f >> edges[i].s;
		int rr = INF;
		for(int i = 1; i <= m; i++)
		{
			add(i);
			if(works)
				continue;
			opt[i] = INF;
			rr = min(rr, i+1);
		}
		while(roll.size())
			undo();
		dnc(1, min(rr-1, m), 1, m);
		while(q--)
		{
			int l, r;
			cin >> l >> r;
			bool tt = (l < rr)&&(r>=opt[l]);
			cout << (tt? "NO\n" : "YES\n");
		}
	}
	return 0;
}	

Compilation message

Joker.cpp: In function 'void dnc(long long int, long long int, long long int, long long int)':
Joker.cpp:91:20: warning: comparison of integer expressions of different signedness: 'std::stack<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   91 |  while(roll.size() > SZ)
      |        ~~~~~~~~~~~~^~~~
Joker.cpp:96:20: warning: comparison of integer expressions of different signedness: 'std::stack<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   96 |  while(roll.size() > SZ)
      |        ~~~~~~~~~~~~^~~~
Joker.cpp:101:20: warning: comparison of integer expressions of different signedness: 'std::stack<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
  101 |  while(roll.size() > SZ)
      |        ~~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3416 KB Output is correct
2 Correct 2 ms 3420 KB Output is correct
3 Correct 2 ms 3416 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 2 ms 3416 KB Output is correct
7 Correct 2 ms 3420 KB Output is correct
8 Correct 2 ms 3420 KB Output is correct
9 Correct 2 ms 3420 KB Output is correct
10 Correct 2 ms 3420 KB Output is correct
11 Correct 2 ms 3416 KB Output is correct
12 Correct 2 ms 3416 KB Output is correct
13 Correct 2 ms 3420 KB Output is correct
14 Correct 3 ms 3420 KB Output is correct
15 Correct 2 ms 3420 KB Output is correct
16 Correct 2 ms 3420 KB Output is correct
17 Correct 2 ms 3420 KB Output is correct
18 Correct 2 ms 3424 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3428 KB Output is correct
21 Correct 2 ms 3428 KB Output is correct
22 Correct 2 ms 3428 KB Output is correct
23 Correct 2 ms 3428 KB Output is correct
24 Correct 2 ms 3428 KB Output is correct
25 Correct 2 ms 3428 KB Output is correct
26 Correct 2 ms 3428 KB Output is correct
27 Correct 2 ms 3428 KB Output is correct
28 Correct 2 ms 3428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3416 KB Output is correct
2 Correct 2 ms 3420 KB Output is correct
3 Correct 2 ms 3416 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 2 ms 3416 KB Output is correct
7 Correct 2 ms 3420 KB Output is correct
8 Correct 2 ms 3420 KB Output is correct
9 Correct 2 ms 3420 KB Output is correct
10 Correct 2 ms 3420 KB Output is correct
11 Correct 2 ms 3416 KB Output is correct
12 Correct 2 ms 3416 KB Output is correct
13 Correct 2 ms 3420 KB Output is correct
14 Correct 3 ms 3420 KB Output is correct
15 Correct 2 ms 3420 KB Output is correct
16 Correct 2 ms 3420 KB Output is correct
17 Correct 2 ms 3420 KB Output is correct
18 Correct 2 ms 3424 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3428 KB Output is correct
21 Correct 2 ms 3428 KB Output is correct
22 Correct 2 ms 3428 KB Output is correct
23 Correct 2 ms 3428 KB Output is correct
24 Correct 2 ms 3428 KB Output is correct
25 Correct 2 ms 3428 KB Output is correct
26 Correct 2 ms 3428 KB Output is correct
27 Correct 2 ms 3428 KB Output is correct
28 Correct 2 ms 3428 KB Output is correct
29 Correct 3 ms 3672 KB Output is correct
30 Correct 3 ms 3676 KB Output is correct
31 Correct 4 ms 3508 KB Output is correct
32 Correct 3 ms 3672 KB Output is correct
33 Correct 3 ms 3676 KB Output is correct
34 Correct 4 ms 3676 KB Output is correct
35 Correct 4 ms 3672 KB Output is correct
36 Correct 3 ms 3672 KB Output is correct
37 Correct 5 ms 3672 KB Output is correct
38 Correct 5 ms 3676 KB Output is correct
39 Correct 5 ms 3676 KB Output is correct
40 Correct 3 ms 3484 KB Output is correct
41 Correct 3 ms 3676 KB Output is correct
42 Correct 3 ms 3672 KB Output is correct
43 Correct 3 ms 3676 KB Output is correct
44 Correct 3 ms 3676 KB Output is correct
45 Correct 3 ms 3676 KB Output is correct
46 Correct 4 ms 3676 KB Output is correct
47 Correct 3 ms 3672 KB Output is correct
48 Correct 3 ms 3676 KB Output is correct
49 Correct 4 ms 3672 KB Output is correct
50 Correct 4 ms 3928 KB Output is correct
51 Correct 4 ms 3676 KB Output is correct
52 Correct 4 ms 3676 KB Output is correct
53 Correct 4 ms 3612 KB Output is correct
54 Correct 4 ms 3676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3416 KB Output is correct
2 Correct 2 ms 3420 KB Output is correct
3 Correct 186 ms 13056 KB Output is correct
4 Correct 357 ms 16892 KB Output is correct
5 Correct 204 ms 17044 KB Output is correct
6 Correct 156 ms 14676 KB Output is correct
7 Correct 167 ms 14540 KB Output is correct
8 Correct 183 ms 13080 KB Output is correct
9 Correct 211 ms 14156 KB Output is correct
10 Correct 265 ms 15956 KB Output is correct
11 Correct 187 ms 14672 KB Output is correct
12 Correct 235 ms 16104 KB Output is correct
13 Correct 179 ms 12420 KB Output is correct
14 Correct 173 ms 13144 KB Output is correct
15 Correct 236 ms 15432 KB Output is correct
16 Correct 267 ms 16460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3416 KB Output is correct
2 Correct 2 ms 3420 KB Output is correct
3 Correct 2 ms 3416 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 2 ms 3416 KB Output is correct
7 Correct 2 ms 3420 KB Output is correct
8 Correct 2 ms 3420 KB Output is correct
9 Correct 2 ms 3420 KB Output is correct
10 Correct 2 ms 3420 KB Output is correct
11 Correct 2 ms 3416 KB Output is correct
12 Correct 2 ms 3416 KB Output is correct
13 Correct 2 ms 3420 KB Output is correct
14 Correct 3 ms 3420 KB Output is correct
15 Correct 2 ms 3420 KB Output is correct
16 Correct 2 ms 3420 KB Output is correct
17 Correct 2 ms 3420 KB Output is correct
18 Correct 2 ms 3424 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3428 KB Output is correct
21 Correct 2 ms 3428 KB Output is correct
22 Correct 2 ms 3428 KB Output is correct
23 Correct 2 ms 3428 KB Output is correct
24 Correct 2 ms 3428 KB Output is correct
25 Correct 2 ms 3428 KB Output is correct
26 Correct 2 ms 3428 KB Output is correct
27 Correct 2 ms 3428 KB Output is correct
28 Correct 2 ms 3428 KB Output is correct
29 Correct 186 ms 13056 KB Output is correct
30 Correct 357 ms 16892 KB Output is correct
31 Correct 204 ms 17044 KB Output is correct
32 Correct 156 ms 14676 KB Output is correct
33 Correct 167 ms 14540 KB Output is correct
34 Correct 183 ms 13080 KB Output is correct
35 Correct 211 ms 14156 KB Output is correct
36 Correct 265 ms 15956 KB Output is correct
37 Correct 187 ms 14672 KB Output is correct
38 Correct 235 ms 16104 KB Output is correct
39 Correct 179 ms 12420 KB Output is correct
40 Correct 173 ms 13144 KB Output is correct
41 Correct 236 ms 15432 KB Output is correct
42 Correct 267 ms 16460 KB Output is correct
43 Correct 189 ms 15508 KB Output is correct
44 Correct 369 ms 16960 KB Output is correct
45 Correct 313 ms 17976 KB Output is correct
46 Correct 144 ms 14668 KB Output is correct
47 Correct 147 ms 14664 KB Output is correct
48 Correct 206 ms 14168 KB Output is correct
49 Correct 256 ms 16304 KB Output is correct
50 Correct 180 ms 13896 KB Output is correct
51 Correct 185 ms 15644 KB Output is correct
52 Correct 237 ms 16576 KB Output is correct
53 Correct 161 ms 12072 KB Output is correct
54 Correct 204 ms 13908 KB Output is correct
55 Correct 250 ms 15688 KB Output is correct
56 Correct 268 ms 16468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3416 KB Output is correct
2 Correct 2 ms 3420 KB Output is correct
3 Correct 2 ms 3416 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 2 ms 3416 KB Output is correct
7 Correct 2 ms 3420 KB Output is correct
8 Correct 2 ms 3420 KB Output is correct
9 Correct 2 ms 3420 KB Output is correct
10 Correct 2 ms 3420 KB Output is correct
11 Correct 2 ms 3416 KB Output is correct
12 Correct 2 ms 3416 KB Output is correct
13 Correct 2 ms 3420 KB Output is correct
14 Correct 3 ms 3420 KB Output is correct
15 Correct 2 ms 3420 KB Output is correct
16 Correct 2 ms 3420 KB Output is correct
17 Correct 2 ms 3420 KB Output is correct
18 Correct 2 ms 3424 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3428 KB Output is correct
21 Correct 2 ms 3428 KB Output is correct
22 Correct 2 ms 3428 KB Output is correct
23 Correct 2 ms 3428 KB Output is correct
24 Correct 2 ms 3428 KB Output is correct
25 Correct 2 ms 3428 KB Output is correct
26 Correct 2 ms 3428 KB Output is correct
27 Correct 2 ms 3428 KB Output is correct
28 Correct 2 ms 3428 KB Output is correct
29 Correct 3 ms 3672 KB Output is correct
30 Correct 3 ms 3676 KB Output is correct
31 Correct 4 ms 3508 KB Output is correct
32 Correct 3 ms 3672 KB Output is correct
33 Correct 3 ms 3676 KB Output is correct
34 Correct 4 ms 3676 KB Output is correct
35 Correct 4 ms 3672 KB Output is correct
36 Correct 3 ms 3672 KB Output is correct
37 Correct 5 ms 3672 KB Output is correct
38 Correct 5 ms 3676 KB Output is correct
39 Correct 5 ms 3676 KB Output is correct
40 Correct 3 ms 3484 KB Output is correct
41 Correct 3 ms 3676 KB Output is correct
42 Correct 3 ms 3672 KB Output is correct
43 Correct 3 ms 3676 KB Output is correct
44 Correct 3 ms 3676 KB Output is correct
45 Correct 3 ms 3676 KB Output is correct
46 Correct 4 ms 3676 KB Output is correct
47 Correct 3 ms 3672 KB Output is correct
48 Correct 3 ms 3676 KB Output is correct
49 Correct 4 ms 3672 KB Output is correct
50 Correct 4 ms 3928 KB Output is correct
51 Correct 4 ms 3676 KB Output is correct
52 Correct 4 ms 3676 KB Output is correct
53 Correct 4 ms 3612 KB Output is correct
54 Correct 4 ms 3676 KB Output is correct
55 Correct 155 ms 14676 KB Output is correct
56 Correct 318 ms 16380 KB Output is correct
57 Correct 170 ms 15848 KB Output is correct
58 Correct 128 ms 13904 KB Output is correct
59 Correct 180 ms 13652 KB Output is correct
60 Correct 217 ms 14880 KB Output is correct
61 Correct 177 ms 13652 KB Output is correct
62 Correct 235 ms 15188 KB Output is correct
63 Correct 134 ms 11600 KB Output is correct
64 Correct 191 ms 14164 KB Output is correct
65 Correct 226 ms 15184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3416 KB Output is correct
2 Correct 2 ms 3420 KB Output is correct
3 Correct 2 ms 3416 KB Output is correct
4 Correct 2 ms 3420 KB Output is correct
5 Correct 2 ms 3420 KB Output is correct
6 Correct 2 ms 3416 KB Output is correct
7 Correct 2 ms 3420 KB Output is correct
8 Correct 2 ms 3420 KB Output is correct
9 Correct 2 ms 3420 KB Output is correct
10 Correct 2 ms 3420 KB Output is correct
11 Correct 2 ms 3416 KB Output is correct
12 Correct 2 ms 3416 KB Output is correct
13 Correct 2 ms 3420 KB Output is correct
14 Correct 3 ms 3420 KB Output is correct
15 Correct 2 ms 3420 KB Output is correct
16 Correct 2 ms 3420 KB Output is correct
17 Correct 2 ms 3420 KB Output is correct
18 Correct 2 ms 3424 KB Output is correct
19 Correct 2 ms 3676 KB Output is correct
20 Correct 2 ms 3428 KB Output is correct
21 Correct 2 ms 3428 KB Output is correct
22 Correct 2 ms 3428 KB Output is correct
23 Correct 2 ms 3428 KB Output is correct
24 Correct 2 ms 3428 KB Output is correct
25 Correct 2 ms 3428 KB Output is correct
26 Correct 2 ms 3428 KB Output is correct
27 Correct 2 ms 3428 KB Output is correct
28 Correct 2 ms 3428 KB Output is correct
29 Correct 3 ms 3672 KB Output is correct
30 Correct 3 ms 3676 KB Output is correct
31 Correct 4 ms 3508 KB Output is correct
32 Correct 3 ms 3672 KB Output is correct
33 Correct 3 ms 3676 KB Output is correct
34 Correct 4 ms 3676 KB Output is correct
35 Correct 4 ms 3672 KB Output is correct
36 Correct 3 ms 3672 KB Output is correct
37 Correct 5 ms 3672 KB Output is correct
38 Correct 5 ms 3676 KB Output is correct
39 Correct 5 ms 3676 KB Output is correct
40 Correct 3 ms 3484 KB Output is correct
41 Correct 3 ms 3676 KB Output is correct
42 Correct 3 ms 3672 KB Output is correct
43 Correct 3 ms 3676 KB Output is correct
44 Correct 3 ms 3676 KB Output is correct
45 Correct 3 ms 3676 KB Output is correct
46 Correct 4 ms 3676 KB Output is correct
47 Correct 3 ms 3672 KB Output is correct
48 Correct 3 ms 3676 KB Output is correct
49 Correct 4 ms 3672 KB Output is correct
50 Correct 4 ms 3928 KB Output is correct
51 Correct 4 ms 3676 KB Output is correct
52 Correct 4 ms 3676 KB Output is correct
53 Correct 4 ms 3612 KB Output is correct
54 Correct 4 ms 3676 KB Output is correct
55 Correct 186 ms 13056 KB Output is correct
56 Correct 357 ms 16892 KB Output is correct
57 Correct 204 ms 17044 KB Output is correct
58 Correct 156 ms 14676 KB Output is correct
59 Correct 167 ms 14540 KB Output is correct
60 Correct 183 ms 13080 KB Output is correct
61 Correct 211 ms 14156 KB Output is correct
62 Correct 265 ms 15956 KB Output is correct
63 Correct 187 ms 14672 KB Output is correct
64 Correct 235 ms 16104 KB Output is correct
65 Correct 179 ms 12420 KB Output is correct
66 Correct 173 ms 13144 KB Output is correct
67 Correct 236 ms 15432 KB Output is correct
68 Correct 267 ms 16460 KB Output is correct
69 Correct 189 ms 15508 KB Output is correct
70 Correct 369 ms 16960 KB Output is correct
71 Correct 313 ms 17976 KB Output is correct
72 Correct 144 ms 14668 KB Output is correct
73 Correct 147 ms 14664 KB Output is correct
74 Correct 206 ms 14168 KB Output is correct
75 Correct 256 ms 16304 KB Output is correct
76 Correct 180 ms 13896 KB Output is correct
77 Correct 185 ms 15644 KB Output is correct
78 Correct 237 ms 16576 KB Output is correct
79 Correct 161 ms 12072 KB Output is correct
80 Correct 204 ms 13908 KB Output is correct
81 Correct 250 ms 15688 KB Output is correct
82 Correct 268 ms 16468 KB Output is correct
83 Correct 155 ms 14676 KB Output is correct
84 Correct 318 ms 16380 KB Output is correct
85 Correct 170 ms 15848 KB Output is correct
86 Correct 128 ms 13904 KB Output is correct
87 Correct 180 ms 13652 KB Output is correct
88 Correct 217 ms 14880 KB Output is correct
89 Correct 177 ms 13652 KB Output is correct
90 Correct 235 ms 15188 KB Output is correct
91 Correct 134 ms 11600 KB Output is correct
92 Correct 191 ms 14164 KB Output is correct
93 Correct 226 ms 15184 KB Output is correct
94 Correct 188 ms 15712 KB Output is correct
95 Correct 306 ms 18280 KB Output is correct
96 Correct 209 ms 17504 KB Output is correct
97 Correct 160 ms 15068 KB Output is correct
98 Correct 161 ms 14992 KB Output is correct
99 Correct 189 ms 13604 KB Output is correct
100 Correct 232 ms 16640 KB Output is correct
101 Correct 180 ms 14160 KB Output is correct
102 Correct 220 ms 15552 KB Output is correct
103 Correct 232 ms 16468 KB Output is correct
104 Correct 174 ms 13688 KB Output is correct
105 Correct 232 ms 15184 KB Output is correct
106 Correct 249 ms 16216 KB Output is correct
107 Correct 229 ms 18156 KB Output is correct
108 Correct 189 ms 15584 KB Output is correct
109 Correct 188 ms 15532 KB Output is correct
110 Correct 182 ms 15704 KB Output is correct
111 Correct 189 ms 15940 KB Output is correct
112 Correct 192 ms 15692 KB Output is correct
113 Correct 185 ms 15700 KB Output is correct
114 Correct 189 ms 15820 KB Output is correct
115 Correct 188 ms 15704 KB Output is correct
116 Correct 184 ms 15576 KB Output is correct