Submission #1095356

# Submission time Handle Problem Language Result Execution time Memory
1095356 2024-10-02T01:52:19 Z duyhoanho Joker (BOI20_joker) C++17
49 / 100
2000 ms 14676 KB
#include<bits/stdc++.h>
#define forinc(i,a,b) for(int i=a;i<=b;i++)
#define fi first
#define se second
#define pii pair<int,int>
#define pb push_back
using namespace std;
const int N = 2e5+10, S = 448;
int n,m,q,p[N],sz[N],lz[N],x[N],y[N];
int ans[N];
bool ok;
stack<pii> sk,pr,si,la;
struct node
{
    int l,r,id;
} qu[N];
bool cmp(node a,node b)
{
    if(a.l / S != b.l / S) return a.l < b.l;
    return a.r > b.r;
}
int pa(int v,int &c)
{
    c ^= lz[v];
    if(p[v] == v) return v;
    return pa(p[v],c);
}
void join(int a,int b)
{
    int ca = 0;
    int cb = 0;
    a = pa(a,ca);
    b = pa(b,cb);
    if(sz[a] < sz[b]) swap(a,b);
    sk.push({a,b});
    si.push({sz[a],sz[b]});
    pr.push({p[a],p[b]});
    la.push({lz[a],lz[b]});
    if(a != b)
    {
        sz[a] += sz[b];
        p[b] = a;
        if(ca == cb) lz[b] = 1;
    }
}
void rollback()
{
    auto[a,b] = sk.top(); sk.pop();
    auto[sza,szb] = si.top();si.pop();
    sz[a] = sza;
    sz[b] = szb;
    auto[pa,pb] = pr.top(); pr.pop();
    p[a] = pa ;
    p[b] = pb;
    auto[lza,lzb] = la.top(); la.pop();
    lz[a] = lza ;
    lz[b] = lzb;
}
int get(int i)
{
    return (i - 1) / S + 1;
}
bool check(int a,int b)
{
    int ca = 0;
    int cb = 0;
    a = pa(a,ca);
    b = pa(b,cb);
    if(a == b && ca == cb) return true;
    return false;
}
int32_t main()
{
    if(fopen("task.inp","r"))
    {
        freopen("task.inp","r",stdin);
        freopen("task.out","w",stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>m>>q;
    for(int i=1; i<=m; i++) cin>>x[i]>>y[i];
    forinc(i,1,q)
    {
        int l,r;
        cin>>l>>r;
        qu[i] = {l,r,i};
    }
    sort(qu+1,qu+q+1,cmp);
    forinc(i,1,n)
    {
        sz[i] = 1;
        lz[i] = 0;
        p[i] = i;
    }
    for(int i=m; i>qu[1].r; i--)
    {
        if(check(x[i],y[i])) ok = 1;
          ans[qu[1].id] |= ok;
        join(x[i],y[i]);
    }
    for(int i=1; i<qu[1].l; i++)
    {
        if(check(x[i], y[i])) ans[qu[1].id] = 1;
        join(x[i],y[i]);
    }
    for(int t=2; t<=q; t++)
    {
        if(get(qu[t].l) == get(qu[t-1].l))
        {
            for(int i=1; i<qu[t-1].l; i++) rollback();
            ans[qu[t].id] |= ok;
            for(int i=qu[t-1].r ; i > qu[t].r ; i--)
            {
                if(check(x[i],y[i])) ok = 1;
                ans[qu[t].id] |= ok;
                join(x[i],y[i]);
            }
            for(int i=1; i<qu[t].l; i++)
            {
                if(check(x[i],y[i])) ans[qu[t].id] = 1;
                join(x[i],y[i]);
            }
        }
        else
        {
            ok = 0;
            forinc(i,1,n)
            {
                sz[i] = 1;
                lz[i] = 0;
                p[i] = i;
            }
            while(sk.size())
            {
                sk.pop();
                la.pop();
                si.pop();
                pr.pop();
            }
            for(int i=m; i>qu[t].r; i--)
            {
                if(check(x[i],y[i])) ok = 1;
                ans[qu[t].id] |= ok;
                join(x[i],y[i]);
            }
            for(int i=1; i<qu[t].l; i++)
            {
                if(check(x[i], y[i])) ans[qu[t].id] = 1;
                join(x[i],y[i]);
            }
        }
    }
    forinc(i,1,q) cout<<(ans[i] == 1 ? "YES\n" : "NO\n");
}

Compilation message

Joker.cpp: In function 'int32_t main()':
Joker.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen("task.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:77:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         freopen("task.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 2 ms 4568 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 2 ms 4440 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 2 ms 4568 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 2 ms 4440 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 38 ms 4444 KB Output is correct
30 Correct 70 ms 4444 KB Output is correct
31 Correct 80 ms 4440 KB Output is correct
32 Correct 79 ms 4640 KB Output is correct
33 Correct 82 ms 4636 KB Output is correct
34 Correct 80 ms 4440 KB Output is correct
35 Correct 84 ms 4648 KB Output is correct
36 Correct 80 ms 4640 KB Output is correct
37 Correct 78 ms 4444 KB Output is correct
38 Correct 79 ms 4440 KB Output is correct
39 Correct 77 ms 4444 KB Output is correct
40 Correct 78 ms 4440 KB Output is correct
41 Correct 80 ms 4444 KB Output is correct
42 Correct 77 ms 4656 KB Output is correct
43 Correct 80 ms 4636 KB Output is correct
44 Correct 83 ms 4444 KB Output is correct
45 Correct 87 ms 4440 KB Output is correct
46 Correct 84 ms 4444 KB Output is correct
47 Correct 78 ms 4444 KB Output is correct
48 Correct 81 ms 4440 KB Output is correct
49 Correct 79 ms 4444 KB Output is correct
50 Correct 80 ms 4636 KB Output is correct
51 Correct 82 ms 4444 KB Output is correct
52 Correct 81 ms 4440 KB Output is correct
53 Correct 80 ms 4444 KB Output is correct
54 Correct 81 ms 4440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 70 ms 14196 KB Output is correct
4 Correct 73 ms 14456 KB Output is correct
5 Correct 72 ms 14552 KB Output is correct
6 Correct 73 ms 14200 KB Output is correct
7 Correct 72 ms 14160 KB Output is correct
8 Correct 70 ms 14164 KB Output is correct
9 Correct 70 ms 14292 KB Output is correct
10 Correct 75 ms 14672 KB Output is correct
11 Correct 71 ms 14160 KB Output is correct
12 Correct 72 ms 14420 KB Output is correct
13 Correct 69 ms 13936 KB Output is correct
14 Correct 71 ms 14164 KB Output is correct
15 Correct 73 ms 14288 KB Output is correct
16 Correct 80 ms 14536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 2 ms 4568 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 2 ms 4440 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 70 ms 14196 KB Output is correct
30 Correct 73 ms 14456 KB Output is correct
31 Correct 72 ms 14552 KB Output is correct
32 Correct 73 ms 14200 KB Output is correct
33 Correct 72 ms 14160 KB Output is correct
34 Correct 70 ms 14164 KB Output is correct
35 Correct 70 ms 14292 KB Output is correct
36 Correct 75 ms 14672 KB Output is correct
37 Correct 71 ms 14160 KB Output is correct
38 Correct 72 ms 14420 KB Output is correct
39 Correct 69 ms 13936 KB Output is correct
40 Correct 71 ms 14164 KB Output is correct
41 Correct 73 ms 14288 KB Output is correct
42 Correct 80 ms 14536 KB Output is correct
43 Correct 813 ms 14160 KB Output is correct
44 Correct 837 ms 14448 KB Output is correct
45 Correct 816 ms 14452 KB Output is correct
46 Correct 834 ms 14164 KB Output is correct
47 Correct 850 ms 14196 KB Output is correct
48 Correct 864 ms 14420 KB Output is correct
49 Correct 874 ms 14672 KB Output is correct
50 Correct 828 ms 14172 KB Output is correct
51 Correct 833 ms 14352 KB Output is correct
52 Correct 825 ms 14676 KB Output is correct
53 Correct 838 ms 13908 KB Output is correct
54 Correct 867 ms 14164 KB Output is correct
55 Correct 870 ms 14420 KB Output is correct
56 Correct 897 ms 14468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 2 ms 4568 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 2 ms 4440 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 38 ms 4444 KB Output is correct
30 Correct 70 ms 4444 KB Output is correct
31 Correct 80 ms 4440 KB Output is correct
32 Correct 79 ms 4640 KB Output is correct
33 Correct 82 ms 4636 KB Output is correct
34 Correct 80 ms 4440 KB Output is correct
35 Correct 84 ms 4648 KB Output is correct
36 Correct 80 ms 4640 KB Output is correct
37 Correct 78 ms 4444 KB Output is correct
38 Correct 79 ms 4440 KB Output is correct
39 Correct 77 ms 4444 KB Output is correct
40 Correct 78 ms 4440 KB Output is correct
41 Correct 80 ms 4444 KB Output is correct
42 Correct 77 ms 4656 KB Output is correct
43 Correct 80 ms 4636 KB Output is correct
44 Correct 83 ms 4444 KB Output is correct
45 Correct 87 ms 4440 KB Output is correct
46 Correct 84 ms 4444 KB Output is correct
47 Correct 78 ms 4444 KB Output is correct
48 Correct 81 ms 4440 KB Output is correct
49 Correct 79 ms 4444 KB Output is correct
50 Correct 80 ms 4636 KB Output is correct
51 Correct 82 ms 4444 KB Output is correct
52 Correct 81 ms 4440 KB Output is correct
53 Correct 80 ms 4444 KB Output is correct
54 Correct 81 ms 4440 KB Output is correct
55 Execution timed out 2039 ms 11344 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 0 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Correct 1 ms 4440 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 2 ms 4444 KB Output is correct
12 Correct 2 ms 4568 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 2 ms 4444 KB Output is correct
15 Correct 1 ms 4444 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 2 ms 4440 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4444 KB Output is correct
23 Correct 1 ms 4444 KB Output is correct
24 Correct 1 ms 4444 KB Output is correct
25 Correct 1 ms 4444 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 1 ms 4444 KB Output is correct
28 Correct 1 ms 4444 KB Output is correct
29 Correct 38 ms 4444 KB Output is correct
30 Correct 70 ms 4444 KB Output is correct
31 Correct 80 ms 4440 KB Output is correct
32 Correct 79 ms 4640 KB Output is correct
33 Correct 82 ms 4636 KB Output is correct
34 Correct 80 ms 4440 KB Output is correct
35 Correct 84 ms 4648 KB Output is correct
36 Correct 80 ms 4640 KB Output is correct
37 Correct 78 ms 4444 KB Output is correct
38 Correct 79 ms 4440 KB Output is correct
39 Correct 77 ms 4444 KB Output is correct
40 Correct 78 ms 4440 KB Output is correct
41 Correct 80 ms 4444 KB Output is correct
42 Correct 77 ms 4656 KB Output is correct
43 Correct 80 ms 4636 KB Output is correct
44 Correct 83 ms 4444 KB Output is correct
45 Correct 87 ms 4440 KB Output is correct
46 Correct 84 ms 4444 KB Output is correct
47 Correct 78 ms 4444 KB Output is correct
48 Correct 81 ms 4440 KB Output is correct
49 Correct 79 ms 4444 KB Output is correct
50 Correct 80 ms 4636 KB Output is correct
51 Correct 82 ms 4444 KB Output is correct
52 Correct 81 ms 4440 KB Output is correct
53 Correct 80 ms 4444 KB Output is correct
54 Correct 81 ms 4440 KB Output is correct
55 Correct 70 ms 14196 KB Output is correct
56 Correct 73 ms 14456 KB Output is correct
57 Correct 72 ms 14552 KB Output is correct
58 Correct 73 ms 14200 KB Output is correct
59 Correct 72 ms 14160 KB Output is correct
60 Correct 70 ms 14164 KB Output is correct
61 Correct 70 ms 14292 KB Output is correct
62 Correct 75 ms 14672 KB Output is correct
63 Correct 71 ms 14160 KB Output is correct
64 Correct 72 ms 14420 KB Output is correct
65 Correct 69 ms 13936 KB Output is correct
66 Correct 71 ms 14164 KB Output is correct
67 Correct 73 ms 14288 KB Output is correct
68 Correct 80 ms 14536 KB Output is correct
69 Correct 813 ms 14160 KB Output is correct
70 Correct 837 ms 14448 KB Output is correct
71 Correct 816 ms 14452 KB Output is correct
72 Correct 834 ms 14164 KB Output is correct
73 Correct 850 ms 14196 KB Output is correct
74 Correct 864 ms 14420 KB Output is correct
75 Correct 874 ms 14672 KB Output is correct
76 Correct 828 ms 14172 KB Output is correct
77 Correct 833 ms 14352 KB Output is correct
78 Correct 825 ms 14676 KB Output is correct
79 Correct 838 ms 13908 KB Output is correct
80 Correct 867 ms 14164 KB Output is correct
81 Correct 870 ms 14420 KB Output is correct
82 Correct 897 ms 14468 KB Output is correct
83 Execution timed out 2039 ms 11344 KB Time limit exceeded
84 Halted 0 ms 0 KB -