Submission #1100829

# Submission time Handle Problem Language Result Execution time Memory
1100829 2024-10-14T18:48:57 Z vivkostov Joker (BOI20_joker) C++14
100 / 100
176 ms 12924 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
struct cell
{
    int a,b,tim;
};
int n,m,q,a[200005],b[200005],l,r,lead[200005],sw[200005],sz[200005],lamp,otg[200005],br;
stack<cell>s;
void prec()
{
    for(int i=1;i<=n;i++)
    {
        lead[i]=i;
        sz[i]=1;
        sw[i]=0;
    }
}
int get_lead(int beg)
{
    if(lead[beg]==beg)return beg;
    return get_lead(lead[beg]);
}
int get_br(int beg,int br)
{
    if(lead[beg]==beg)return br;
    return get_br(lead[beg],br+sw[beg]);
}
void add(int a,int b)
{
    br++;
    int la=get_lead(a);
    int lb=get_lead(b);
    if(la==lb)
    {
        if(get_br(a,0)%2==get_br(b,0)%2&&!lamp)lamp=br;
        return;
    }
    if(sz[la]<sz[lb])
    {
        swap(la,lb);
        swap(a,b);
    }
    lead[lb]=la;
    sz[la]+=sz[lb];
    if(get_br(a,0)%2==get_br(b,0)%2)sw[lb]++;
    cell h;
    h.a=la;
    h.b=lb;
    h.tim=br;
    s.push(h);
}
void rem(int num)
{
    for(int i=1;i<=num;i++)
    {
        if(s.top().tim==br)
        {
            int a=s.top().a;
            int b=s.top().b;
            s.pop();
            sz[a]-=sz[b];
            lead[b]=b;
        }
        br--;
        if(br<lamp)lamp=0;
    }
}
void rec(int l1,int l2,int r1,int r2)
{
    if(l1>l2)return;
    int mid=(l1+l2)/2;
    int nbr=br;
    for(int i=l1;i<mid;i++)
    {
        add(a[i],b[i]);
    }
    //cout<<br<<endl;
    int x=r2;
    int obr=br;
    while(!lamp&&x>max(mid,r1))
    {
        x--;
        add(a[x],b[x]);
    }
    int ubr=br;
    otg[mid]=x;
    //cout<<l1<<" "<<l2<<" "<<r1<<" "<<r2<<" "<<otg[mid]<<endl;
    //cout<<nbr<<" "<<obr<<" "<<br<<" "<<mid<<endl;
    rem(ubr-obr);

    add(a[mid],b[mid]);

    rec(mid+1,l2,otg[mid],r2);

    rem(mid-l1+1);

    //cout<<l1<<" "<<l2<<" "<<br<<" "<<nbr<<" "<<obr<<" "<<ubr<<" "<<otg[mid]<<endl;

    for(int i=r2-1;i>=otg[mid];i--)
    {
        add(a[i],b[i]);
    }

    rec(l1,mid-1,r1,otg[mid]);

    rem(r2-otg[mid]);
}
void read()
{
    cin>>n>>m>>q;
    prec();
    for(int i=1;i<=m;i++)
    {
        cin>>a[i]>>b[i];
    }
    rec(1,m,1,m+1);
    for(int i=1;i<=q;i++)
    {
        cin>>l>>r;
        if(otg[l]>r)cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
int main()
{
    speed();
    read();
    return 0;
}

Compilation message

Joker.cpp: In function 'void rec(int, int, int, int)':
Joker.cpp:79:9: warning: unused variable 'nbr' [-Wunused-variable]
   79 |     int nbr=br;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4600 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 2 ms 4600 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 1 ms 4600 KB Output is correct
21 Correct 1 ms 4432 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4432 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4600 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 2 ms 4600 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 1 ms 4600 KB Output is correct
21 Correct 1 ms 4432 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4432 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 2 ms 4432 KB Output is correct
30 Correct 2 ms 4432 KB Output is correct
31 Correct 2 ms 4432 KB Output is correct
32 Correct 2 ms 4572 KB Output is correct
33 Correct 2 ms 4432 KB Output is correct
34 Correct 2 ms 4432 KB Output is correct
35 Correct 2 ms 4432 KB Output is correct
36 Correct 2 ms 4432 KB Output is correct
37 Correct 2 ms 4432 KB Output is correct
38 Correct 2 ms 4600 KB Output is correct
39 Correct 2 ms 4432 KB Output is correct
40 Correct 2 ms 4432 KB Output is correct
41 Correct 2 ms 4604 KB Output is correct
42 Correct 2 ms 4432 KB Output is correct
43 Correct 2 ms 4432 KB Output is correct
44 Correct 2 ms 4608 KB Output is correct
45 Correct 2 ms 4432 KB Output is correct
46 Correct 2 ms 4432 KB Output is correct
47 Correct 2 ms 4432 KB Output is correct
48 Correct 2 ms 4432 KB Output is correct
49 Correct 2 ms 4432 KB Output is correct
50 Correct 2 ms 4432 KB Output is correct
51 Correct 2 ms 4432 KB Output is correct
52 Correct 2 ms 4592 KB Output is correct
53 Correct 2 ms 4432 KB Output is correct
54 Correct 2 ms 4532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 101 ms 6608 KB Output is correct
4 Correct 176 ms 7464 KB Output is correct
5 Correct 84 ms 7660 KB Output is correct
6 Correct 107 ms 6796 KB Output is correct
7 Correct 108 ms 6792 KB Output is correct
8 Correct 128 ms 6464 KB Output is correct
9 Correct 126 ms 6820 KB Output is correct
10 Correct 159 ms 7632 KB Output is correct
11 Correct 120 ms 6776 KB Output is correct
12 Correct 135 ms 7488 KB Output is correct
13 Correct 119 ms 5992 KB Output is correct
14 Correct 119 ms 6316 KB Output is correct
15 Correct 156 ms 6936 KB Output is correct
16 Correct 159 ms 7632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4600 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 2 ms 4600 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 1 ms 4600 KB Output is correct
21 Correct 1 ms 4432 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4432 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 101 ms 6608 KB Output is correct
30 Correct 176 ms 7464 KB Output is correct
31 Correct 84 ms 7660 KB Output is correct
32 Correct 107 ms 6796 KB Output is correct
33 Correct 108 ms 6792 KB Output is correct
34 Correct 128 ms 6464 KB Output is correct
35 Correct 126 ms 6820 KB Output is correct
36 Correct 159 ms 7632 KB Output is correct
37 Correct 120 ms 6776 KB Output is correct
38 Correct 135 ms 7488 KB Output is correct
39 Correct 119 ms 5992 KB Output is correct
40 Correct 119 ms 6316 KB Output is correct
41 Correct 156 ms 6936 KB Output is correct
42 Correct 159 ms 7632 KB Output is correct
43 Correct 99 ms 11184 KB Output is correct
44 Correct 171 ms 11596 KB Output is correct
45 Correct 140 ms 12116 KB Output is correct
46 Correct 108 ms 11216 KB Output is correct
47 Correct 112 ms 11148 KB Output is correct
48 Correct 151 ms 10660 KB Output is correct
49 Correct 167 ms 11728 KB Output is correct
50 Correct 123 ms 10824 KB Output is correct
51 Correct 133 ms 11252 KB Output is correct
52 Correct 140 ms 11864 KB Output is correct
53 Correct 137 ms 10056 KB Output is correct
54 Correct 143 ms 10932 KB Output is correct
55 Correct 161 ms 11288 KB Output is correct
56 Correct 169 ms 11984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4600 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 2 ms 4600 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 1 ms 4600 KB Output is correct
21 Correct 1 ms 4432 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4432 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 2 ms 4432 KB Output is correct
30 Correct 2 ms 4432 KB Output is correct
31 Correct 2 ms 4432 KB Output is correct
32 Correct 2 ms 4572 KB Output is correct
33 Correct 2 ms 4432 KB Output is correct
34 Correct 2 ms 4432 KB Output is correct
35 Correct 2 ms 4432 KB Output is correct
36 Correct 2 ms 4432 KB Output is correct
37 Correct 2 ms 4432 KB Output is correct
38 Correct 2 ms 4600 KB Output is correct
39 Correct 2 ms 4432 KB Output is correct
40 Correct 2 ms 4432 KB Output is correct
41 Correct 2 ms 4604 KB Output is correct
42 Correct 2 ms 4432 KB Output is correct
43 Correct 2 ms 4432 KB Output is correct
44 Correct 2 ms 4608 KB Output is correct
45 Correct 2 ms 4432 KB Output is correct
46 Correct 2 ms 4432 KB Output is correct
47 Correct 2 ms 4432 KB Output is correct
48 Correct 2 ms 4432 KB Output is correct
49 Correct 2 ms 4432 KB Output is correct
50 Correct 2 ms 4432 KB Output is correct
51 Correct 2 ms 4432 KB Output is correct
52 Correct 2 ms 4592 KB Output is correct
53 Correct 2 ms 4432 KB Output is correct
54 Correct 2 ms 4532 KB Output is correct
55 Correct 76 ms 6232 KB Output is correct
56 Correct 140 ms 10020 KB Output is correct
57 Correct 61 ms 9440 KB Output is correct
58 Correct 90 ms 8592 KB Output is correct
59 Correct 117 ms 8352 KB Output is correct
60 Correct 144 ms 9288 KB Output is correct
61 Correct 110 ms 8460 KB Output is correct
62 Correct 121 ms 9400 KB Output is correct
63 Correct 91 ms 7760 KB Output is correct
64 Correct 131 ms 8660 KB Output is correct
65 Correct 141 ms 9412 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4432 KB Output is correct
2 Correct 1 ms 4432 KB Output is correct
3 Correct 1 ms 4600 KB Output is correct
4 Correct 1 ms 4432 KB Output is correct
5 Correct 1 ms 4432 KB Output is correct
6 Correct 1 ms 4432 KB Output is correct
7 Correct 1 ms 4432 KB Output is correct
8 Correct 1 ms 4432 KB Output is correct
9 Correct 1 ms 4432 KB Output is correct
10 Correct 1 ms 4432 KB Output is correct
11 Correct 1 ms 4432 KB Output is correct
12 Correct 1 ms 4432 KB Output is correct
13 Correct 1 ms 4432 KB Output is correct
14 Correct 1 ms 4432 KB Output is correct
15 Correct 1 ms 4432 KB Output is correct
16 Correct 1 ms 4432 KB Output is correct
17 Correct 1 ms 4432 KB Output is correct
18 Correct 2 ms 4600 KB Output is correct
19 Correct 1 ms 4432 KB Output is correct
20 Correct 1 ms 4600 KB Output is correct
21 Correct 1 ms 4432 KB Output is correct
22 Correct 1 ms 4432 KB Output is correct
23 Correct 1 ms 4432 KB Output is correct
24 Correct 1 ms 4432 KB Output is correct
25 Correct 1 ms 4432 KB Output is correct
26 Correct 1 ms 4432 KB Output is correct
27 Correct 1 ms 4432 KB Output is correct
28 Correct 1 ms 4432 KB Output is correct
29 Correct 2 ms 4432 KB Output is correct
30 Correct 2 ms 4432 KB Output is correct
31 Correct 2 ms 4432 KB Output is correct
32 Correct 2 ms 4572 KB Output is correct
33 Correct 2 ms 4432 KB Output is correct
34 Correct 2 ms 4432 KB Output is correct
35 Correct 2 ms 4432 KB Output is correct
36 Correct 2 ms 4432 KB Output is correct
37 Correct 2 ms 4432 KB Output is correct
38 Correct 2 ms 4600 KB Output is correct
39 Correct 2 ms 4432 KB Output is correct
40 Correct 2 ms 4432 KB Output is correct
41 Correct 2 ms 4604 KB Output is correct
42 Correct 2 ms 4432 KB Output is correct
43 Correct 2 ms 4432 KB Output is correct
44 Correct 2 ms 4608 KB Output is correct
45 Correct 2 ms 4432 KB Output is correct
46 Correct 2 ms 4432 KB Output is correct
47 Correct 2 ms 4432 KB Output is correct
48 Correct 2 ms 4432 KB Output is correct
49 Correct 2 ms 4432 KB Output is correct
50 Correct 2 ms 4432 KB Output is correct
51 Correct 2 ms 4432 KB Output is correct
52 Correct 2 ms 4592 KB Output is correct
53 Correct 2 ms 4432 KB Output is correct
54 Correct 2 ms 4532 KB Output is correct
55 Correct 101 ms 6608 KB Output is correct
56 Correct 176 ms 7464 KB Output is correct
57 Correct 84 ms 7660 KB Output is correct
58 Correct 107 ms 6796 KB Output is correct
59 Correct 108 ms 6792 KB Output is correct
60 Correct 128 ms 6464 KB Output is correct
61 Correct 126 ms 6820 KB Output is correct
62 Correct 159 ms 7632 KB Output is correct
63 Correct 120 ms 6776 KB Output is correct
64 Correct 135 ms 7488 KB Output is correct
65 Correct 119 ms 5992 KB Output is correct
66 Correct 119 ms 6316 KB Output is correct
67 Correct 156 ms 6936 KB Output is correct
68 Correct 159 ms 7632 KB Output is correct
69 Correct 99 ms 11184 KB Output is correct
70 Correct 171 ms 11596 KB Output is correct
71 Correct 140 ms 12116 KB Output is correct
72 Correct 108 ms 11216 KB Output is correct
73 Correct 112 ms 11148 KB Output is correct
74 Correct 151 ms 10660 KB Output is correct
75 Correct 167 ms 11728 KB Output is correct
76 Correct 123 ms 10824 KB Output is correct
77 Correct 133 ms 11252 KB Output is correct
78 Correct 140 ms 11864 KB Output is correct
79 Correct 137 ms 10056 KB Output is correct
80 Correct 143 ms 10932 KB Output is correct
81 Correct 161 ms 11288 KB Output is correct
82 Correct 169 ms 11984 KB Output is correct
83 Correct 76 ms 6232 KB Output is correct
84 Correct 140 ms 10020 KB Output is correct
85 Correct 61 ms 9440 KB Output is correct
86 Correct 90 ms 8592 KB Output is correct
87 Correct 117 ms 8352 KB Output is correct
88 Correct 144 ms 9288 KB Output is correct
89 Correct 110 ms 8460 KB Output is correct
90 Correct 121 ms 9400 KB Output is correct
91 Correct 91 ms 7760 KB Output is correct
92 Correct 131 ms 8660 KB Output is correct
93 Correct 141 ms 9412 KB Output is correct
94 Correct 111 ms 11596 KB Output is correct
95 Correct 137 ms 12752 KB Output is correct
96 Correct 91 ms 12872 KB Output is correct
97 Correct 118 ms 11892 KB Output is correct
98 Correct 119 ms 11608 KB Output is correct
99 Correct 135 ms 11444 KB Output is correct
100 Correct 153 ms 12924 KB Output is correct
101 Correct 130 ms 11592 KB Output is correct
102 Correct 144 ms 12048 KB Output is correct
103 Correct 153 ms 12748 KB Output is correct
104 Correct 127 ms 11216 KB Output is correct
105 Correct 159 ms 11988 KB Output is correct
106 Correct 174 ms 12876 KB Output is correct
107 Correct 82 ms 12884 KB Output is correct
108 Correct 106 ms 11600 KB Output is correct
109 Correct 103 ms 11444 KB Output is correct
110 Correct 112 ms 11468 KB Output is correct
111 Correct 109 ms 11592 KB Output is correct
112 Correct 102 ms 11476 KB Output is correct
113 Correct 116 ms 11472 KB Output is correct
114 Correct 103 ms 11588 KB Output is correct
115 Correct 103 ms 11472 KB Output is correct
116 Correct 104 ms 11472 KB Output is correct