Submission #929169

# Submission time Handle Problem Language Result Execution time Memory
929169 2024-02-17T19:38:00 Z Joshua_Andersson Joker (BOI20_joker) C++14
14 / 100
2000 ms 20676 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define int ll
const int inf = int(1e18);

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> p2;

#define rep(i, high) for (int i = 0; i < high; i++)
#define repp(i, low, high) for (int i = low; i < high; i++)
#define repe(i, container) for (auto& i : container)
#define sz(container) ((int)container.size())

inline void fast() { ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); }

struct change
{
	int a, b;
	int oldpar, oldxor, oldsize;
};

struct UF
{
	vector<change> updates;
	vi size;
	vi par;
	vi parity;

	UF(int n) : size(n, 1), parity(n), par(n)
	{
		rep(i, n)par[i] = i;
	}

	int find(int x) { return x == par[x] ? x : find(par[x]); }
	int getparity(int x) { return x == par[x] ? parity[x] : parity[x] ^ getparity(par[x]); }
	bool oddcycle(int a, int b)
	{
		return getparity(a) == getparity(b);
	}

	void merge(int a, int b)
	{
		if (size[find(a)] < size[find(b)]) swap(a, b);
		int childa = a;
		int childb = b;
		a = find(a); b = find(b);
		change c({a,b,par[b],parity[b],size[a]});
		updates.push_back(c);

		if (a != b)
		{
			parity[b] = getparity(childb) ^ getparity(childa) ^ 1;
			size[a] += size[b];
			par[b] = a;
		}
	}

	void rollback()
	{
		change c = updates.back();
		updates.pop_back();
		par[c.b] = c.oldpar;
		parity[c.b] = c.oldxor;
		size[c.a] = c.oldsize;
	}
};

signed main()
{
	fast();

	int n, m, q;
	cin >> n >> m >> q;
	vector<p2> edgelist;
	rep(i, m)
	{
		int a, b;
		cin >> a >> b;
		a--; b--;
		edgelist.emplace_back(a, b);
	}
	//shuffle(edgelist.begin(), prev(edgelist.end()), mt19937(3436876));

	UF uf(n);
	vi right(m, inf);
	bool anyodd = 0;
	auto add = [&](int i)
	{
		int a, b;
		tie(a, b) = edgelist[i];
		int ret = 0;
		if (uf.find(a) == uf.find(b)) ret = uf.oddcycle(a, b);
		uf.merge(a, b);
		return ret;
	};
	rep(i, m)
	{
		int lo = i;
		int hi = m;
		while (lo+1<hi)
		{
			int mid = (lo + hi) / 2;
			bool odd = 0;
			for (int j = m - 1; j >= mid; j--) odd |= add(j);
			for (int j = m - 1; j >= mid; j--) uf.rollback();
			if (odd) lo = mid;
			else hi = mid;
		}
		right[i] = lo;

		if (anyodd) right[i] = inf;
		anyodd |= add(i);
	}

	//vvi queries(m);
	while (q--)
	{
		int l, r;
		cin >> l >> r;
		l--; r--;
		
		cout << (r+1<=right[l] ? "YES" : "NO") << "\n";
	}

	return 0;
}

Compilation message

Joker.cpp: In constructor 'UF::UF(ll)':
Joker.cpp:30:5: warning: 'UF::parity' will be initialized after [-Wreorder]
   30 |  vi parity;
      |     ^~~~~~
Joker.cpp:29:5: warning:   'vi UF::par' [-Wreorder]
   29 |  vi par;
      |     ^~~
Joker.cpp:32:2: warning:   when initialized here [-Wreorder]
   32 |  UF(int n) : size(n, 1), parity(n), par(n)
      |  ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 488 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 488 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 59 ms 604 KB Output is correct
30 Correct 96 ms 600 KB Output is correct
31 Correct 84 ms 856 KB Output is correct
32 Correct 57 ms 604 KB Output is correct
33 Correct 46 ms 604 KB Output is correct
34 Correct 95 ms 688 KB Output is correct
35 Correct 117 ms 676 KB Output is correct
36 Correct 92 ms 1056 KB Output is correct
37 Correct 197 ms 692 KB Output is correct
38 Correct 259 ms 692 KB Output is correct
39 Correct 43 ms 680 KB Output is correct
40 Correct 41 ms 600 KB Output is correct
41 Correct 40 ms 600 KB Output is correct
42 Correct 39 ms 604 KB Output is correct
43 Correct 50 ms 604 KB Output is correct
44 Correct 57 ms 640 KB Output is correct
45 Correct 63 ms 600 KB Output is correct
46 Correct 112 ms 848 KB Output is correct
47 Correct 56 ms 604 KB Output is correct
48 Correct 70 ms 604 KB Output is correct
49 Correct 81 ms 660 KB Output is correct
50 Correct 108 ms 600 KB Output is correct
51 Correct 51 ms 648 KB Output is correct
52 Correct 57 ms 604 KB Output is correct
53 Correct 72 ms 604 KB Output is correct
54 Correct 115 ms 692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 2075 ms 20160 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 488 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Execution timed out 2075 ms 20160 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 488 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 59 ms 604 KB Output is correct
30 Correct 96 ms 600 KB Output is correct
31 Correct 84 ms 856 KB Output is correct
32 Correct 57 ms 604 KB Output is correct
33 Correct 46 ms 604 KB Output is correct
34 Correct 95 ms 688 KB Output is correct
35 Correct 117 ms 676 KB Output is correct
36 Correct 92 ms 1056 KB Output is correct
37 Correct 197 ms 692 KB Output is correct
38 Correct 259 ms 692 KB Output is correct
39 Correct 43 ms 680 KB Output is correct
40 Correct 41 ms 600 KB Output is correct
41 Correct 40 ms 600 KB Output is correct
42 Correct 39 ms 604 KB Output is correct
43 Correct 50 ms 604 KB Output is correct
44 Correct 57 ms 640 KB Output is correct
45 Correct 63 ms 600 KB Output is correct
46 Correct 112 ms 848 KB Output is correct
47 Correct 56 ms 604 KB Output is correct
48 Correct 70 ms 604 KB Output is correct
49 Correct 81 ms 660 KB Output is correct
50 Correct 108 ms 600 KB Output is correct
51 Correct 51 ms 648 KB Output is correct
52 Correct 57 ms 604 KB Output is correct
53 Correct 72 ms 604 KB Output is correct
54 Correct 115 ms 692 KB Output is correct
55 Execution timed out 2039 ms 20676 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 2 ms 488 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 344 KB Output is correct
28 Correct 1 ms 344 KB Output is correct
29 Correct 59 ms 604 KB Output is correct
30 Correct 96 ms 600 KB Output is correct
31 Correct 84 ms 856 KB Output is correct
32 Correct 57 ms 604 KB Output is correct
33 Correct 46 ms 604 KB Output is correct
34 Correct 95 ms 688 KB Output is correct
35 Correct 117 ms 676 KB Output is correct
36 Correct 92 ms 1056 KB Output is correct
37 Correct 197 ms 692 KB Output is correct
38 Correct 259 ms 692 KB Output is correct
39 Correct 43 ms 680 KB Output is correct
40 Correct 41 ms 600 KB Output is correct
41 Correct 40 ms 600 KB Output is correct
42 Correct 39 ms 604 KB Output is correct
43 Correct 50 ms 604 KB Output is correct
44 Correct 57 ms 640 KB Output is correct
45 Correct 63 ms 600 KB Output is correct
46 Correct 112 ms 848 KB Output is correct
47 Correct 56 ms 604 KB Output is correct
48 Correct 70 ms 604 KB Output is correct
49 Correct 81 ms 660 KB Output is correct
50 Correct 108 ms 600 KB Output is correct
51 Correct 51 ms 648 KB Output is correct
52 Correct 57 ms 604 KB Output is correct
53 Correct 72 ms 604 KB Output is correct
54 Correct 115 ms 692 KB Output is correct
55 Execution timed out 2075 ms 20160 KB Time limit exceeded
56 Halted 0 ms 0 KB -