답안 #470593

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
470593 2021-09-04T12:55:11 Z cp_is_hard Joker (BOI20_joker) C++14
100 / 100
1439 ms 20524 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma loop-opt(on)

#define rep(i, a, b) for(int i = a; i <= b; i++)
#define rrep(i, a, b) for(int i = b; i >= a; i--)
#define all(x) x.begin(), x.end()
#define ceil(a, b)

using namespace std;

#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())

#ifdef wiwihorz
#define print(a...) kout("[" + string(#a) + "] = ", a)
void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
void kout() { cerr << endl; }
template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); }
#else 
#define print(...)
#define vprint(...)
#endif
namespace dsu {
	int n, cnt, ops;
	vector<int> sz, par;
	vector<pii> ss, sp;
	void init_(int _n) {
		n = _n, cnt = 0, ops = 0;
		sz.assign(n + 1, 0);
		par.assign(n + 1, 0);
		rep(i, 1, n) 
			sz[i] = 1, par[i] = i;
	}
	int find_par(int a) {
		while(a != par[a]) a = par[a];
		return a;
	}
	bool same(int a, int b) {
		return find_par(a) == find_par(b);
	}
	void unite(int a, int b) {
		ops ++;
		int aa = find_par(a);
		int bb = find_par(b);
		if(aa == bb) return;
		if(sz[aa] < sz[bb]) swap(aa, bb);
		cnt++;
		sp.push_back({bb, par[bb]});
		ss.push_back({aa, sz[aa]});
		par[bb] = aa, sz[aa] += sz[bb];
	}
	void undo() {
		if(!cnt) return;
		cnt--;
		pii p;
		p = ss.back(), ss.pop_back();
		sz[p.first] = p.second;
		p = sp.back(), sp.pop_back();
		par[p.first] = p.second;
	}
};
namespace solver {
	int n, m;
	vector<int> s;
	vector<pii> es;
	void init_(int _n, int _m) {
		n = _n, m = _m;
		s.assign(2 * m, 0);
		es.assign(2 * m, {0, 0});
		dsu::init_(2 * n);
	}
	void solve(int L, int R, int l, int r) {
		int mid = (L + R) / 2, id = max(l, mid);
		if(L > R) return;
		int p1 = dsu::cnt;
		rep(i, mid, min(R, id - 1)) {
			dsu::unite(es[i].first, es[i].second + n);
			dsu::unite(es[i].first + n, es[i].second);
		} 
		int p2 = dsu::cnt;
		while(id < r) {
			int x = es[id].first, y = es[id].second;
			if(dsu::same(x, y)) break;
			dsu::unite(x, y + n);
			dsu::unite(x + n, y);
			id ++;
		}
		s[mid] = id;
		while(dsu::cnt != p2) dsu::undo();
		solve(L, mid - 1, l, id);
		while(dsu::cnt != p1) dsu::undo();
		rep(i, max(R + 1, l), id - 1) {
			dsu::unite(es[i].first, es[i].second + n);
			dsu::unite(es[i].first + n, es[i].second);
		} 
		solve(mid + 1, R, id, r);
		while(dsu::cnt != p1) dsu::undo();
		return;
	}
	bool query(int L, int R) {
		L --, R --;
		int l = R + 1, r = m + L - 1;
		return s[l] <= r; 
	}
};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n, m, q;
	cin >> n >> m >> q;
	init_(n, m);
	rep(i, 0, m - 1) {
		cin >> es[i].first;
		cin >> es[i].second;
	}
	rep(i, m, 2 * m - 1) es[i] = es[i - m];
	solve(0, 2 * m - 1, 0, 2 * m);
	rep(i, 1, q) {
		int L, R;
		cin >> L >> R;
		cout << (query(L, R) ? "YES" : "NO") << "\n"; 
	}
	
	return 0;
}

Compilation message

Joker.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
Joker.cpp:18:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
Joker.cpp:18:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   18 | void vprint(auto L, auto R) { while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 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 204 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 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 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 204 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 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 3 ms 332 KB Output is correct
30 Correct 6 ms 460 KB Output is correct
31 Correct 7 ms 332 KB Output is correct
32 Correct 6 ms 332 KB Output is correct
33 Correct 5 ms 332 KB Output is correct
34 Correct 6 ms 468 KB Output is correct
35 Correct 7 ms 460 KB Output is correct
36 Correct 6 ms 332 KB Output is correct
37 Correct 9 ms 484 KB Output is correct
38 Correct 6 ms 460 KB Output is correct
39 Correct 6 ms 460 KB Output is correct
40 Correct 6 ms 332 KB Output is correct
41 Correct 5 ms 332 KB Output is correct
42 Correct 6 ms 332 KB Output is correct
43 Correct 6 ms 420 KB Output is correct
44 Correct 6 ms 332 KB Output is correct
45 Correct 6 ms 332 KB Output is correct
46 Correct 7 ms 460 KB Output is correct
47 Correct 5 ms 332 KB Output is correct
48 Correct 5 ms 332 KB Output is correct
49 Correct 6 ms 460 KB Output is correct
50 Correct 7 ms 460 KB Output is correct
51 Correct 6 ms 332 KB Output is correct
52 Correct 6 ms 332 KB Output is correct
53 Correct 7 ms 332 KB Output is correct
54 Correct 7 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 996 ms 10524 KB Output is correct
4 Correct 1137 ms 15180 KB Output is correct
5 Correct 1018 ms 14364 KB Output is correct
6 Correct 915 ms 10524 KB Output is correct
7 Correct 913 ms 10456 KB Output is correct
8 Correct 1144 ms 8752 KB Output is correct
9 Correct 1378 ms 10268 KB Output is correct
10 Correct 1398 ms 12348 KB Output is correct
11 Correct 995 ms 13972 KB Output is correct
12 Correct 1029 ms 16164 KB Output is correct
13 Correct 874 ms 10680 KB Output is correct
14 Correct 1129 ms 12584 KB Output is correct
15 Correct 1219 ms 15056 KB Output is correct
16 Correct 1322 ms 16288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 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 204 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 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 996 ms 10524 KB Output is correct
30 Correct 1137 ms 15180 KB Output is correct
31 Correct 1018 ms 14364 KB Output is correct
32 Correct 915 ms 10524 KB Output is correct
33 Correct 913 ms 10456 KB Output is correct
34 Correct 1144 ms 8752 KB Output is correct
35 Correct 1378 ms 10268 KB Output is correct
36 Correct 1398 ms 12348 KB Output is correct
37 Correct 995 ms 13972 KB Output is correct
38 Correct 1029 ms 16164 KB Output is correct
39 Correct 874 ms 10680 KB Output is correct
40 Correct 1129 ms 12584 KB Output is correct
41 Correct 1219 ms 15056 KB Output is correct
42 Correct 1322 ms 16288 KB Output is correct
43 Correct 988 ms 14788 KB Output is correct
44 Correct 1070 ms 19244 KB Output is correct
45 Correct 1439 ms 19640 KB Output is correct
46 Correct 1026 ms 14880 KB Output is correct
47 Correct 950 ms 14912 KB Output is correct
48 Correct 1352 ms 13980 KB Output is correct
49 Correct 1407 ms 16508 KB Output is correct
50 Correct 1012 ms 13724 KB Output is correct
51 Correct 1045 ms 15528 KB Output is correct
52 Correct 1104 ms 16980 KB Output is correct
53 Correct 853 ms 11064 KB Output is correct
54 Correct 1249 ms 13788 KB Output is correct
55 Correct 1243 ms 15492 KB Output is correct
56 Correct 1416 ms 16768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 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 204 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 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 3 ms 332 KB Output is correct
30 Correct 6 ms 460 KB Output is correct
31 Correct 7 ms 332 KB Output is correct
32 Correct 6 ms 332 KB Output is correct
33 Correct 5 ms 332 KB Output is correct
34 Correct 6 ms 468 KB Output is correct
35 Correct 7 ms 460 KB Output is correct
36 Correct 6 ms 332 KB Output is correct
37 Correct 9 ms 484 KB Output is correct
38 Correct 6 ms 460 KB Output is correct
39 Correct 6 ms 460 KB Output is correct
40 Correct 6 ms 332 KB Output is correct
41 Correct 5 ms 332 KB Output is correct
42 Correct 6 ms 332 KB Output is correct
43 Correct 6 ms 420 KB Output is correct
44 Correct 6 ms 332 KB Output is correct
45 Correct 6 ms 332 KB Output is correct
46 Correct 7 ms 460 KB Output is correct
47 Correct 5 ms 332 KB Output is correct
48 Correct 5 ms 332 KB Output is correct
49 Correct 6 ms 460 KB Output is correct
50 Correct 7 ms 460 KB Output is correct
51 Correct 6 ms 332 KB Output is correct
52 Correct 6 ms 332 KB Output is correct
53 Correct 7 ms 332 KB Output is correct
54 Correct 7 ms 460 KB Output is correct
55 Correct 930 ms 9928 KB Output is correct
56 Correct 1008 ms 14748 KB Output is correct
57 Correct 1177 ms 14124 KB Output is correct
58 Correct 861 ms 12264 KB Output is correct
59 Correct 1184 ms 12208 KB Output is correct
60 Correct 1203 ms 13336 KB Output is correct
61 Correct 943 ms 12208 KB Output is correct
62 Correct 1061 ms 13864 KB Output is correct
63 Correct 923 ms 9656 KB Output is correct
64 Correct 1158 ms 12596 KB Output is correct
65 Correct 1212 ms 13708 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 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 204 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 204 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 3 ms 332 KB Output is correct
30 Correct 6 ms 460 KB Output is correct
31 Correct 7 ms 332 KB Output is correct
32 Correct 6 ms 332 KB Output is correct
33 Correct 5 ms 332 KB Output is correct
34 Correct 6 ms 468 KB Output is correct
35 Correct 7 ms 460 KB Output is correct
36 Correct 6 ms 332 KB Output is correct
37 Correct 9 ms 484 KB Output is correct
38 Correct 6 ms 460 KB Output is correct
39 Correct 6 ms 460 KB Output is correct
40 Correct 6 ms 332 KB Output is correct
41 Correct 5 ms 332 KB Output is correct
42 Correct 6 ms 332 KB Output is correct
43 Correct 6 ms 420 KB Output is correct
44 Correct 6 ms 332 KB Output is correct
45 Correct 6 ms 332 KB Output is correct
46 Correct 7 ms 460 KB Output is correct
47 Correct 5 ms 332 KB Output is correct
48 Correct 5 ms 332 KB Output is correct
49 Correct 6 ms 460 KB Output is correct
50 Correct 7 ms 460 KB Output is correct
51 Correct 6 ms 332 KB Output is correct
52 Correct 6 ms 332 KB Output is correct
53 Correct 7 ms 332 KB Output is correct
54 Correct 7 ms 460 KB Output is correct
55 Correct 996 ms 10524 KB Output is correct
56 Correct 1137 ms 15180 KB Output is correct
57 Correct 1018 ms 14364 KB Output is correct
58 Correct 915 ms 10524 KB Output is correct
59 Correct 913 ms 10456 KB Output is correct
60 Correct 1144 ms 8752 KB Output is correct
61 Correct 1378 ms 10268 KB Output is correct
62 Correct 1398 ms 12348 KB Output is correct
63 Correct 995 ms 13972 KB Output is correct
64 Correct 1029 ms 16164 KB Output is correct
65 Correct 874 ms 10680 KB Output is correct
66 Correct 1129 ms 12584 KB Output is correct
67 Correct 1219 ms 15056 KB Output is correct
68 Correct 1322 ms 16288 KB Output is correct
69 Correct 988 ms 14788 KB Output is correct
70 Correct 1070 ms 19244 KB Output is correct
71 Correct 1439 ms 19640 KB Output is correct
72 Correct 1026 ms 14880 KB Output is correct
73 Correct 950 ms 14912 KB Output is correct
74 Correct 1352 ms 13980 KB Output is correct
75 Correct 1407 ms 16508 KB Output is correct
76 Correct 1012 ms 13724 KB Output is correct
77 Correct 1045 ms 15528 KB Output is correct
78 Correct 1104 ms 16980 KB Output is correct
79 Correct 853 ms 11064 KB Output is correct
80 Correct 1249 ms 13788 KB Output is correct
81 Correct 1243 ms 15492 KB Output is correct
82 Correct 1416 ms 16768 KB Output is correct
83 Correct 930 ms 9928 KB Output is correct
84 Correct 1008 ms 14748 KB Output is correct
85 Correct 1177 ms 14124 KB Output is correct
86 Correct 861 ms 12264 KB Output is correct
87 Correct 1184 ms 12208 KB Output is correct
88 Correct 1203 ms 13336 KB Output is correct
89 Correct 943 ms 12208 KB Output is correct
90 Correct 1061 ms 13864 KB Output is correct
91 Correct 923 ms 9656 KB Output is correct
92 Correct 1158 ms 12596 KB Output is correct
93 Correct 1212 ms 13708 KB Output is correct
94 Correct 1073 ms 15552 KB Output is correct
95 Correct 1311 ms 20256 KB Output is correct
96 Correct 1315 ms 19452 KB Output is correct
97 Correct 1034 ms 15524 KB Output is correct
98 Correct 982 ms 15552 KB Output is correct
99 Correct 1010 ms 13680 KB Output is correct
100 Correct 1256 ms 17460 KB Output is correct
101 Correct 879 ms 14456 KB Output is correct
102 Correct 1098 ms 16296 KB Output is correct
103 Correct 1275 ms 17848 KB Output is correct
104 Correct 1004 ms 12600 KB Output is correct
105 Correct 1299 ms 15604 KB Output is correct
106 Correct 1348 ms 17040 KB Output is correct
107 Correct 1178 ms 20524 KB Output is correct
108 Correct 1012 ms 15392 KB Output is correct
109 Correct 992 ms 15396 KB Output is correct
110 Correct 990 ms 15408 KB Output is correct
111 Correct 992 ms 15296 KB Output is correct
112 Correct 1002 ms 15400 KB Output is correct
113 Correct 1012 ms 15292 KB Output is correct
114 Correct 1027 ms 15388 KB Output is correct
115 Correct 1016 ms 15300 KB Output is correct
116 Correct 1012 ms 15436 KB Output is correct