Submission #362946

# Submission time Handle Problem Language Result Execution time Memory
362946 2021-02-04T19:25:54 Z songc Joker (BOI20_joker) C++14
100 / 100
308 ms 16584 KB
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define Mup(a,x) a=max(a, x)
#define mup(a,x) a=min(a, x)
#define all(v) v.begin(),v.end()
#define lb lower_bound
#define INF (1ll<<60)
#define MOD 1'000'000'007 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;

int N, M, Q;
int U[202020], V[202020];
int P[404040], R[202020];
vector<pii> rb;

int rt(int u){
	if (P[u] < 0) return u;
	return rt(P[u]);
}

void uni(int u, int v){
	u = rt(u), v = rt(v);
	if (u == v) return;
	if (P[u] > P[v]) swap(u, v);
	rb.pb(pii(u, P[u]));
	rb.pb(pii(v, P[v]));
	P[u] += P[v], P[v] = u;
}

void undo(){
	pii t = rb.back();
	rb.pop_back();
	P[t.fi] = t.se;
}

void dnc(int s, int e, int r){
	if (s > e) return;
	int m=s+e>>1, rs=(int)rb.size();
	for (int i=max(s,1); i<=m; i++){
		uni(U[i], V[i]+N);
		uni(U[i]+N, V[i]);
		if (rt(U[i]) == rt(U[i]+N)){
			for (int j=m; j<=e; j++) R[j] = r;
			while (rb.size()>rs) undo();
			dnc(s, m-1, r);
			return;
		}
	}
	int rr=(int)rb.size();
	for (int i=r-1; i>s; i--){
		uni(U[i], V[i]+N);
		uni(U[i]+N, V[i]);
		if (rt(U[i]) == rt(U[i]+N)){R[m] = i; break;}
	}
	while (rb.size()>rr) undo();
	dnc(m+1, e, r);
	while (rb.size()>rs) undo();
	for (int i=r-1; i>=max(R[m],s+1); i--){
		uni(U[i], V[i]+N);
		uni(U[i]+N, V[i]);
		if (rt(U[i]) == rt(U[i]+N)){
			for (int j=s; j<m; j++) R[j] = R[m];
			return;
		}
	}
	dnc(s, m-1, R[m]);
}

int main(){
	scanf("%d %d %d", &N, &M, &Q);
	for (int i=1; i<=M; i++) scanf("%d %d", &U[i], &V[i]);
	for (int i=1; i<=2*N; i++) P[i] = -1;
	dnc(0, M-1, M+1);
	while (Q--){
		int l, r;
		scanf("%d %d", &l, &r);
		puts(r<R[l-1]?"YES":"NO");
	}
	return 0;
}

Compilation message

Joker.cpp: In function 'void dnc(int, int, int)':
Joker.cpp:42:9: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |  int m=s+e>>1, rs=(int)rb.size();
      |        ~^~
Joker.cpp:48:20: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   48 |    while (rb.size()>rs) undo();
      |           ~~~~~~~~~^~~
Joker.cpp:59:18: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   59 |  while (rb.size()>rr) undo();
      |         ~~~~~~~~~^~~
Joker.cpp:61:18: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   61 |  while (rb.size()>rs) undo();
      |         ~~~~~~~~~^~~
Joker.cpp: In function 'int main()':
Joker.cpp:74:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   74 |  scanf("%d %d %d", &N, &M, &Q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:75:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   75 |  for (int i=1; i<=M; i++) scanf("%d %d", &U[i], &V[i]);
      |                           ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   80 |   scanf("%d %d", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 3 ms 492 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 3 ms 620 KB Output is correct
38 Correct 3 ms 492 KB Output is correct
39 Correct 2 ms 620 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 2 ms 492 KB Output is correct
42 Correct 2 ms 492 KB Output is correct
43 Correct 2 ms 492 KB Output is correct
44 Correct 2 ms 492 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 3 ms 492 KB Output is correct
47 Correct 2 ms 492 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Correct 3 ms 492 KB Output is correct
50 Correct 3 ms 492 KB Output is correct
51 Correct 2 ms 492 KB Output is correct
52 Correct 2 ms 492 KB Output is correct
53 Correct 3 ms 492 KB Output is correct
54 Correct 3 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 263 ms 7764 KB Output is correct
4 Correct 220 ms 12248 KB Output is correct
5 Correct 155 ms 12512 KB Output is correct
6 Correct 160 ms 11476 KB Output is correct
7 Correct 167 ms 11348 KB Output is correct
8 Correct 171 ms 9180 KB Output is correct
9 Correct 209 ms 10484 KB Output is correct
10 Correct 283 ms 12116 KB Output is correct
11 Correct 224 ms 10964 KB Output is correct
12 Correct 243 ms 12372 KB Output is correct
13 Correct 163 ms 8032 KB Output is correct
14 Correct 171 ms 9696 KB Output is correct
15 Correct 277 ms 11604 KB Output is correct
16 Correct 280 ms 12420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 263 ms 7764 KB Output is correct
30 Correct 220 ms 12248 KB Output is correct
31 Correct 155 ms 12512 KB Output is correct
32 Correct 160 ms 11476 KB Output is correct
33 Correct 167 ms 11348 KB Output is correct
34 Correct 171 ms 9180 KB Output is correct
35 Correct 209 ms 10484 KB Output is correct
36 Correct 283 ms 12116 KB Output is correct
37 Correct 224 ms 10964 KB Output is correct
38 Correct 243 ms 12372 KB Output is correct
39 Correct 163 ms 8032 KB Output is correct
40 Correct 171 ms 9696 KB Output is correct
41 Correct 277 ms 11604 KB Output is correct
42 Correct 280 ms 12420 KB Output is correct
43 Correct 267 ms 11732 KB Output is correct
44 Correct 232 ms 14664 KB Output is correct
45 Correct 308 ms 15756 KB Output is correct
46 Correct 150 ms 11732 KB Output is correct
47 Correct 163 ms 11680 KB Output is correct
48 Correct 230 ms 10836 KB Output is correct
49 Correct 293 ms 12500 KB Output is correct
50 Correct 226 ms 10836 KB Output is correct
51 Correct 239 ms 12116 KB Output is correct
52 Correct 261 ms 12884 KB Output is correct
53 Correct 173 ms 8416 KB Output is correct
54 Correct 234 ms 10708 KB Output is correct
55 Correct 266 ms 11988 KB Output is correct
56 Correct 291 ms 12756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 3 ms 492 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 3 ms 620 KB Output is correct
38 Correct 3 ms 492 KB Output is correct
39 Correct 2 ms 620 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 2 ms 492 KB Output is correct
42 Correct 2 ms 492 KB Output is correct
43 Correct 2 ms 492 KB Output is correct
44 Correct 2 ms 492 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 3 ms 492 KB Output is correct
47 Correct 2 ms 492 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Correct 3 ms 492 KB Output is correct
50 Correct 3 ms 492 KB Output is correct
51 Correct 2 ms 492 KB Output is correct
52 Correct 2 ms 492 KB Output is correct
53 Correct 3 ms 492 KB Output is correct
54 Correct 3 ms 492 KB Output is correct
55 Correct 214 ms 9308 KB Output is correct
56 Correct 172 ms 14424 KB Output is correct
57 Correct 99 ms 14168 KB Output is correct
58 Correct 117 ms 9308 KB Output is correct
59 Correct 188 ms 9308 KB Output is correct
60 Correct 252 ms 9948 KB Output is correct
61 Correct 199 ms 9308 KB Output is correct
62 Correct 191 ms 10076 KB Output is correct
63 Correct 115 ms 6624 KB Output is correct
64 Correct 197 ms 9436 KB Output is correct
65 Correct 251 ms 10076 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 364 KB Output is correct
11 Correct 1 ms 364 KB Output is correct
12 Correct 1 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 364 KB Output is correct
21 Correct 1 ms 364 KB Output is correct
22 Correct 1 ms 364 KB Output is correct
23 Correct 1 ms 364 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 1 ms 364 KB Output is correct
26 Correct 1 ms 364 KB Output is correct
27 Correct 1 ms 364 KB Output is correct
28 Correct 1 ms 364 KB Output is correct
29 Correct 2 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
31 Correct 2 ms 492 KB Output is correct
32 Correct 2 ms 492 KB Output is correct
33 Correct 2 ms 492 KB Output is correct
34 Correct 2 ms 492 KB Output is correct
35 Correct 3 ms 492 KB Output is correct
36 Correct 2 ms 492 KB Output is correct
37 Correct 3 ms 620 KB Output is correct
38 Correct 3 ms 492 KB Output is correct
39 Correct 2 ms 620 KB Output is correct
40 Correct 2 ms 492 KB Output is correct
41 Correct 2 ms 492 KB Output is correct
42 Correct 2 ms 492 KB Output is correct
43 Correct 2 ms 492 KB Output is correct
44 Correct 2 ms 492 KB Output is correct
45 Correct 2 ms 512 KB Output is correct
46 Correct 3 ms 492 KB Output is correct
47 Correct 2 ms 492 KB Output is correct
48 Correct 2 ms 492 KB Output is correct
49 Correct 3 ms 492 KB Output is correct
50 Correct 3 ms 492 KB Output is correct
51 Correct 2 ms 492 KB Output is correct
52 Correct 2 ms 492 KB Output is correct
53 Correct 3 ms 492 KB Output is correct
54 Correct 3 ms 492 KB Output is correct
55 Correct 263 ms 7764 KB Output is correct
56 Correct 220 ms 12248 KB Output is correct
57 Correct 155 ms 12512 KB Output is correct
58 Correct 160 ms 11476 KB Output is correct
59 Correct 167 ms 11348 KB Output is correct
60 Correct 171 ms 9180 KB Output is correct
61 Correct 209 ms 10484 KB Output is correct
62 Correct 283 ms 12116 KB Output is correct
63 Correct 224 ms 10964 KB Output is correct
64 Correct 243 ms 12372 KB Output is correct
65 Correct 163 ms 8032 KB Output is correct
66 Correct 171 ms 9696 KB Output is correct
67 Correct 277 ms 11604 KB Output is correct
68 Correct 280 ms 12420 KB Output is correct
69 Correct 267 ms 11732 KB Output is correct
70 Correct 232 ms 14664 KB Output is correct
71 Correct 308 ms 15756 KB Output is correct
72 Correct 150 ms 11732 KB Output is correct
73 Correct 163 ms 11680 KB Output is correct
74 Correct 230 ms 10836 KB Output is correct
75 Correct 293 ms 12500 KB Output is correct
76 Correct 226 ms 10836 KB Output is correct
77 Correct 239 ms 12116 KB Output is correct
78 Correct 261 ms 12884 KB Output is correct
79 Correct 173 ms 8416 KB Output is correct
80 Correct 234 ms 10708 KB Output is correct
81 Correct 266 ms 11988 KB Output is correct
82 Correct 291 ms 12756 KB Output is correct
83 Correct 214 ms 9308 KB Output is correct
84 Correct 172 ms 14424 KB Output is correct
85 Correct 99 ms 14168 KB Output is correct
86 Correct 117 ms 9308 KB Output is correct
87 Correct 188 ms 9308 KB Output is correct
88 Correct 252 ms 9948 KB Output is correct
89 Correct 199 ms 9308 KB Output is correct
90 Correct 191 ms 10076 KB Output is correct
91 Correct 115 ms 6624 KB Output is correct
92 Correct 197 ms 9436 KB Output is correct
93 Correct 251 ms 10076 KB Output is correct
94 Correct 271 ms 12500 KB Output is correct
95 Correct 304 ms 16584 KB Output is correct
96 Correct 161 ms 15688 KB Output is correct
97 Correct 160 ms 12372 KB Output is correct
98 Correct 186 ms 12500 KB Output is correct
99 Correct 197 ms 10716 KB Output is correct
100 Correct 261 ms 13524 KB Output is correct
101 Correct 227 ms 11476 KB Output is correct
102 Correct 262 ms 12756 KB Output is correct
103 Correct 292 ms 14056 KB Output is correct
104 Correct 187 ms 9948 KB Output is correct
105 Correct 257 ms 12372 KB Output is correct
106 Correct 304 ms 13292 KB Output is correct
107 Correct 168 ms 16584 KB Output is correct
108 Correct 269 ms 12208 KB Output is correct
109 Correct 269 ms 12116 KB Output is correct
110 Correct 265 ms 12116 KB Output is correct
111 Correct 267 ms 12244 KB Output is correct
112 Correct 267 ms 12116 KB Output is correct
113 Correct 268 ms 12116 KB Output is correct
114 Correct 268 ms 12288 KB Output is correct
115 Correct 268 ms 12244 KB Output is correct
116 Correct 269 ms 12116 KB Output is correct