Submission #439549

# Submission time Handle Problem Language Result Execution time Memory
439549 2021-06-30T08:35:03 Z soroush Joker (BOI20_joker) C++17
100 / 100
348 ms 13368 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int , int> pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int maxn = 4e5+10;
const ll mod = 1e9+7;

#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n, m, q;
int a[maxn], b[maxn], par[maxn] , mn[maxn];
vector < pii > und;

int getpar(int v){
	while(par[v] > 0)v = par[v];
	return v;
}

void merge(int u, int v){
	if((u = getpar(u)) == (v = getpar(v)))return;
	if(par[v] < par[u])swap(u , v);
	und.pb({v, par[v]});
	par[u] += par[v] , par[v] = u;
}

void undo(){
	auto [v , w] = und.back() ; und.pop_back();
	par[par[v]] -= w , par[v] =  w;
}

void solve(int l , int r , int ur){
	if(l > r)return;
	int mid = (l + r) >> 1 , cp = und.size();
	for(int i = max(1 , l) ; i <= mid ; i ++){
		merge(a[i] , b[i] + n);
		merge(b[i] , a[i] + n);
		if(getpar(a[i]) == getpar(b[i])){
			for(int j = mid ; j <= r ; j ++)
				mn[j] = ur;
			while(und.size() > cp)undo();
			solve(l , mid - 1 , ur);
			return;
		}
	}
	int chp = und.size();
	for(int i = ur - 1 ; i > l ; i --){
		merge(a[i] , b[i] + n);
		merge(b[i] , a[i] + n);
		if(getpar(a[i]) == getpar(a[i] + n)){
			mn[mid] = i;
			break;
		}
	}
	while(und.size() > chp)undo();
	solve(mid + 1 , r , ur);
	while(und.size() > cp)undo();
	for(int i = ur - 1 ; i >= max(mn[mid] , l + 1) ; i --){
		merge(a[i] , b[i] + n);
		merge(b[i] , a[i] + n);
		if(getpar(a[i]) == getpar(b[i])){
			for(int j = l ; j < mid ; j ++)
				mn[j] = mn[mid];
			return;
		}
	}
	solve(l , mid - 1 , mn[mid]);
}

int32_t main(){
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin >> n >> m >> q;
	ms(par, -1);
	for(int i = 1 ; i <= m ; i ++)
		cin >> a[i] >> b[i];
	solve(0 , m - 1 , m + 1);
	while(q --){
		int l , r;
		cin >> l >> r;
		cout << ((r < mn[l - 1]) ? "YES" : "NO") << endl;
	}
	return(0);
}

Compilation message

Joker.cpp: In function 'void solve(int, int, int)':
Joker.cpp:50:21: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   50 |    while(und.size() > cp)undo();
      |          ~~~~~~~~~~~^~~~
Joker.cpp:64:19: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   64 |  while(und.size() > chp)undo();
      |        ~~~~~~~~~~~^~~~~
Joker.cpp:66:19: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   66 |  while(und.size() > cp)undo();
      |        ~~~~~~~~~~~^~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1868 KB Output is correct
6 Correct 2 ms 1868 KB Output is correct
7 Correct 2 ms 1908 KB Output is correct
8 Correct 3 ms 1868 KB Output is correct
9 Correct 2 ms 1868 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1864 KB Output is correct
13 Correct 2 ms 1864 KB Output is correct
14 Correct 2 ms 1848 KB Output is correct
15 Correct 2 ms 1868 KB Output is correct
16 Correct 2 ms 1860 KB Output is correct
17 Correct 2 ms 1868 KB Output is correct
18 Correct 2 ms 1864 KB Output is correct
19 Correct 2 ms 1868 KB Output is correct
20 Correct 1 ms 1868 KB Output is correct
21 Correct 2 ms 1868 KB Output is correct
22 Correct 2 ms 1868 KB Output is correct
23 Correct 2 ms 1868 KB Output is correct
24 Correct 1 ms 1868 KB Output is correct
25 Correct 2 ms 1864 KB Output is correct
26 Correct 2 ms 1868 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 2 ms 1864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1868 KB Output is correct
6 Correct 2 ms 1868 KB Output is correct
7 Correct 2 ms 1908 KB Output is correct
8 Correct 3 ms 1868 KB Output is correct
9 Correct 2 ms 1868 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1864 KB Output is correct
13 Correct 2 ms 1864 KB Output is correct
14 Correct 2 ms 1848 KB Output is correct
15 Correct 2 ms 1868 KB Output is correct
16 Correct 2 ms 1860 KB Output is correct
17 Correct 2 ms 1868 KB Output is correct
18 Correct 2 ms 1864 KB Output is correct
19 Correct 2 ms 1868 KB Output is correct
20 Correct 1 ms 1868 KB Output is correct
21 Correct 2 ms 1868 KB Output is correct
22 Correct 2 ms 1868 KB Output is correct
23 Correct 2 ms 1868 KB Output is correct
24 Correct 1 ms 1868 KB Output is correct
25 Correct 2 ms 1864 KB Output is correct
26 Correct 2 ms 1868 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 2 ms 1864 KB Output is correct
29 Correct 2 ms 1876 KB Output is correct
30 Correct 3 ms 1996 KB Output is correct
31 Correct 4 ms 1996 KB Output is correct
32 Correct 4 ms 1996 KB Output is correct
33 Correct 3 ms 1868 KB Output is correct
34 Correct 3 ms 1996 KB Output is correct
35 Correct 3 ms 1996 KB Output is correct
36 Correct 4 ms 1996 KB Output is correct
37 Correct 4 ms 1996 KB Output is correct
38 Correct 5 ms 1996 KB Output is correct
39 Correct 3 ms 2004 KB Output is correct
40 Correct 3 ms 1952 KB Output is correct
41 Correct 3 ms 1996 KB Output is correct
42 Correct 4 ms 2000 KB Output is correct
43 Correct 3 ms 1996 KB Output is correct
44 Correct 3 ms 1996 KB Output is correct
45 Correct 3 ms 2008 KB Output is correct
46 Correct 4 ms 1996 KB Output is correct
47 Correct 4 ms 1996 KB Output is correct
48 Correct 3 ms 1996 KB Output is correct
49 Correct 3 ms 1996 KB Output is correct
50 Correct 4 ms 1996 KB Output is correct
51 Correct 4 ms 1996 KB Output is correct
52 Correct 3 ms 1952 KB Output is correct
53 Correct 3 ms 1996 KB Output is correct
54 Correct 4 ms 1996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 261 ms 6556 KB Output is correct
4 Correct 240 ms 7624 KB Output is correct
5 Correct 164 ms 11984 KB Output is correct
6 Correct 174 ms 10516 KB Output is correct
7 Correct 169 ms 10480 KB Output is correct
8 Correct 169 ms 9336 KB Output is correct
9 Correct 202 ms 9784 KB Output is correct
10 Correct 301 ms 10248 KB Output is correct
11 Correct 240 ms 10272 KB Output is correct
12 Correct 272 ms 10796 KB Output is correct
13 Correct 189 ms 9144 KB Output is correct
14 Correct 182 ms 9864 KB Output is correct
15 Correct 300 ms 10480 KB Output is correct
16 Correct 312 ms 10684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1868 KB Output is correct
6 Correct 2 ms 1868 KB Output is correct
7 Correct 2 ms 1908 KB Output is correct
8 Correct 3 ms 1868 KB Output is correct
9 Correct 2 ms 1868 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1864 KB Output is correct
13 Correct 2 ms 1864 KB Output is correct
14 Correct 2 ms 1848 KB Output is correct
15 Correct 2 ms 1868 KB Output is correct
16 Correct 2 ms 1860 KB Output is correct
17 Correct 2 ms 1868 KB Output is correct
18 Correct 2 ms 1864 KB Output is correct
19 Correct 2 ms 1868 KB Output is correct
20 Correct 1 ms 1868 KB Output is correct
21 Correct 2 ms 1868 KB Output is correct
22 Correct 2 ms 1868 KB Output is correct
23 Correct 2 ms 1868 KB Output is correct
24 Correct 1 ms 1868 KB Output is correct
25 Correct 2 ms 1864 KB Output is correct
26 Correct 2 ms 1868 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 2 ms 1864 KB Output is correct
29 Correct 261 ms 6556 KB Output is correct
30 Correct 240 ms 7624 KB Output is correct
31 Correct 164 ms 11984 KB Output is correct
32 Correct 174 ms 10516 KB Output is correct
33 Correct 169 ms 10480 KB Output is correct
34 Correct 169 ms 9336 KB Output is correct
35 Correct 202 ms 9784 KB Output is correct
36 Correct 301 ms 10248 KB Output is correct
37 Correct 240 ms 10272 KB Output is correct
38 Correct 272 ms 10796 KB Output is correct
39 Correct 189 ms 9144 KB Output is correct
40 Correct 182 ms 9864 KB Output is correct
41 Correct 300 ms 10480 KB Output is correct
42 Correct 312 ms 10684 KB Output is correct
43 Correct 269 ms 10772 KB Output is correct
44 Correct 241 ms 11368 KB Output is correct
45 Correct 311 ms 12500 KB Output is correct
46 Correct 143 ms 10792 KB Output is correct
47 Correct 168 ms 10864 KB Output is correct
48 Correct 234 ms 10288 KB Output is correct
49 Correct 328 ms 10788 KB Output is correct
50 Correct 221 ms 10388 KB Output is correct
51 Correct 247 ms 10960 KB Output is correct
52 Correct 294 ms 11048 KB Output is correct
53 Correct 204 ms 9480 KB Output is correct
54 Correct 258 ms 10356 KB Output is correct
55 Correct 315 ms 11064 KB Output is correct
56 Correct 304 ms 11036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1868 KB Output is correct
6 Correct 2 ms 1868 KB Output is correct
7 Correct 2 ms 1908 KB Output is correct
8 Correct 3 ms 1868 KB Output is correct
9 Correct 2 ms 1868 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1864 KB Output is correct
13 Correct 2 ms 1864 KB Output is correct
14 Correct 2 ms 1848 KB Output is correct
15 Correct 2 ms 1868 KB Output is correct
16 Correct 2 ms 1860 KB Output is correct
17 Correct 2 ms 1868 KB Output is correct
18 Correct 2 ms 1864 KB Output is correct
19 Correct 2 ms 1868 KB Output is correct
20 Correct 1 ms 1868 KB Output is correct
21 Correct 2 ms 1868 KB Output is correct
22 Correct 2 ms 1868 KB Output is correct
23 Correct 2 ms 1868 KB Output is correct
24 Correct 1 ms 1868 KB Output is correct
25 Correct 2 ms 1864 KB Output is correct
26 Correct 2 ms 1868 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 2 ms 1864 KB Output is correct
29 Correct 2 ms 1876 KB Output is correct
30 Correct 3 ms 1996 KB Output is correct
31 Correct 4 ms 1996 KB Output is correct
32 Correct 4 ms 1996 KB Output is correct
33 Correct 3 ms 1868 KB Output is correct
34 Correct 3 ms 1996 KB Output is correct
35 Correct 3 ms 1996 KB Output is correct
36 Correct 4 ms 1996 KB Output is correct
37 Correct 4 ms 1996 KB Output is correct
38 Correct 5 ms 1996 KB Output is correct
39 Correct 3 ms 2004 KB Output is correct
40 Correct 3 ms 1952 KB Output is correct
41 Correct 3 ms 1996 KB Output is correct
42 Correct 4 ms 2000 KB Output is correct
43 Correct 3 ms 1996 KB Output is correct
44 Correct 3 ms 1996 KB Output is correct
45 Correct 3 ms 2008 KB Output is correct
46 Correct 4 ms 1996 KB Output is correct
47 Correct 4 ms 1996 KB Output is correct
48 Correct 3 ms 1996 KB Output is correct
49 Correct 3 ms 1996 KB Output is correct
50 Correct 4 ms 1996 KB Output is correct
51 Correct 4 ms 1996 KB Output is correct
52 Correct 3 ms 1952 KB Output is correct
53 Correct 3 ms 1996 KB Output is correct
54 Correct 4 ms 1996 KB Output is correct
55 Correct 185 ms 8236 KB Output is correct
56 Correct 185 ms 10208 KB Output is correct
57 Correct 111 ms 10172 KB Output is correct
58 Correct 104 ms 8372 KB Output is correct
59 Correct 169 ms 7964 KB Output is correct
60 Correct 285 ms 8528 KB Output is correct
61 Correct 213 ms 8060 KB Output is correct
62 Correct 206 ms 8464 KB Output is correct
63 Correct 128 ms 7252 KB Output is correct
64 Correct 205 ms 8432 KB Output is correct
65 Correct 311 ms 8460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1868 KB Output is correct
2 Correct 2 ms 1868 KB Output is correct
3 Correct 1 ms 1868 KB Output is correct
4 Correct 1 ms 1868 KB Output is correct
5 Correct 1 ms 1868 KB Output is correct
6 Correct 2 ms 1868 KB Output is correct
7 Correct 2 ms 1908 KB Output is correct
8 Correct 3 ms 1868 KB Output is correct
9 Correct 2 ms 1868 KB Output is correct
10 Correct 2 ms 1868 KB Output is correct
11 Correct 2 ms 1868 KB Output is correct
12 Correct 2 ms 1864 KB Output is correct
13 Correct 2 ms 1864 KB Output is correct
14 Correct 2 ms 1848 KB Output is correct
15 Correct 2 ms 1868 KB Output is correct
16 Correct 2 ms 1860 KB Output is correct
17 Correct 2 ms 1868 KB Output is correct
18 Correct 2 ms 1864 KB Output is correct
19 Correct 2 ms 1868 KB Output is correct
20 Correct 1 ms 1868 KB Output is correct
21 Correct 2 ms 1868 KB Output is correct
22 Correct 2 ms 1868 KB Output is correct
23 Correct 2 ms 1868 KB Output is correct
24 Correct 1 ms 1868 KB Output is correct
25 Correct 2 ms 1864 KB Output is correct
26 Correct 2 ms 1868 KB Output is correct
27 Correct 2 ms 1868 KB Output is correct
28 Correct 2 ms 1864 KB Output is correct
29 Correct 2 ms 1876 KB Output is correct
30 Correct 3 ms 1996 KB Output is correct
31 Correct 4 ms 1996 KB Output is correct
32 Correct 4 ms 1996 KB Output is correct
33 Correct 3 ms 1868 KB Output is correct
34 Correct 3 ms 1996 KB Output is correct
35 Correct 3 ms 1996 KB Output is correct
36 Correct 4 ms 1996 KB Output is correct
37 Correct 4 ms 1996 KB Output is correct
38 Correct 5 ms 1996 KB Output is correct
39 Correct 3 ms 2004 KB Output is correct
40 Correct 3 ms 1952 KB Output is correct
41 Correct 3 ms 1996 KB Output is correct
42 Correct 4 ms 2000 KB Output is correct
43 Correct 3 ms 1996 KB Output is correct
44 Correct 3 ms 1996 KB Output is correct
45 Correct 3 ms 2008 KB Output is correct
46 Correct 4 ms 1996 KB Output is correct
47 Correct 4 ms 1996 KB Output is correct
48 Correct 3 ms 1996 KB Output is correct
49 Correct 3 ms 1996 KB Output is correct
50 Correct 4 ms 1996 KB Output is correct
51 Correct 4 ms 1996 KB Output is correct
52 Correct 3 ms 1952 KB Output is correct
53 Correct 3 ms 1996 KB Output is correct
54 Correct 4 ms 1996 KB Output is correct
55 Correct 261 ms 6556 KB Output is correct
56 Correct 240 ms 7624 KB Output is correct
57 Correct 164 ms 11984 KB Output is correct
58 Correct 174 ms 10516 KB Output is correct
59 Correct 169 ms 10480 KB Output is correct
60 Correct 169 ms 9336 KB Output is correct
61 Correct 202 ms 9784 KB Output is correct
62 Correct 301 ms 10248 KB Output is correct
63 Correct 240 ms 10272 KB Output is correct
64 Correct 272 ms 10796 KB Output is correct
65 Correct 189 ms 9144 KB Output is correct
66 Correct 182 ms 9864 KB Output is correct
67 Correct 300 ms 10480 KB Output is correct
68 Correct 312 ms 10684 KB Output is correct
69 Correct 269 ms 10772 KB Output is correct
70 Correct 241 ms 11368 KB Output is correct
71 Correct 311 ms 12500 KB Output is correct
72 Correct 143 ms 10792 KB Output is correct
73 Correct 168 ms 10864 KB Output is correct
74 Correct 234 ms 10288 KB Output is correct
75 Correct 328 ms 10788 KB Output is correct
76 Correct 221 ms 10388 KB Output is correct
77 Correct 247 ms 10960 KB Output is correct
78 Correct 294 ms 11048 KB Output is correct
79 Correct 204 ms 9480 KB Output is correct
80 Correct 258 ms 10356 KB Output is correct
81 Correct 315 ms 11064 KB Output is correct
82 Correct 304 ms 11036 KB Output is correct
83 Correct 185 ms 8236 KB Output is correct
84 Correct 185 ms 10208 KB Output is correct
85 Correct 111 ms 10172 KB Output is correct
86 Correct 104 ms 8372 KB Output is correct
87 Correct 169 ms 7964 KB Output is correct
88 Correct 285 ms 8528 KB Output is correct
89 Correct 213 ms 8060 KB Output is correct
90 Correct 206 ms 8464 KB Output is correct
91 Correct 128 ms 7252 KB Output is correct
92 Correct 205 ms 8432 KB Output is correct
93 Correct 311 ms 8460 KB Output is correct
94 Correct 251 ms 11496 KB Output is correct
95 Correct 302 ms 13196 KB Output is correct
96 Correct 157 ms 12916 KB Output is correct
97 Correct 166 ms 11584 KB Output is correct
98 Correct 177 ms 11576 KB Output is correct
99 Correct 224 ms 10896 KB Output is correct
100 Correct 268 ms 11748 KB Output is correct
101 Correct 233 ms 11084 KB Output is correct
102 Correct 267 ms 11596 KB Output is correct
103 Correct 304 ms 11876 KB Output is correct
104 Correct 198 ms 10572 KB Output is correct
105 Correct 275 ms 11468 KB Output is correct
106 Correct 348 ms 11800 KB Output is correct
107 Correct 143 ms 13368 KB Output is correct
108 Correct 245 ms 11260 KB Output is correct
109 Correct 256 ms 11364 KB Output is correct
110 Correct 250 ms 11340 KB Output is correct
111 Correct 256 ms 11448 KB Output is correct
112 Correct 261 ms 11388 KB Output is correct
113 Correct 263 ms 11556 KB Output is correct
114 Correct 245 ms 11292 KB Output is correct
115 Correct 263 ms 11304 KB Output is correct
116 Correct 266 ms 11340 KB Output is correct