Submission #380043

# Submission time Handle Problem Language Result Execution time Memory
380043 2021-03-20T07:34:12 Z Return_0 Joker (BOI20_joker) C++17
100 / 100
309 ms 12900 KB
#pragma GCC optimize("Ofast,unroll-loops")
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma,tune=native")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

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

#ifdef SINA
#define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void __f(const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << std::endl; }
template <typename Arg1, typename... Args> void __f (const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...); }
#define dbg2(x, j, n) cout<< #x << " : "; output((j), (n), x, 1); cout.flush();
#else
#define dbg(...) 0
#define dbg2(x, j, n) 0
#endif
#define SZ(x) ((ll)((x).size()))
#define File(s, t) freopen(s ".txt", "r", stdin); freopen(t ".txt", "w", stdout);
#define input(j, n, a) for (int _i = (j); _i < (n)+(j); _i++) cin>> a[_i];
#define output(j, n, a, t) for (int _i = (j); _i < (n)+(j); _i++) cout<< a[_i] << (((t) && _i != (n)+(j)-1)? ' ' : '\n');
#define kill(x) return cout<< (x) << endl, 0
#define cl const ll
#define fr first
#define sc second
#define lc (v << 1)
#define rc (lc | 1)
#define mid ((l + r) >> 1)
#define All(x) (x).begin(), (x).end()

cl inf = sizeof(ll) == 4 ? (1e9 + 10) : (3e18), mod = 1e9 + 7, MOD = 998244353;

template <class A,class B> ostream& operator << (ostream& out,const pair<A,B>&a){return out<<'('<<a.first<<", "<<a.second<<')';}
template <class A> ostream& operator << (ostream& out, const vector<A> &a) {
	out<< '['; for (int i = -1; ++i < int(a.size());) out<< a[i] << (i + 1 < int(a.size()) ? ", " : ""); return out<<']'; }
template <class T, typename _t = less <T> > using Tree = tree <T, null_type, _t, rb_tree_tag, tree_order_statistics_node_update>;

cl N = 2e5 + 7;

ll e1 [N], e2 [N];

struct DSU {
	ll par [N], sz [N], epr [N], bads;
	bool is [N];
	vector <pll> node;
	inline DSU () { reset(); }
	inline void reset () { iota(par, par + N, 0); fill(sz, sz + N, 1); memset(epr, 0, sizeof epr); node.clear(); memset(is, 0, sizeof is); bads = 0; }

	inline pll root (ll v) {
		ll t = 0;
		for (; v != par[v]; v = par[v]) t ^= epr[v];
		return pll(v, t);
	}

	inline ll unite (ll id) {
		pll x = root(e1[id]), y = root(e2[id]);
		if (x.fr == y.fr) {
			if (x.sc == y.sc) return 0;
			return 1;
		}
		if (sz[x.fr] < sz[y.fr]) swap(x, y);
		is[id] = true;
		node.push_back({y.fr, id});
		sz[x.fr] += sz[y.fr];
		par[y.fr] = x.fr;
		epr[y.fr] = x.sc ^ y.sc ^ 1;
		return 2;
	}

	inline void undo () {
		ll v = node.back().fr;
		sz[par[v]] -= sz[v];
		par[v] = v;
		epr[v] = 0;
		is[node.back().sc] = false;
		node.pop_back();
	}
} ds;

ll dp [N], n, m, q, suff;

void solve (ll l, ll r, ll optl) {
	if (l > r) return;
	ll m = l + r >> 1, opt = m + 1;

	for (ll i = r; i >= m; i--) ds.unite(i);
	solve(l, m - 1, optl);
	if (ds.is[m]) ds.undo();

	for (ll i = optl; i <= m; i++) if (!ds.unite(i)) { opt = i; break; }
	dp[m] = opt;
	for (ll i = opt - 1; i >= optl; i--) if (ds.is[i]) ds.undo();
	for (ll i = m + 1; i <= r; i++) if (ds.is[i]) ds.undo();
	for (ll i = optl; i < opt; i++) ds.unite(i);

	solve(m + 1, r, opt);
	for (ll i = opt - 1; i >= optl; i--) if (ds.is[i]) ds.undo(); // :OBD:
}

int main ()
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	cin>> n >> m >> q;
	for (ll i = 1; i <= m; i++) cin>> e1[i] >> e2[i];

	for (ll i = m; i; i--) if (!ds.unite(i)) { suff = i; break; }

	ds.reset();
	solve(suff, m, 1);

	for (ll l, r; q--;) {
		cin>> l >> r;
		if (r < suff || dp[r] < l) cout<< "YES\n";
		else cout<< "NO\n";
	}

	cerr<< "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";

	return 0;
}
/*

*/

Compilation message

Joker.cpp: In function 'void solve(ll, ll, ll)':
Joker.cpp:92:11: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   92 |  ll m = l + r >> 1, opt = m + 1;
      |         ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3052 KB Output is correct
2 Correct 2 ms 2924 KB Output is correct
3 Correct 2 ms 2924 KB Output is correct
4 Correct 2 ms 2924 KB Output is correct
5 Correct 2 ms 2924 KB Output is correct
6 Correct 2 ms 2924 KB Output is correct
7 Correct 2 ms 2924 KB Output is correct
8 Correct 2 ms 2924 KB Output is correct
9 Correct 2 ms 2924 KB Output is correct
10 Correct 2 ms 2924 KB Output is correct
11 Correct 2 ms 2924 KB Output is correct
12 Correct 2 ms 2924 KB Output is correct
13 Correct 2 ms 2924 KB Output is correct
14 Correct 2 ms 2924 KB Output is correct
15 Correct 2 ms 2924 KB Output is correct
16 Correct 2 ms 2924 KB Output is correct
17 Correct 2 ms 2924 KB Output is correct
18 Correct 2 ms 2924 KB Output is correct
19 Correct 2 ms 2944 KB Output is correct
20 Correct 2 ms 2924 KB Output is correct
21 Correct 2 ms 2924 KB Output is correct
22 Correct 2 ms 2924 KB Output is correct
23 Correct 2 ms 2924 KB Output is correct
24 Correct 3 ms 2924 KB Output is correct
25 Correct 2 ms 2924 KB Output is correct
26 Correct 2 ms 2924 KB Output is correct
27 Correct 2 ms 2924 KB Output is correct
28 Correct 3 ms 2924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3052 KB Output is correct
2 Correct 2 ms 2924 KB Output is correct
3 Correct 2 ms 2924 KB Output is correct
4 Correct 2 ms 2924 KB Output is correct
5 Correct 2 ms 2924 KB Output is correct
6 Correct 2 ms 2924 KB Output is correct
7 Correct 2 ms 2924 KB Output is correct
8 Correct 2 ms 2924 KB Output is correct
9 Correct 2 ms 2924 KB Output is correct
10 Correct 2 ms 2924 KB Output is correct
11 Correct 2 ms 2924 KB Output is correct
12 Correct 2 ms 2924 KB Output is correct
13 Correct 2 ms 2924 KB Output is correct
14 Correct 2 ms 2924 KB Output is correct
15 Correct 2 ms 2924 KB Output is correct
16 Correct 2 ms 2924 KB Output is correct
17 Correct 2 ms 2924 KB Output is correct
18 Correct 2 ms 2924 KB Output is correct
19 Correct 2 ms 2944 KB Output is correct
20 Correct 2 ms 2924 KB Output is correct
21 Correct 2 ms 2924 KB Output is correct
22 Correct 2 ms 2924 KB Output is correct
23 Correct 2 ms 2924 KB Output is correct
24 Correct 3 ms 2924 KB Output is correct
25 Correct 2 ms 2924 KB Output is correct
26 Correct 2 ms 2924 KB Output is correct
27 Correct 2 ms 2924 KB Output is correct
28 Correct 3 ms 2924 KB Output is correct
29 Correct 3 ms 2924 KB Output is correct
30 Correct 4 ms 3052 KB Output is correct
31 Correct 3 ms 3052 KB Output is correct
32 Correct 3 ms 3052 KB Output is correct
33 Correct 3 ms 3072 KB Output is correct
34 Correct 3 ms 3052 KB Output is correct
35 Correct 4 ms 3052 KB Output is correct
36 Correct 3 ms 3052 KB Output is correct
37 Correct 4 ms 3052 KB Output is correct
38 Correct 4 ms 3052 KB Output is correct
39 Correct 3 ms 3052 KB Output is correct
40 Correct 3 ms 3052 KB Output is correct
41 Correct 3 ms 3052 KB Output is correct
42 Correct 3 ms 3052 KB Output is correct
43 Correct 3 ms 3052 KB Output is correct
44 Correct 5 ms 3052 KB Output is correct
45 Correct 4 ms 3052 KB Output is correct
46 Correct 3 ms 3052 KB Output is correct
47 Correct 3 ms 3052 KB Output is correct
48 Correct 3 ms 3052 KB Output is correct
49 Correct 3 ms 3052 KB Output is correct
50 Correct 4 ms 3180 KB Output is correct
51 Correct 3 ms 3052 KB Output is correct
52 Correct 4 ms 3052 KB Output is correct
53 Correct 4 ms 3052 KB Output is correct
54 Correct 4 ms 3052 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3052 KB Output is correct
2 Correct 2 ms 2924 KB Output is correct
3 Correct 158 ms 10472 KB Output is correct
4 Correct 271 ms 11108 KB Output is correct
5 Correct 120 ms 11000 KB Output is correct
6 Correct 137 ms 10472 KB Output is correct
7 Correct 154 ms 10420 KB Output is correct
8 Correct 148 ms 9648 KB Output is correct
9 Correct 168 ms 9832 KB Output is correct
10 Correct 242 ms 10320 KB Output is correct
11 Correct 178 ms 10344 KB Output is correct
12 Correct 183 ms 10600 KB Output is correct
13 Correct 124 ms 9584 KB Output is correct
14 Correct 154 ms 10092 KB Output is correct
15 Correct 196 ms 10344 KB Output is correct
16 Correct 243 ms 10600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3052 KB Output is correct
2 Correct 2 ms 2924 KB Output is correct
3 Correct 2 ms 2924 KB Output is correct
4 Correct 2 ms 2924 KB Output is correct
5 Correct 2 ms 2924 KB Output is correct
6 Correct 2 ms 2924 KB Output is correct
7 Correct 2 ms 2924 KB Output is correct
8 Correct 2 ms 2924 KB Output is correct
9 Correct 2 ms 2924 KB Output is correct
10 Correct 2 ms 2924 KB Output is correct
11 Correct 2 ms 2924 KB Output is correct
12 Correct 2 ms 2924 KB Output is correct
13 Correct 2 ms 2924 KB Output is correct
14 Correct 2 ms 2924 KB Output is correct
15 Correct 2 ms 2924 KB Output is correct
16 Correct 2 ms 2924 KB Output is correct
17 Correct 2 ms 2924 KB Output is correct
18 Correct 2 ms 2924 KB Output is correct
19 Correct 2 ms 2944 KB Output is correct
20 Correct 2 ms 2924 KB Output is correct
21 Correct 2 ms 2924 KB Output is correct
22 Correct 2 ms 2924 KB Output is correct
23 Correct 2 ms 2924 KB Output is correct
24 Correct 3 ms 2924 KB Output is correct
25 Correct 2 ms 2924 KB Output is correct
26 Correct 2 ms 2924 KB Output is correct
27 Correct 2 ms 2924 KB Output is correct
28 Correct 3 ms 2924 KB Output is correct
29 Correct 158 ms 10472 KB Output is correct
30 Correct 271 ms 11108 KB Output is correct
31 Correct 120 ms 11000 KB Output is correct
32 Correct 137 ms 10472 KB Output is correct
33 Correct 154 ms 10420 KB Output is correct
34 Correct 148 ms 9648 KB Output is correct
35 Correct 168 ms 9832 KB Output is correct
36 Correct 242 ms 10320 KB Output is correct
37 Correct 178 ms 10344 KB Output is correct
38 Correct 183 ms 10600 KB Output is correct
39 Correct 124 ms 9584 KB Output is correct
40 Correct 154 ms 10092 KB Output is correct
41 Correct 196 ms 10344 KB Output is correct
42 Correct 243 ms 10600 KB Output is correct
43 Correct 163 ms 10728 KB Output is correct
44 Correct 281 ms 11620 KB Output is correct
45 Correct 212 ms 12004 KB Output is correct
46 Correct 158 ms 10856 KB Output is correct
47 Correct 159 ms 10728 KB Output is correct
48 Correct 192 ms 10216 KB Output is correct
49 Correct 239 ms 10600 KB Output is correct
50 Correct 162 ms 10472 KB Output is correct
51 Correct 187 ms 10856 KB Output is correct
52 Correct 192 ms 10856 KB Output is correct
53 Correct 144 ms 10096 KB Output is correct
54 Correct 185 ms 10472 KB Output is correct
55 Correct 230 ms 10896 KB Output is correct
56 Correct 230 ms 10984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3052 KB Output is correct
2 Correct 2 ms 2924 KB Output is correct
3 Correct 2 ms 2924 KB Output is correct
4 Correct 2 ms 2924 KB Output is correct
5 Correct 2 ms 2924 KB Output is correct
6 Correct 2 ms 2924 KB Output is correct
7 Correct 2 ms 2924 KB Output is correct
8 Correct 2 ms 2924 KB Output is correct
9 Correct 2 ms 2924 KB Output is correct
10 Correct 2 ms 2924 KB Output is correct
11 Correct 2 ms 2924 KB Output is correct
12 Correct 2 ms 2924 KB Output is correct
13 Correct 2 ms 2924 KB Output is correct
14 Correct 2 ms 2924 KB Output is correct
15 Correct 2 ms 2924 KB Output is correct
16 Correct 2 ms 2924 KB Output is correct
17 Correct 2 ms 2924 KB Output is correct
18 Correct 2 ms 2924 KB Output is correct
19 Correct 2 ms 2944 KB Output is correct
20 Correct 2 ms 2924 KB Output is correct
21 Correct 2 ms 2924 KB Output is correct
22 Correct 2 ms 2924 KB Output is correct
23 Correct 2 ms 2924 KB Output is correct
24 Correct 3 ms 2924 KB Output is correct
25 Correct 2 ms 2924 KB Output is correct
26 Correct 2 ms 2924 KB Output is correct
27 Correct 2 ms 2924 KB Output is correct
28 Correct 3 ms 2924 KB Output is correct
29 Correct 3 ms 2924 KB Output is correct
30 Correct 4 ms 3052 KB Output is correct
31 Correct 3 ms 3052 KB Output is correct
32 Correct 3 ms 3052 KB Output is correct
33 Correct 3 ms 3072 KB Output is correct
34 Correct 3 ms 3052 KB Output is correct
35 Correct 4 ms 3052 KB Output is correct
36 Correct 3 ms 3052 KB Output is correct
37 Correct 4 ms 3052 KB Output is correct
38 Correct 4 ms 3052 KB Output is correct
39 Correct 3 ms 3052 KB Output is correct
40 Correct 3 ms 3052 KB Output is correct
41 Correct 3 ms 3052 KB Output is correct
42 Correct 3 ms 3052 KB Output is correct
43 Correct 3 ms 3052 KB Output is correct
44 Correct 5 ms 3052 KB Output is correct
45 Correct 4 ms 3052 KB Output is correct
46 Correct 3 ms 3052 KB Output is correct
47 Correct 3 ms 3052 KB Output is correct
48 Correct 3 ms 3052 KB Output is correct
49 Correct 3 ms 3052 KB Output is correct
50 Correct 4 ms 3180 KB Output is correct
51 Correct 3 ms 3052 KB Output is correct
52 Correct 4 ms 3052 KB Output is correct
53 Correct 4 ms 3052 KB Output is correct
54 Correct 4 ms 3052 KB Output is correct
55 Correct 115 ms 8168 KB Output is correct
56 Correct 226 ms 9444 KB Output is correct
57 Correct 85 ms 9316 KB Output is correct
58 Correct 104 ms 8168 KB Output is correct
59 Correct 144 ms 8040 KB Output is correct
60 Correct 186 ms 8384 KB Output is correct
61 Correct 133 ms 8040 KB Output is correct
62 Correct 171 ms 8552 KB Output is correct
63 Correct 99 ms 7532 KB Output is correct
64 Correct 149 ms 8168 KB Output is correct
65 Correct 186 ms 8432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3052 KB Output is correct
2 Correct 2 ms 2924 KB Output is correct
3 Correct 2 ms 2924 KB Output is correct
4 Correct 2 ms 2924 KB Output is correct
5 Correct 2 ms 2924 KB Output is correct
6 Correct 2 ms 2924 KB Output is correct
7 Correct 2 ms 2924 KB Output is correct
8 Correct 2 ms 2924 KB Output is correct
9 Correct 2 ms 2924 KB Output is correct
10 Correct 2 ms 2924 KB Output is correct
11 Correct 2 ms 2924 KB Output is correct
12 Correct 2 ms 2924 KB Output is correct
13 Correct 2 ms 2924 KB Output is correct
14 Correct 2 ms 2924 KB Output is correct
15 Correct 2 ms 2924 KB Output is correct
16 Correct 2 ms 2924 KB Output is correct
17 Correct 2 ms 2924 KB Output is correct
18 Correct 2 ms 2924 KB Output is correct
19 Correct 2 ms 2944 KB Output is correct
20 Correct 2 ms 2924 KB Output is correct
21 Correct 2 ms 2924 KB Output is correct
22 Correct 2 ms 2924 KB Output is correct
23 Correct 2 ms 2924 KB Output is correct
24 Correct 3 ms 2924 KB Output is correct
25 Correct 2 ms 2924 KB Output is correct
26 Correct 2 ms 2924 KB Output is correct
27 Correct 2 ms 2924 KB Output is correct
28 Correct 3 ms 2924 KB Output is correct
29 Correct 3 ms 2924 KB Output is correct
30 Correct 4 ms 3052 KB Output is correct
31 Correct 3 ms 3052 KB Output is correct
32 Correct 3 ms 3052 KB Output is correct
33 Correct 3 ms 3072 KB Output is correct
34 Correct 3 ms 3052 KB Output is correct
35 Correct 4 ms 3052 KB Output is correct
36 Correct 3 ms 3052 KB Output is correct
37 Correct 4 ms 3052 KB Output is correct
38 Correct 4 ms 3052 KB Output is correct
39 Correct 3 ms 3052 KB Output is correct
40 Correct 3 ms 3052 KB Output is correct
41 Correct 3 ms 3052 KB Output is correct
42 Correct 3 ms 3052 KB Output is correct
43 Correct 3 ms 3052 KB Output is correct
44 Correct 5 ms 3052 KB Output is correct
45 Correct 4 ms 3052 KB Output is correct
46 Correct 3 ms 3052 KB Output is correct
47 Correct 3 ms 3052 KB Output is correct
48 Correct 3 ms 3052 KB Output is correct
49 Correct 3 ms 3052 KB Output is correct
50 Correct 4 ms 3180 KB Output is correct
51 Correct 3 ms 3052 KB Output is correct
52 Correct 4 ms 3052 KB Output is correct
53 Correct 4 ms 3052 KB Output is correct
54 Correct 4 ms 3052 KB Output is correct
55 Correct 158 ms 10472 KB Output is correct
56 Correct 271 ms 11108 KB Output is correct
57 Correct 120 ms 11000 KB Output is correct
58 Correct 137 ms 10472 KB Output is correct
59 Correct 154 ms 10420 KB Output is correct
60 Correct 148 ms 9648 KB Output is correct
61 Correct 168 ms 9832 KB Output is correct
62 Correct 242 ms 10320 KB Output is correct
63 Correct 178 ms 10344 KB Output is correct
64 Correct 183 ms 10600 KB Output is correct
65 Correct 124 ms 9584 KB Output is correct
66 Correct 154 ms 10092 KB Output is correct
67 Correct 196 ms 10344 KB Output is correct
68 Correct 243 ms 10600 KB Output is correct
69 Correct 163 ms 10728 KB Output is correct
70 Correct 281 ms 11620 KB Output is correct
71 Correct 212 ms 12004 KB Output is correct
72 Correct 158 ms 10856 KB Output is correct
73 Correct 159 ms 10728 KB Output is correct
74 Correct 192 ms 10216 KB Output is correct
75 Correct 239 ms 10600 KB Output is correct
76 Correct 162 ms 10472 KB Output is correct
77 Correct 187 ms 10856 KB Output is correct
78 Correct 192 ms 10856 KB Output is correct
79 Correct 144 ms 10096 KB Output is correct
80 Correct 185 ms 10472 KB Output is correct
81 Correct 230 ms 10896 KB Output is correct
82 Correct 230 ms 10984 KB Output is correct
83 Correct 115 ms 8168 KB Output is correct
84 Correct 226 ms 9444 KB Output is correct
85 Correct 85 ms 9316 KB Output is correct
86 Correct 104 ms 8168 KB Output is correct
87 Correct 144 ms 8040 KB Output is correct
88 Correct 186 ms 8384 KB Output is correct
89 Correct 133 ms 8040 KB Output is correct
90 Correct 171 ms 8552 KB Output is correct
91 Correct 99 ms 7532 KB Output is correct
92 Correct 149 ms 8168 KB Output is correct
93 Correct 186 ms 8432 KB Output is correct
94 Correct 176 ms 11368 KB Output is correct
95 Correct 309 ms 12260 KB Output is correct
96 Correct 135 ms 12004 KB Output is correct
97 Correct 151 ms 11496 KB Output is correct
98 Correct 168 ms 11496 KB Output is correct
99 Correct 161 ms 11116 KB Output is correct
100 Correct 206 ms 11624 KB Output is correct
101 Correct 168 ms 11240 KB Output is correct
102 Correct 188 ms 11496 KB Output is correct
103 Correct 256 ms 11752 KB Output is correct
104 Correct 156 ms 10860 KB Output is correct
105 Correct 209 ms 11496 KB Output is correct
106 Correct 233 ms 11624 KB Output is correct
107 Correct 122 ms 12900 KB Output is correct
108 Correct 162 ms 11368 KB Output is correct
109 Correct 165 ms 11240 KB Output is correct
110 Correct 167 ms 11356 KB Output is correct
111 Correct 163 ms 11368 KB Output is correct
112 Correct 163 ms 11240 KB Output is correct
113 Correct 171 ms 11240 KB Output is correct
114 Correct 170 ms 11264 KB Output is correct
115 Correct 162 ms 11240 KB Output is correct
116 Correct 164 ms 11516 KB Output is correct