답안 #480085

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
480085 2021-10-14T14:30:20 Z AdamGS Joker (BOI20_joker) C++14
100 / 100
452 ms 15136 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=2e5+7;
struct operacje {
	int a, ilea, b, ileb, zmianacyklu;
};
pair<int,int>F[LIM], kraw[LIM];
int ile[LIM], T[LIM], cykl, n, m, q;
stack<operacje>S;
pair<int,int>fnd(int x) {
	if(F[x].st==x) return F[x];
	pair<int,int>ans=fnd(F[x].st);
	ans.nd^=F[x].nd;
	return ans;
}
void uni(int a, int b) {
	pair<int,int>x=fnd(a), y=fnd(b);
	operacje p={x.st, ile[x.st], y.st, ile[y.st], 0};
	if(x.st==y.st) {
		if(x.nd==y.nd) {
			++cykl;
			p.zmianacyklu=1;
		}
		S.push(p);
		return;
	}
	if(ile[x.st]>ile[y.st]) swap(x, y);
	ile[y.st]+=ile[x.st];
	F[x.st]={y.st, x.nd==y.nd};
	S.push(p);
}
void usun(int x) {
	while(x--) {
		operacje p=S.top(); S.pop();
		F[p.a]={p.a, 0};
		ile[p.a]=p.ilea;
		F[p.b]={p.b, 0};
		ile[p.b]=p.ileb;
		cykl-=p.zmianacyklu;
	}
}
void dodaj(int l, int r) {
	while(l<=r) {
		uni(kraw[l].st, kraw[l].nd);
		++l;
	}
}
void dc(int l, int r, int x) {
	int mid=(l+r)/2, p=x+1;
	dodaj(l, mid-1);
	while(!cykl) {
		--p;
		dodaj(p, p);
	}
	usun(x-p+1);
	if(l==r) {
		T[l]=p;
		return;
	}
	usun(mid-l);
	dodaj(p+1, x);
	dc(l, mid, min(p, x));
	usun(max(0, x-p));
	dodaj(l, mid);
	dc(mid+1, r, x);
	usun(mid-l+1);
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> m >> q;
	rep(i, n) {
		F[i]={i, 0};
		ile[i]=1;
	}
	rep(i, m) {
		cin >> kraw[i].st >> kraw[i].nd;
		--kraw[i].st;
		--kraw[i].nd;
	}
	dodaj(0, m-1);
	if(!cykl) {
		while(q--) cout << "NO\n";
		return 0;
	}
	usun(m);
	dc(0, m-1, m-1);
	while(q--) {
		int a, b;
		cin >> a >> b; --a; --b;
		cout << (b<T[a]?"YES":"NO") << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 3 ms 456 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 3 ms 460 KB Output is correct
35 Correct 3 ms 460 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 3 ms 460 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 3 ms 460 KB Output is correct
41 Correct 2 ms 460 KB Output is correct
42 Correct 2 ms 456 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 3 ms 460 KB Output is correct
45 Correct 3 ms 460 KB Output is correct
46 Correct 3 ms 460 KB Output is correct
47 Correct 3 ms 460 KB Output is correct
48 Correct 3 ms 392 KB Output is correct
49 Correct 3 ms 460 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 3 ms 460 KB Output is correct
52 Correct 3 ms 460 KB Output is correct
53 Correct 3 ms 460 KB Output is correct
54 Correct 3 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 260 ms 12532 KB Output is correct
4 Correct 56 ms 11460 KB Output is correct
5 Correct 237 ms 13720 KB Output is correct
6 Correct 288 ms 8572 KB Output is correct
7 Correct 289 ms 8476 KB Output is correct
8 Correct 327 ms 8216 KB Output is correct
9 Correct 353 ms 8684 KB Output is correct
10 Correct 397 ms 9848 KB Output is correct
11 Correct 291 ms 8532 KB Output is correct
12 Correct 331 ms 9416 KB Output is correct
13 Correct 302 ms 7576 KB Output is correct
14 Correct 341 ms 8084 KB Output is correct
15 Correct 378 ms 9008 KB Output is correct
16 Correct 400 ms 9624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 260 ms 12532 KB Output is correct
30 Correct 56 ms 11460 KB Output is correct
31 Correct 237 ms 13720 KB Output is correct
32 Correct 288 ms 8572 KB Output is correct
33 Correct 289 ms 8476 KB Output is correct
34 Correct 327 ms 8216 KB Output is correct
35 Correct 353 ms 8684 KB Output is correct
36 Correct 397 ms 9848 KB Output is correct
37 Correct 291 ms 8532 KB Output is correct
38 Correct 331 ms 9416 KB Output is correct
39 Correct 302 ms 7576 KB Output is correct
40 Correct 341 ms 8084 KB Output is correct
41 Correct 378 ms 9008 KB Output is correct
42 Correct 400 ms 9624 KB Output is correct
43 Correct 258 ms 12824 KB Output is correct
44 Correct 56 ms 11588 KB Output is correct
45 Correct 309 ms 14064 KB Output is correct
46 Correct 288 ms 12896 KB Output is correct
47 Correct 287 ms 12876 KB Output is correct
48 Correct 346 ms 12480 KB Output is correct
49 Correct 390 ms 13868 KB Output is correct
50 Correct 297 ms 12604 KB Output is correct
51 Correct 309 ms 13520 KB Output is correct
52 Correct 350 ms 14264 KB Output is correct
53 Correct 298 ms 11756 KB Output is correct
54 Correct 348 ms 12532 KB Output is correct
55 Correct 376 ms 13396 KB Output is correct
56 Correct 419 ms 14180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 3 ms 456 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 3 ms 460 KB Output is correct
35 Correct 3 ms 460 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 3 ms 460 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 3 ms 460 KB Output is correct
41 Correct 2 ms 460 KB Output is correct
42 Correct 2 ms 456 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 3 ms 460 KB Output is correct
45 Correct 3 ms 460 KB Output is correct
46 Correct 3 ms 460 KB Output is correct
47 Correct 3 ms 460 KB Output is correct
48 Correct 3 ms 392 KB Output is correct
49 Correct 3 ms 460 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 3 ms 460 KB Output is correct
52 Correct 3 ms 460 KB Output is correct
53 Correct 3 ms 460 KB Output is correct
54 Correct 3 ms 460 KB Output is correct
55 Correct 207 ms 10136 KB Output is correct
56 Correct 48 ms 10748 KB Output is correct
57 Correct 194 ms 11324 KB Output is correct
58 Correct 243 ms 10180 KB Output is correct
59 Correct 323 ms 10348 KB Output is correct
60 Correct 359 ms 11028 KB Output is correct
61 Correct 269 ms 10216 KB Output is correct
62 Correct 277 ms 11296 KB Output is correct
63 Correct 267 ms 9452 KB Output is correct
64 Correct 330 ms 10460 KB Output is correct
65 Correct 360 ms 11300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 324 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 312 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 3 ms 460 KB Output is correct
31 Correct 3 ms 456 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 2 ms 460 KB Output is correct
34 Correct 3 ms 460 KB Output is correct
35 Correct 3 ms 460 KB Output is correct
36 Correct 2 ms 460 KB Output is correct
37 Correct 3 ms 460 KB Output is correct
38 Correct 1 ms 460 KB Output is correct
39 Correct 2 ms 460 KB Output is correct
40 Correct 3 ms 460 KB Output is correct
41 Correct 2 ms 460 KB Output is correct
42 Correct 2 ms 456 KB Output is correct
43 Correct 2 ms 460 KB Output is correct
44 Correct 3 ms 460 KB Output is correct
45 Correct 3 ms 460 KB Output is correct
46 Correct 3 ms 460 KB Output is correct
47 Correct 3 ms 460 KB Output is correct
48 Correct 3 ms 392 KB Output is correct
49 Correct 3 ms 460 KB Output is correct
50 Correct 3 ms 512 KB Output is correct
51 Correct 3 ms 460 KB Output is correct
52 Correct 3 ms 460 KB Output is correct
53 Correct 3 ms 460 KB Output is correct
54 Correct 3 ms 460 KB Output is correct
55 Correct 260 ms 12532 KB Output is correct
56 Correct 56 ms 11460 KB Output is correct
57 Correct 237 ms 13720 KB Output is correct
58 Correct 288 ms 8572 KB Output is correct
59 Correct 289 ms 8476 KB Output is correct
60 Correct 327 ms 8216 KB Output is correct
61 Correct 353 ms 8684 KB Output is correct
62 Correct 397 ms 9848 KB Output is correct
63 Correct 291 ms 8532 KB Output is correct
64 Correct 331 ms 9416 KB Output is correct
65 Correct 302 ms 7576 KB Output is correct
66 Correct 341 ms 8084 KB Output is correct
67 Correct 378 ms 9008 KB Output is correct
68 Correct 400 ms 9624 KB Output is correct
69 Correct 258 ms 12824 KB Output is correct
70 Correct 56 ms 11588 KB Output is correct
71 Correct 309 ms 14064 KB Output is correct
72 Correct 288 ms 12896 KB Output is correct
73 Correct 287 ms 12876 KB Output is correct
74 Correct 346 ms 12480 KB Output is correct
75 Correct 390 ms 13868 KB Output is correct
76 Correct 297 ms 12604 KB Output is correct
77 Correct 309 ms 13520 KB Output is correct
78 Correct 350 ms 14264 KB Output is correct
79 Correct 298 ms 11756 KB Output is correct
80 Correct 348 ms 12532 KB Output is correct
81 Correct 376 ms 13396 KB Output is correct
82 Correct 419 ms 14180 KB Output is correct
83 Correct 207 ms 10136 KB Output is correct
84 Correct 48 ms 10748 KB Output is correct
85 Correct 194 ms 11324 KB Output is correct
86 Correct 243 ms 10180 KB Output is correct
87 Correct 323 ms 10348 KB Output is correct
88 Correct 359 ms 11028 KB Output is correct
89 Correct 269 ms 10216 KB Output is correct
90 Correct 277 ms 11296 KB Output is correct
91 Correct 267 ms 9452 KB Output is correct
92 Correct 330 ms 10460 KB Output is correct
93 Correct 360 ms 11300 KB Output is correct
94 Correct 269 ms 13452 KB Output is correct
95 Correct 303 ms 14736 KB Output is correct
96 Correct 244 ms 14648 KB Output is correct
97 Correct 284 ms 13576 KB Output is correct
98 Correct 287 ms 13632 KB Output is correct
99 Correct 346 ms 13144 KB Output is correct
100 Correct 363 ms 14860 KB Output is correct
101 Correct 291 ms 13288 KB Output is correct
102 Correct 343 ms 14140 KB Output is correct
103 Correct 375 ms 15136 KB Output is correct
104 Correct 324 ms 12692 KB Output is correct
105 Correct 375 ms 14036 KB Output is correct
106 Correct 452 ms 14604 KB Output is correct
107 Correct 208 ms 15092 KB Output is correct
108 Correct 257 ms 13252 KB Output is correct
109 Correct 255 ms 13452 KB Output is correct
110 Correct 267 ms 13328 KB Output is correct
111 Correct 267 ms 13288 KB Output is correct
112 Correct 264 ms 13464 KB Output is correct
113 Correct 288 ms 13428 KB Output is correct
114 Correct 269 ms 13452 KB Output is correct
115 Correct 276 ms 13308 KB Output is correct
116 Correct 277 ms 13328 KB Output is correct