# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1054303 |
2024-08-12T08:32:59 Z |
allin27x |
Joker (BOI20_joker) |
C++17 |
|
2000 ms |
21440 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;
#define forn(i,n) for(int i=0; i<n; i++)
#define readv(a,n) vector<int>a(n);forn(i,n)cin>>a[i];
#define readvv(a,n,m) vector<vector<int>> a(n,vector<int>(m));forn(i,n)forn(j,m)cin>>a[i][j];
#define all(a) a.begin(), a.end()
#define _max(x,y) x = max(x,y)
#define _min(x,y) x = min(x,y)
// #define f first
// #define s second
const int N = 2e5+4;
const int SQRT = 460;
int ans[N];
struct qr{
int l, r, i;
bool operator<(qr b){
return make_pair(l/SQRT, r) < make_pair(b.l/SQRT,b.r);
}
};
vector<qr> queries[SQRT];
int edges[N][2];
struct DSU{
vector<int> par;
vector<int> size;
stack<int> rb;
int cmp;
DSU(int n){
par.resize(n); for(int i=0; i<n; ++i) par[i]=i;
size.resize(n,1); cmp = n;
}
int get(int p){
return par[p]==p? p: get(par[p]);
}
void unite(int a, int b){
a = get(a); b = get(b);
if (a==b){
rb.push(-1);
return;
}
cmp--;
if (size[a] > size[b]) swap(a,b);
rb.push(a);
size[b]+=size[a];
par[a] = b;
}
int conn(int a, int b){
return get(a) == get(b);
}
void rollback(){
int f = rb.top();
rb.pop();
if (f==-1) return;
cmp++;
size[par[f]] -= size[f];
par[f] = f;
}
};
void solve(){
int n,m,q; cin>>n>>m>>q;
for (int i=0; i<m; i++){
int a,b; cin>>a>>b; a--;b--; edges[i][0]=a; edges[i][1] = b;
}
for (int i=0; i<q; i++){
int l,r; cin>>l>>r; l--; r--;
qr p; p.l=l;p.r=r;p.i=i;
queries[l/SQRT].push_back(p);
}
for (int i=0; i<SQRT; i++) sort(queries[i].begin(), queries[i].end());
DSU dsu(2*n);
int fM =0;
for (int t=0; t<SQRT; t++){
int fm = 0;
int i = m-1; int j = queries[t].size()-1;
while (i>=0){
if (j<0){
dsu.unite(edges[i][0] + n, edges[i][1]);
dsu.unite(edges[i][0], edges[i][1] + n);
i--;
continue;
}
qr p = queries[t][j];
while (p.r == i){
if (j<0) break;
int f = 0;
for (int ll=t*SQRT; ll<p.l; ll++){
if (dsu.conn(edges[ll][0],edges[ll][1])) f++;
dsu.unite(edges[ll][0]+n, edges[ll][1]);
dsu.unite(edges[ll][0], edges[ll][1]+n);
}
for (int ll=t*SQRT; ll<p.l; ll++){
dsu.rollback(); dsu.rollback();
}
if (f || fm || fM) ans[p.i] = 1;
j--;
if (j<0) break;
p = queries[t][j];
}
fm += dsu.conn(edges[i][0], edges[i][1]);
dsu.unite(edges[i][0] + n, edges[i][1]);
dsu.unite(edges[i][0], edges[i][1] + n);
i--;
}
for (int ll=0; ll<2*m; ll++) dsu.rollback();
for (int ll=SQRT*t; ll<min(m, SQRT*t + SQRT); ll++){
fM += dsu.conn(edges[ll][0], edges[ll][1]);
dsu.unite(edges[ll][0] + n, edges[ll][1]);
dsu.unite(edges[ll][0], edges[ll][1] + n);
}
}
for (int i=0;i<q; i++) cout<<(ans[i]?"YES\n":"NO\n");
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t=1;
while(t--){
solve();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2536 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
2 ms |
2396 KB |
Output is correct |
21 |
Correct |
2 ms |
2396 KB |
Output is correct |
22 |
Correct |
2 ms |
2532 KB |
Output is correct |
23 |
Correct |
3 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
2 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2536 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
2 ms |
2396 KB |
Output is correct |
21 |
Correct |
2 ms |
2396 KB |
Output is correct |
22 |
Correct |
2 ms |
2532 KB |
Output is correct |
23 |
Correct |
3 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
2 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
11 ms |
2652 KB |
Output is correct |
30 |
Correct |
16 ms |
2708 KB |
Output is correct |
31 |
Correct |
18 ms |
2728 KB |
Output is correct |
32 |
Correct |
16 ms |
2652 KB |
Output is correct |
33 |
Correct |
16 ms |
2696 KB |
Output is correct |
34 |
Correct |
18 ms |
2648 KB |
Output is correct |
35 |
Correct |
18 ms |
2648 KB |
Output is correct |
36 |
Correct |
27 ms |
2648 KB |
Output is correct |
37 |
Correct |
21 ms |
2704 KB |
Output is correct |
38 |
Correct |
14 ms |
2652 KB |
Output is correct |
39 |
Correct |
29 ms |
2736 KB |
Output is correct |
40 |
Correct |
34 ms |
2652 KB |
Output is correct |
41 |
Correct |
18 ms |
2652 KB |
Output is correct |
42 |
Correct |
17 ms |
2652 KB |
Output is correct |
43 |
Correct |
34 ms |
2668 KB |
Output is correct |
44 |
Correct |
17 ms |
2712 KB |
Output is correct |
45 |
Correct |
18 ms |
2648 KB |
Output is correct |
46 |
Correct |
17 ms |
2740 KB |
Output is correct |
47 |
Correct |
15 ms |
2648 KB |
Output is correct |
48 |
Correct |
15 ms |
2720 KB |
Output is correct |
49 |
Correct |
17 ms |
2652 KB |
Output is correct |
50 |
Correct |
15 ms |
2716 KB |
Output is correct |
51 |
Correct |
18 ms |
2652 KB |
Output is correct |
52 |
Correct |
18 ms |
2712 KB |
Output is correct |
53 |
Correct |
22 ms |
2724 KB |
Output is correct |
54 |
Correct |
19 ms |
2716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1587 ms |
21440 KB |
Output is correct |
4 |
Execution timed out |
2054 ms |
21432 KB |
Time limit exceeded |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2536 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
2 ms |
2396 KB |
Output is correct |
21 |
Correct |
2 ms |
2396 KB |
Output is correct |
22 |
Correct |
2 ms |
2532 KB |
Output is correct |
23 |
Correct |
3 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
2 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1587 ms |
21440 KB |
Output is correct |
30 |
Execution timed out |
2054 ms |
21432 KB |
Time limit exceeded |
31 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2536 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
2 ms |
2396 KB |
Output is correct |
21 |
Correct |
2 ms |
2396 KB |
Output is correct |
22 |
Correct |
2 ms |
2532 KB |
Output is correct |
23 |
Correct |
3 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
2 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
11 ms |
2652 KB |
Output is correct |
30 |
Correct |
16 ms |
2708 KB |
Output is correct |
31 |
Correct |
18 ms |
2728 KB |
Output is correct |
32 |
Correct |
16 ms |
2652 KB |
Output is correct |
33 |
Correct |
16 ms |
2696 KB |
Output is correct |
34 |
Correct |
18 ms |
2648 KB |
Output is correct |
35 |
Correct |
18 ms |
2648 KB |
Output is correct |
36 |
Correct |
27 ms |
2648 KB |
Output is correct |
37 |
Correct |
21 ms |
2704 KB |
Output is correct |
38 |
Correct |
14 ms |
2652 KB |
Output is correct |
39 |
Correct |
29 ms |
2736 KB |
Output is correct |
40 |
Correct |
34 ms |
2652 KB |
Output is correct |
41 |
Correct |
18 ms |
2652 KB |
Output is correct |
42 |
Correct |
17 ms |
2652 KB |
Output is correct |
43 |
Correct |
34 ms |
2668 KB |
Output is correct |
44 |
Correct |
17 ms |
2712 KB |
Output is correct |
45 |
Correct |
18 ms |
2648 KB |
Output is correct |
46 |
Correct |
17 ms |
2740 KB |
Output is correct |
47 |
Correct |
15 ms |
2648 KB |
Output is correct |
48 |
Correct |
15 ms |
2720 KB |
Output is correct |
49 |
Correct |
17 ms |
2652 KB |
Output is correct |
50 |
Correct |
15 ms |
2716 KB |
Output is correct |
51 |
Correct |
18 ms |
2652 KB |
Output is correct |
52 |
Correct |
18 ms |
2712 KB |
Output is correct |
53 |
Correct |
22 ms |
2724 KB |
Output is correct |
54 |
Correct |
19 ms |
2716 KB |
Output is correct |
55 |
Correct |
1671 ms |
14316 KB |
Output is correct |
56 |
Execution timed out |
2087 ms |
19672 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
0 ms |
2396 KB |
Output is correct |
4 |
Correct |
0 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
0 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
2 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2396 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
2 ms |
2396 KB |
Output is correct |
17 |
Correct |
2 ms |
2536 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
2 ms |
2396 KB |
Output is correct |
21 |
Correct |
2 ms |
2396 KB |
Output is correct |
22 |
Correct |
2 ms |
2532 KB |
Output is correct |
23 |
Correct |
3 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
2 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
11 ms |
2652 KB |
Output is correct |
30 |
Correct |
16 ms |
2708 KB |
Output is correct |
31 |
Correct |
18 ms |
2728 KB |
Output is correct |
32 |
Correct |
16 ms |
2652 KB |
Output is correct |
33 |
Correct |
16 ms |
2696 KB |
Output is correct |
34 |
Correct |
18 ms |
2648 KB |
Output is correct |
35 |
Correct |
18 ms |
2648 KB |
Output is correct |
36 |
Correct |
27 ms |
2648 KB |
Output is correct |
37 |
Correct |
21 ms |
2704 KB |
Output is correct |
38 |
Correct |
14 ms |
2652 KB |
Output is correct |
39 |
Correct |
29 ms |
2736 KB |
Output is correct |
40 |
Correct |
34 ms |
2652 KB |
Output is correct |
41 |
Correct |
18 ms |
2652 KB |
Output is correct |
42 |
Correct |
17 ms |
2652 KB |
Output is correct |
43 |
Correct |
34 ms |
2668 KB |
Output is correct |
44 |
Correct |
17 ms |
2712 KB |
Output is correct |
45 |
Correct |
18 ms |
2648 KB |
Output is correct |
46 |
Correct |
17 ms |
2740 KB |
Output is correct |
47 |
Correct |
15 ms |
2648 KB |
Output is correct |
48 |
Correct |
15 ms |
2720 KB |
Output is correct |
49 |
Correct |
17 ms |
2652 KB |
Output is correct |
50 |
Correct |
15 ms |
2716 KB |
Output is correct |
51 |
Correct |
18 ms |
2652 KB |
Output is correct |
52 |
Correct |
18 ms |
2712 KB |
Output is correct |
53 |
Correct |
22 ms |
2724 KB |
Output is correct |
54 |
Correct |
19 ms |
2716 KB |
Output is correct |
55 |
Correct |
1587 ms |
21440 KB |
Output is correct |
56 |
Execution timed out |
2054 ms |
21432 KB |
Time limit exceeded |
57 |
Halted |
0 ms |
0 KB |
- |