답안 #1095354

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1095354 2024-10-02T01:50:53 Z duyhoanho Joker (BOI20_joker) C++17
49 / 100
2000 ms 32708 KB
#include<bits/stdc++.h>
#define int long long
#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,q) cout<<qu[i].l<<" "<<qu[i].r<<" "<<qu[i].id<<"\n";
    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++)
    {
//        auto[l,r,id] = qu[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;
                //cout<<t<<" "<<i<<" "<<x[i]<<" "<<y[i]<<" "<<check(x[i],y[i])<<" "<<qu[t].id<<"\n";
                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: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.inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:78:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen("task.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8660 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 2 ms 8536 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 2 ms 8540 KB Output is correct
22 Correct 2 ms 8696 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 2 ms 8536 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 2 ms 8696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8660 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 2 ms 8536 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 2 ms 8540 KB Output is correct
22 Correct 2 ms 8696 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 2 ms 8536 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 2 ms 8696 KB Output is correct
29 Correct 43 ms 8676 KB Output is correct
30 Correct 79 ms 8876 KB Output is correct
31 Correct 89 ms 8884 KB Output is correct
32 Correct 100 ms 8792 KB Output is correct
33 Correct 88 ms 8792 KB Output is correct
34 Correct 90 ms 8796 KB Output is correct
35 Correct 89 ms 8796 KB Output is correct
36 Correct 87 ms 8796 KB Output is correct
37 Correct 88 ms 8796 KB Output is correct
38 Correct 86 ms 8796 KB Output is correct
39 Correct 84 ms 8792 KB Output is correct
40 Correct 87 ms 8792 KB Output is correct
41 Correct 86 ms 8704 KB Output is correct
42 Correct 84 ms 8796 KB Output is correct
43 Correct 88 ms 8876 KB Output is correct
44 Correct 90 ms 8796 KB Output is correct
45 Correct 92 ms 8792 KB Output is correct
46 Correct 91 ms 8892 KB Output is correct
47 Correct 86 ms 8796 KB Output is correct
48 Correct 88 ms 8796 KB Output is correct
49 Correct 88 ms 8792 KB Output is correct
50 Correct 87 ms 8796 KB Output is correct
51 Correct 88 ms 8796 KB Output is correct
52 Correct 88 ms 8888 KB Output is correct
53 Correct 87 ms 8796 KB Output is correct
54 Correct 89 ms 8792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 77 ms 27476 KB Output is correct
4 Correct 79 ms 31680 KB Output is correct
5 Correct 84 ms 32200 KB Output is correct
6 Correct 80 ms 31316 KB Output is correct
7 Correct 84 ms 31316 KB Output is correct
8 Correct 79 ms 30544 KB Output is correct
9 Correct 84 ms 30912 KB Output is correct
10 Correct 82 ms 31828 KB Output is correct
11 Correct 79 ms 31324 KB Output is correct
12 Correct 79 ms 32084 KB Output is correct
13 Correct 83 ms 30624 KB Output is correct
14 Correct 81 ms 31056 KB Output is correct
15 Correct 85 ms 31828 KB Output is correct
16 Correct 83 ms 32340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8660 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 2 ms 8536 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 2 ms 8540 KB Output is correct
22 Correct 2 ms 8696 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 2 ms 8536 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 2 ms 8696 KB Output is correct
29 Correct 77 ms 27476 KB Output is correct
30 Correct 79 ms 31680 KB Output is correct
31 Correct 84 ms 32200 KB Output is correct
32 Correct 80 ms 31316 KB Output is correct
33 Correct 84 ms 31316 KB Output is correct
34 Correct 79 ms 30544 KB Output is correct
35 Correct 84 ms 30912 KB Output is correct
36 Correct 82 ms 31828 KB Output is correct
37 Correct 79 ms 31324 KB Output is correct
38 Correct 79 ms 32084 KB Output is correct
39 Correct 83 ms 30624 KB Output is correct
40 Correct 81 ms 31056 KB Output is correct
41 Correct 85 ms 31828 KB Output is correct
42 Correct 83 ms 32340 KB Output is correct
43 Correct 938 ms 31568 KB Output is correct
44 Correct 894 ms 32332 KB Output is correct
45 Correct 936 ms 32592 KB Output is correct
46 Correct 936 ms 31832 KB Output is correct
47 Correct 963 ms 31824 KB Output is correct
48 Correct 961 ms 31316 KB Output is correct
49 Correct 991 ms 32336 KB Output is correct
50 Correct 921 ms 29996 KB Output is correct
51 Correct 978 ms 31344 KB Output is correct
52 Correct 977 ms 32708 KB Output is correct
53 Correct 998 ms 30972 KB Output is correct
54 Correct 984 ms 31676 KB Output is correct
55 Correct 958 ms 32084 KB Output is correct
56 Correct 980 ms 32596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8660 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 2 ms 8536 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 2 ms 8540 KB Output is correct
22 Correct 2 ms 8696 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 2 ms 8536 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 2 ms 8696 KB Output is correct
29 Correct 43 ms 8676 KB Output is correct
30 Correct 79 ms 8876 KB Output is correct
31 Correct 89 ms 8884 KB Output is correct
32 Correct 100 ms 8792 KB Output is correct
33 Correct 88 ms 8792 KB Output is correct
34 Correct 90 ms 8796 KB Output is correct
35 Correct 89 ms 8796 KB Output is correct
36 Correct 87 ms 8796 KB Output is correct
37 Correct 88 ms 8796 KB Output is correct
38 Correct 86 ms 8796 KB Output is correct
39 Correct 84 ms 8792 KB Output is correct
40 Correct 87 ms 8792 KB Output is correct
41 Correct 86 ms 8704 KB Output is correct
42 Correct 84 ms 8796 KB Output is correct
43 Correct 88 ms 8876 KB Output is correct
44 Correct 90 ms 8796 KB Output is correct
45 Correct 92 ms 8792 KB Output is correct
46 Correct 91 ms 8892 KB Output is correct
47 Correct 86 ms 8796 KB Output is correct
48 Correct 88 ms 8796 KB Output is correct
49 Correct 88 ms 8792 KB Output is correct
50 Correct 87 ms 8796 KB Output is correct
51 Correct 88 ms 8796 KB Output is correct
52 Correct 88 ms 8888 KB Output is correct
53 Correct 87 ms 8796 KB Output is correct
54 Correct 89 ms 8792 KB Output is correct
55 Execution timed out 2058 ms 24804 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 8536 KB Output is correct
2 Correct 1 ms 8540 KB Output is correct
3 Correct 1 ms 8540 KB Output is correct
4 Correct 1 ms 8540 KB Output is correct
5 Correct 1 ms 8540 KB Output is correct
6 Correct 1 ms 8660 KB Output is correct
7 Correct 2 ms 8540 KB Output is correct
8 Correct 2 ms 8540 KB Output is correct
9 Correct 2 ms 8540 KB Output is correct
10 Correct 2 ms 8540 KB Output is correct
11 Correct 2 ms 8540 KB Output is correct
12 Correct 2 ms 8536 KB Output is correct
13 Correct 2 ms 8536 KB Output is correct
14 Correct 2 ms 8540 KB Output is correct
15 Correct 2 ms 8540 KB Output is correct
16 Correct 2 ms 8540 KB Output is correct
17 Correct 2 ms 8540 KB Output is correct
18 Correct 2 ms 8540 KB Output is correct
19 Correct 2 ms 8540 KB Output is correct
20 Correct 2 ms 8540 KB Output is correct
21 Correct 2 ms 8540 KB Output is correct
22 Correct 2 ms 8696 KB Output is correct
23 Correct 2 ms 8540 KB Output is correct
24 Correct 2 ms 8536 KB Output is correct
25 Correct 2 ms 8540 KB Output is correct
26 Correct 2 ms 8540 KB Output is correct
27 Correct 2 ms 8540 KB Output is correct
28 Correct 2 ms 8696 KB Output is correct
29 Correct 43 ms 8676 KB Output is correct
30 Correct 79 ms 8876 KB Output is correct
31 Correct 89 ms 8884 KB Output is correct
32 Correct 100 ms 8792 KB Output is correct
33 Correct 88 ms 8792 KB Output is correct
34 Correct 90 ms 8796 KB Output is correct
35 Correct 89 ms 8796 KB Output is correct
36 Correct 87 ms 8796 KB Output is correct
37 Correct 88 ms 8796 KB Output is correct
38 Correct 86 ms 8796 KB Output is correct
39 Correct 84 ms 8792 KB Output is correct
40 Correct 87 ms 8792 KB Output is correct
41 Correct 86 ms 8704 KB Output is correct
42 Correct 84 ms 8796 KB Output is correct
43 Correct 88 ms 8876 KB Output is correct
44 Correct 90 ms 8796 KB Output is correct
45 Correct 92 ms 8792 KB Output is correct
46 Correct 91 ms 8892 KB Output is correct
47 Correct 86 ms 8796 KB Output is correct
48 Correct 88 ms 8796 KB Output is correct
49 Correct 88 ms 8792 KB Output is correct
50 Correct 87 ms 8796 KB Output is correct
51 Correct 88 ms 8796 KB Output is correct
52 Correct 88 ms 8888 KB Output is correct
53 Correct 87 ms 8796 KB Output is correct
54 Correct 89 ms 8792 KB Output is correct
55 Correct 77 ms 27476 KB Output is correct
56 Correct 79 ms 31680 KB Output is correct
57 Correct 84 ms 32200 KB Output is correct
58 Correct 80 ms 31316 KB Output is correct
59 Correct 84 ms 31316 KB Output is correct
60 Correct 79 ms 30544 KB Output is correct
61 Correct 84 ms 30912 KB Output is correct
62 Correct 82 ms 31828 KB Output is correct
63 Correct 79 ms 31324 KB Output is correct
64 Correct 79 ms 32084 KB Output is correct
65 Correct 83 ms 30624 KB Output is correct
66 Correct 81 ms 31056 KB Output is correct
67 Correct 85 ms 31828 KB Output is correct
68 Correct 83 ms 32340 KB Output is correct
69 Correct 938 ms 31568 KB Output is correct
70 Correct 894 ms 32332 KB Output is correct
71 Correct 936 ms 32592 KB Output is correct
72 Correct 936 ms 31832 KB Output is correct
73 Correct 963 ms 31824 KB Output is correct
74 Correct 961 ms 31316 KB Output is correct
75 Correct 991 ms 32336 KB Output is correct
76 Correct 921 ms 29996 KB Output is correct
77 Correct 978 ms 31344 KB Output is correct
78 Correct 977 ms 32708 KB Output is correct
79 Correct 998 ms 30972 KB Output is correct
80 Correct 984 ms 31676 KB Output is correct
81 Correct 958 ms 32084 KB Output is correct
82 Correct 980 ms 32596 KB Output is correct
83 Execution timed out 2058 ms 24804 KB Time limit exceeded
84 Halted 0 ms 0 KB -