# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
716503 |
2023-03-30T08:03:34 Z |
josanneo22 |
Joker (BOI20_joker) |
C++17 |
|
2000 ms |
22112 KB |
#include <bits/stdc++.h>
using namespace std;
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define sp " "
#define endl "\n"
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 400005
const int modulo = 1e9 + 7;
int ans[N], u[N], v[N], l[N], r[N], n, sz[N];
vector<int> root;
vector<pii> block[N];
int res[N], s;
int find(vector<int> &b, int node, int flag)
{
if (node < 0) return -(find(b, -node, flag));
if (node == b[node]) return node;
if (flag) return b[node] = find(b, b[node], flag);
return find(b, b[node], flag);
}
int32_t main()
{
fastio();
int m, q;
cin>>n>>m>>q;
root.resize(n + 5, 0);
while(s * s < m) s++;
for (int i = 1; i <= m; i++)
{
cin>>u[i]>>v[i];
}
int maks = 0;
for (int i = 1; i <= q; i++)
{
cin>>l[i]>>r[i];
block[l[i] / s].pb({r[i], i});
}
int it = 0;
for (int i = 0; i <= m / s + 1; i++)
{
for (int j = 1; j <= n; j++) root[j] = j, sz[j] = 1;
sort(block[i].rbegin(), block[i].rend());
stack<pii> sl, slz;
int last = m;
for (auto j : block[i])
{
while(!sl.empty())
{
root[sl.top().st] = sl.top().nd;
sl.pop();
sz[slz.top().st] = slz.top().nd;
slz.pop();
}
//cout<<j.nd<<sp<<l[j.nd]<<sp<<r[j.nd]<<endl;
while(last > r[j.nd])
{
int a = find(root, u[last], 1), b = find(root, v[last], 1);
if (a == b)
{
res[j.nd] = 1;
break;
}
else
{
if (sz[abs(a)] > sz[abs(b)]) swap(a, b);
if (a < 0) a *= -1, b *= -1;
sz[abs(b)] += sz[a];
root[a] = -b;
}
last--;
}
for (int k = 1; k < l[j.nd]; k++)
{
int a = find(root, u[k], 0), b = find(root, v[k], 0);
if (a == b)
{
res[j.nd] = 1;
break;
}
else
{
if (sz[abs(a)] > sz[abs(b)]) swap(a, b);
if (a < 0) a *= -1, b *= -1;
slz.push({abs(b), sz[abs(b)]});
sz[abs(b)] += sz[a];
sl.push({a, root[a]});
root[a] = -b;
}
}
}
}
for (int i = 1; i <= q; i++)
{
if (res[i]) cout<<"YES\n";
else cout<<"NO\n";
}
cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
Compilation message
Joker.cpp: In function 'int32_t main()':
Joker.cpp:43:6: warning: unused variable 'maks' [-Wunused-variable]
43 | int maks = 0;
| ^~~~
Joker.cpp:50:6: warning: unused variable 'it' [-Wunused-variable]
50 | int it = 0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
6 ms |
9684 KB |
Output is correct |
7 |
Correct |
7 ms |
9728 KB |
Output is correct |
8 |
Correct |
6 ms |
9684 KB |
Output is correct |
9 |
Correct |
6 ms |
9648 KB |
Output is correct |
10 |
Correct |
6 ms |
9684 KB |
Output is correct |
11 |
Correct |
6 ms |
9684 KB |
Output is correct |
12 |
Correct |
6 ms |
9716 KB |
Output is correct |
13 |
Correct |
6 ms |
9684 KB |
Output is correct |
14 |
Correct |
7 ms |
9724 KB |
Output is correct |
15 |
Correct |
6 ms |
9692 KB |
Output is correct |
16 |
Correct |
6 ms |
9692 KB |
Output is correct |
17 |
Correct |
6 ms |
9684 KB |
Output is correct |
18 |
Correct |
6 ms |
9728 KB |
Output is correct |
19 |
Correct |
6 ms |
9684 KB |
Output is correct |
20 |
Correct |
6 ms |
9812 KB |
Output is correct |
21 |
Correct |
7 ms |
9684 KB |
Output is correct |
22 |
Correct |
6 ms |
9700 KB |
Output is correct |
23 |
Correct |
6 ms |
9684 KB |
Output is correct |
24 |
Correct |
6 ms |
9696 KB |
Output is correct |
25 |
Correct |
6 ms |
9744 KB |
Output is correct |
26 |
Correct |
6 ms |
9728 KB |
Output is correct |
27 |
Correct |
6 ms |
9684 KB |
Output is correct |
28 |
Correct |
6 ms |
9684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
6 ms |
9684 KB |
Output is correct |
7 |
Correct |
7 ms |
9728 KB |
Output is correct |
8 |
Correct |
6 ms |
9684 KB |
Output is correct |
9 |
Correct |
6 ms |
9648 KB |
Output is correct |
10 |
Correct |
6 ms |
9684 KB |
Output is correct |
11 |
Correct |
6 ms |
9684 KB |
Output is correct |
12 |
Correct |
6 ms |
9716 KB |
Output is correct |
13 |
Correct |
6 ms |
9684 KB |
Output is correct |
14 |
Correct |
7 ms |
9724 KB |
Output is correct |
15 |
Correct |
6 ms |
9692 KB |
Output is correct |
16 |
Correct |
6 ms |
9692 KB |
Output is correct |
17 |
Correct |
6 ms |
9684 KB |
Output is correct |
18 |
Correct |
6 ms |
9728 KB |
Output is correct |
19 |
Correct |
6 ms |
9684 KB |
Output is correct |
20 |
Correct |
6 ms |
9812 KB |
Output is correct |
21 |
Correct |
7 ms |
9684 KB |
Output is correct |
22 |
Correct |
6 ms |
9700 KB |
Output is correct |
23 |
Correct |
6 ms |
9684 KB |
Output is correct |
24 |
Correct |
6 ms |
9696 KB |
Output is correct |
25 |
Correct |
6 ms |
9744 KB |
Output is correct |
26 |
Correct |
6 ms |
9728 KB |
Output is correct |
27 |
Correct |
6 ms |
9684 KB |
Output is correct |
28 |
Correct |
6 ms |
9684 KB |
Output is correct |
29 |
Correct |
36 ms |
9844 KB |
Output is correct |
30 |
Correct |
44 ms |
9884 KB |
Output is correct |
31 |
Correct |
43 ms |
9888 KB |
Output is correct |
32 |
Correct |
30 ms |
9880 KB |
Output is correct |
33 |
Correct |
22 ms |
9880 KB |
Output is correct |
34 |
Correct |
35 ms |
9876 KB |
Output is correct |
35 |
Correct |
53 ms |
9884 KB |
Output is correct |
36 |
Correct |
48 ms |
9876 KB |
Output is correct |
37 |
Correct |
74 ms |
9820 KB |
Output is correct |
38 |
Correct |
71 ms |
9892 KB |
Output is correct |
39 |
Correct |
59 ms |
9896 KB |
Output is correct |
40 |
Correct |
41 ms |
9892 KB |
Output is correct |
41 |
Correct |
41 ms |
9892 KB |
Output is correct |
42 |
Correct |
40 ms |
9880 KB |
Output is correct |
43 |
Correct |
11 ms |
9872 KB |
Output is correct |
44 |
Correct |
17 ms |
9896 KB |
Output is correct |
45 |
Correct |
16 ms |
9872 KB |
Output is correct |
46 |
Correct |
32 ms |
9812 KB |
Output is correct |
47 |
Correct |
52 ms |
9864 KB |
Output is correct |
48 |
Correct |
49 ms |
9872 KB |
Output is correct |
49 |
Correct |
49 ms |
9880 KB |
Output is correct |
50 |
Correct |
50 ms |
9884 KB |
Output is correct |
51 |
Correct |
110 ms |
9820 KB |
Output is correct |
52 |
Correct |
85 ms |
9892 KB |
Output is correct |
53 |
Correct |
52 ms |
9868 KB |
Output is correct |
54 |
Correct |
51 ms |
9896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
127 ms |
18248 KB |
Output is correct |
4 |
Correct |
164 ms |
20276 KB |
Output is correct |
5 |
Correct |
142 ms |
21656 KB |
Output is correct |
6 |
Correct |
127 ms |
20740 KB |
Output is correct |
7 |
Correct |
153 ms |
20932 KB |
Output is correct |
8 |
Correct |
127 ms |
19824 KB |
Output is correct |
9 |
Correct |
126 ms |
20276 KB |
Output is correct |
10 |
Correct |
158 ms |
21252 KB |
Output is correct |
11 |
Correct |
139 ms |
20676 KB |
Output is correct |
12 |
Correct |
149 ms |
21568 KB |
Output is correct |
13 |
Correct |
111 ms |
20000 KB |
Output is correct |
14 |
Correct |
127 ms |
20408 KB |
Output is correct |
15 |
Correct |
134 ms |
21060 KB |
Output is correct |
16 |
Correct |
154 ms |
21560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
6 ms |
9684 KB |
Output is correct |
7 |
Correct |
7 ms |
9728 KB |
Output is correct |
8 |
Correct |
6 ms |
9684 KB |
Output is correct |
9 |
Correct |
6 ms |
9648 KB |
Output is correct |
10 |
Correct |
6 ms |
9684 KB |
Output is correct |
11 |
Correct |
6 ms |
9684 KB |
Output is correct |
12 |
Correct |
6 ms |
9716 KB |
Output is correct |
13 |
Correct |
6 ms |
9684 KB |
Output is correct |
14 |
Correct |
7 ms |
9724 KB |
Output is correct |
15 |
Correct |
6 ms |
9692 KB |
Output is correct |
16 |
Correct |
6 ms |
9692 KB |
Output is correct |
17 |
Correct |
6 ms |
9684 KB |
Output is correct |
18 |
Correct |
6 ms |
9728 KB |
Output is correct |
19 |
Correct |
6 ms |
9684 KB |
Output is correct |
20 |
Correct |
6 ms |
9812 KB |
Output is correct |
21 |
Correct |
7 ms |
9684 KB |
Output is correct |
22 |
Correct |
6 ms |
9700 KB |
Output is correct |
23 |
Correct |
6 ms |
9684 KB |
Output is correct |
24 |
Correct |
6 ms |
9696 KB |
Output is correct |
25 |
Correct |
6 ms |
9744 KB |
Output is correct |
26 |
Correct |
6 ms |
9728 KB |
Output is correct |
27 |
Correct |
6 ms |
9684 KB |
Output is correct |
28 |
Correct |
6 ms |
9684 KB |
Output is correct |
29 |
Correct |
127 ms |
18248 KB |
Output is correct |
30 |
Correct |
164 ms |
20276 KB |
Output is correct |
31 |
Correct |
142 ms |
21656 KB |
Output is correct |
32 |
Correct |
127 ms |
20740 KB |
Output is correct |
33 |
Correct |
153 ms |
20932 KB |
Output is correct |
34 |
Correct |
127 ms |
19824 KB |
Output is correct |
35 |
Correct |
126 ms |
20276 KB |
Output is correct |
36 |
Correct |
158 ms |
21252 KB |
Output is correct |
37 |
Correct |
139 ms |
20676 KB |
Output is correct |
38 |
Correct |
149 ms |
21568 KB |
Output is correct |
39 |
Correct |
111 ms |
20000 KB |
Output is correct |
40 |
Correct |
127 ms |
20408 KB |
Output is correct |
41 |
Correct |
134 ms |
21060 KB |
Output is correct |
42 |
Correct |
154 ms |
21560 KB |
Output is correct |
43 |
Correct |
637 ms |
21212 KB |
Output is correct |
44 |
Correct |
763 ms |
20716 KB |
Output is correct |
45 |
Correct |
759 ms |
21832 KB |
Output is correct |
46 |
Correct |
597 ms |
21100 KB |
Output is correct |
47 |
Correct |
542 ms |
21104 KB |
Output is correct |
48 |
Correct |
197 ms |
20676 KB |
Output is correct |
49 |
Correct |
798 ms |
21868 KB |
Output is correct |
50 |
Correct |
1089 ms |
20796 KB |
Output is correct |
51 |
Correct |
902 ms |
21512 KB |
Output is correct |
52 |
Correct |
825 ms |
21820 KB |
Output is correct |
53 |
Correct |
778 ms |
20288 KB |
Output is correct |
54 |
Correct |
1387 ms |
20924 KB |
Output is correct |
55 |
Correct |
878 ms |
21460 KB |
Output is correct |
56 |
Correct |
797 ms |
22112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
6 ms |
9684 KB |
Output is correct |
7 |
Correct |
7 ms |
9728 KB |
Output is correct |
8 |
Correct |
6 ms |
9684 KB |
Output is correct |
9 |
Correct |
6 ms |
9648 KB |
Output is correct |
10 |
Correct |
6 ms |
9684 KB |
Output is correct |
11 |
Correct |
6 ms |
9684 KB |
Output is correct |
12 |
Correct |
6 ms |
9716 KB |
Output is correct |
13 |
Correct |
6 ms |
9684 KB |
Output is correct |
14 |
Correct |
7 ms |
9724 KB |
Output is correct |
15 |
Correct |
6 ms |
9692 KB |
Output is correct |
16 |
Correct |
6 ms |
9692 KB |
Output is correct |
17 |
Correct |
6 ms |
9684 KB |
Output is correct |
18 |
Correct |
6 ms |
9728 KB |
Output is correct |
19 |
Correct |
6 ms |
9684 KB |
Output is correct |
20 |
Correct |
6 ms |
9812 KB |
Output is correct |
21 |
Correct |
7 ms |
9684 KB |
Output is correct |
22 |
Correct |
6 ms |
9700 KB |
Output is correct |
23 |
Correct |
6 ms |
9684 KB |
Output is correct |
24 |
Correct |
6 ms |
9696 KB |
Output is correct |
25 |
Correct |
6 ms |
9744 KB |
Output is correct |
26 |
Correct |
6 ms |
9728 KB |
Output is correct |
27 |
Correct |
6 ms |
9684 KB |
Output is correct |
28 |
Correct |
6 ms |
9684 KB |
Output is correct |
29 |
Correct |
36 ms |
9844 KB |
Output is correct |
30 |
Correct |
44 ms |
9884 KB |
Output is correct |
31 |
Correct |
43 ms |
9888 KB |
Output is correct |
32 |
Correct |
30 ms |
9880 KB |
Output is correct |
33 |
Correct |
22 ms |
9880 KB |
Output is correct |
34 |
Correct |
35 ms |
9876 KB |
Output is correct |
35 |
Correct |
53 ms |
9884 KB |
Output is correct |
36 |
Correct |
48 ms |
9876 KB |
Output is correct |
37 |
Correct |
74 ms |
9820 KB |
Output is correct |
38 |
Correct |
71 ms |
9892 KB |
Output is correct |
39 |
Correct |
59 ms |
9896 KB |
Output is correct |
40 |
Correct |
41 ms |
9892 KB |
Output is correct |
41 |
Correct |
41 ms |
9892 KB |
Output is correct |
42 |
Correct |
40 ms |
9880 KB |
Output is correct |
43 |
Correct |
11 ms |
9872 KB |
Output is correct |
44 |
Correct |
17 ms |
9896 KB |
Output is correct |
45 |
Correct |
16 ms |
9872 KB |
Output is correct |
46 |
Correct |
32 ms |
9812 KB |
Output is correct |
47 |
Correct |
52 ms |
9864 KB |
Output is correct |
48 |
Correct |
49 ms |
9872 KB |
Output is correct |
49 |
Correct |
49 ms |
9880 KB |
Output is correct |
50 |
Correct |
50 ms |
9884 KB |
Output is correct |
51 |
Correct |
110 ms |
9820 KB |
Output is correct |
52 |
Correct |
85 ms |
9892 KB |
Output is correct |
53 |
Correct |
52 ms |
9868 KB |
Output is correct |
54 |
Correct |
51 ms |
9896 KB |
Output is correct |
55 |
Execution timed out |
2052 ms |
16196 KB |
Time limit exceeded |
56 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
9684 KB |
Output is correct |
2 |
Correct |
5 ms |
9684 KB |
Output is correct |
3 |
Correct |
5 ms |
9684 KB |
Output is correct |
4 |
Correct |
6 ms |
9684 KB |
Output is correct |
5 |
Correct |
5 ms |
9684 KB |
Output is correct |
6 |
Correct |
6 ms |
9684 KB |
Output is correct |
7 |
Correct |
7 ms |
9728 KB |
Output is correct |
8 |
Correct |
6 ms |
9684 KB |
Output is correct |
9 |
Correct |
6 ms |
9648 KB |
Output is correct |
10 |
Correct |
6 ms |
9684 KB |
Output is correct |
11 |
Correct |
6 ms |
9684 KB |
Output is correct |
12 |
Correct |
6 ms |
9716 KB |
Output is correct |
13 |
Correct |
6 ms |
9684 KB |
Output is correct |
14 |
Correct |
7 ms |
9724 KB |
Output is correct |
15 |
Correct |
6 ms |
9692 KB |
Output is correct |
16 |
Correct |
6 ms |
9692 KB |
Output is correct |
17 |
Correct |
6 ms |
9684 KB |
Output is correct |
18 |
Correct |
6 ms |
9728 KB |
Output is correct |
19 |
Correct |
6 ms |
9684 KB |
Output is correct |
20 |
Correct |
6 ms |
9812 KB |
Output is correct |
21 |
Correct |
7 ms |
9684 KB |
Output is correct |
22 |
Correct |
6 ms |
9700 KB |
Output is correct |
23 |
Correct |
6 ms |
9684 KB |
Output is correct |
24 |
Correct |
6 ms |
9696 KB |
Output is correct |
25 |
Correct |
6 ms |
9744 KB |
Output is correct |
26 |
Correct |
6 ms |
9728 KB |
Output is correct |
27 |
Correct |
6 ms |
9684 KB |
Output is correct |
28 |
Correct |
6 ms |
9684 KB |
Output is correct |
29 |
Correct |
36 ms |
9844 KB |
Output is correct |
30 |
Correct |
44 ms |
9884 KB |
Output is correct |
31 |
Correct |
43 ms |
9888 KB |
Output is correct |
32 |
Correct |
30 ms |
9880 KB |
Output is correct |
33 |
Correct |
22 ms |
9880 KB |
Output is correct |
34 |
Correct |
35 ms |
9876 KB |
Output is correct |
35 |
Correct |
53 ms |
9884 KB |
Output is correct |
36 |
Correct |
48 ms |
9876 KB |
Output is correct |
37 |
Correct |
74 ms |
9820 KB |
Output is correct |
38 |
Correct |
71 ms |
9892 KB |
Output is correct |
39 |
Correct |
59 ms |
9896 KB |
Output is correct |
40 |
Correct |
41 ms |
9892 KB |
Output is correct |
41 |
Correct |
41 ms |
9892 KB |
Output is correct |
42 |
Correct |
40 ms |
9880 KB |
Output is correct |
43 |
Correct |
11 ms |
9872 KB |
Output is correct |
44 |
Correct |
17 ms |
9896 KB |
Output is correct |
45 |
Correct |
16 ms |
9872 KB |
Output is correct |
46 |
Correct |
32 ms |
9812 KB |
Output is correct |
47 |
Correct |
52 ms |
9864 KB |
Output is correct |
48 |
Correct |
49 ms |
9872 KB |
Output is correct |
49 |
Correct |
49 ms |
9880 KB |
Output is correct |
50 |
Correct |
50 ms |
9884 KB |
Output is correct |
51 |
Correct |
110 ms |
9820 KB |
Output is correct |
52 |
Correct |
85 ms |
9892 KB |
Output is correct |
53 |
Correct |
52 ms |
9868 KB |
Output is correct |
54 |
Correct |
51 ms |
9896 KB |
Output is correct |
55 |
Correct |
127 ms |
18248 KB |
Output is correct |
56 |
Correct |
164 ms |
20276 KB |
Output is correct |
57 |
Correct |
142 ms |
21656 KB |
Output is correct |
58 |
Correct |
127 ms |
20740 KB |
Output is correct |
59 |
Correct |
153 ms |
20932 KB |
Output is correct |
60 |
Correct |
127 ms |
19824 KB |
Output is correct |
61 |
Correct |
126 ms |
20276 KB |
Output is correct |
62 |
Correct |
158 ms |
21252 KB |
Output is correct |
63 |
Correct |
139 ms |
20676 KB |
Output is correct |
64 |
Correct |
149 ms |
21568 KB |
Output is correct |
65 |
Correct |
111 ms |
20000 KB |
Output is correct |
66 |
Correct |
127 ms |
20408 KB |
Output is correct |
67 |
Correct |
134 ms |
21060 KB |
Output is correct |
68 |
Correct |
154 ms |
21560 KB |
Output is correct |
69 |
Correct |
637 ms |
21212 KB |
Output is correct |
70 |
Correct |
763 ms |
20716 KB |
Output is correct |
71 |
Correct |
759 ms |
21832 KB |
Output is correct |
72 |
Correct |
597 ms |
21100 KB |
Output is correct |
73 |
Correct |
542 ms |
21104 KB |
Output is correct |
74 |
Correct |
197 ms |
20676 KB |
Output is correct |
75 |
Correct |
798 ms |
21868 KB |
Output is correct |
76 |
Correct |
1089 ms |
20796 KB |
Output is correct |
77 |
Correct |
902 ms |
21512 KB |
Output is correct |
78 |
Correct |
825 ms |
21820 KB |
Output is correct |
79 |
Correct |
778 ms |
20288 KB |
Output is correct |
80 |
Correct |
1387 ms |
20924 KB |
Output is correct |
81 |
Correct |
878 ms |
21460 KB |
Output is correct |
82 |
Correct |
797 ms |
22112 KB |
Output is correct |
83 |
Execution timed out |
2052 ms |
16196 KB |
Time limit exceeded |
84 |
Halted |
0 ms |
0 KB |
- |