Submission #1095610

# Submission time Handle Problem Language Result Execution time Memory
1095610 2024-10-02T17:22:58 Z simona1230 Joker (BOI20_joker) C++17
100 / 100
361 ms 15852 KB
#include <bits/stdc++.h>

using namespace std;

int n,m,k;
pair<int,int> e[200001],q[200001];

void read()
{
    cin>>n>>m>>k;
    for(int i=1;i<=m;i++)
    {
        int x,y;
        cin>>x>>y;
        e[i]={x,y};
    }

    for(int i=1;i<=k;i++)
    {
        int l,r;
        cin>>l>>r;
        q[i]={l,r};
    }
}

struct event
{
    int x,y;
    pair<int,int> p;
    event(){}
    event(int _x,int _y,pair<int,int> _p)
    {
        x=_x;
        y=_y;
        p=_p;
    }
};

pair<int,int> p[200001];
stack<event> s;
int sz[200001];

void rollback()
{
    event t=s.top();
    s.pop();

    p[t.x]=t.p;
    sz[t.y]-=sz[t.x];
}

pair<int,int> parent(int x)
{
    if(x==p[x].first)return p[x];
    pair<int,int> curr=parent(p[x].first);
    curr.second+=p[x].second;
    return curr;
}

void unite(int x,int y,int&cnt, bool&cyc)
{
    //cout<<x<<" "<<y<<endl;
    pair<int,int> px=parent(x);
    pair<int,int> py=parent(y);

    x=px.first;
    y=py.first;

    if(x!=y)
    {
        if(sz[x]>sz[y])swap(x,y);
        s.push({x,y,p[x]});
        p[x]={y,px.second+py.second+1};
        sz[y]+=sz[x];
        cnt++;
    }
    else
    {
        if(px.second%2==py.second%2)
        {
            //cout<<"hje"<<endl;
            cyc=1;
        }
    }
}

int c[200001];

void rec(int l,int r,int optl,int optr)
{
    if(l>r)return;
    //cout<<l<<" "<<r<<" "<<optl<<" "<<optr<<endl;
    if(optl==optr)
    {
        for(int i=l;i<=r;i++)
            c[i]=optr;
        return;
    }

    int mid=(l+r)/2;

    int cnt1=0;
    bool ans=0;
    for(int i=l;i<mid;i++)
        unite(e[i].first,e[i].second,cnt1,ans);

    int j=optr;
    int cnt2=0;
    if(ans)j--;
    while(!ans&&j>=optl)
    {
        if(j!=m+1)
            unite(e[j].first,e[j].second,cnt2,ans);
        j--;
    }
    j++;

    while(cnt2)
    {
        cnt2--;
        rollback();
    }

    while(cnt1)
    {
        cnt1--;
        rollback();
    }

    c[mid]=j;
    //cout<<"! "<<mid<<" "<<j<<endl;

    ans=0;
    int cnt3=0;
    for(int i=j+1;i<=min(m,optr);i++)
        unite(e[i].first,e[i].second,cnt3,ans);
    if(ans)rec(l,mid-1,j,j);
    else rec(l,mid-1,optl,j);

    while(cnt3)
    {
        cnt3--;
        rollback();
    }

    ans=0;
    int cnt4=0;
    for(int i=l;i<=mid;i++)
        unite(e[i].first,e[i].second,cnt4,ans);
    if(ans)rec(mid+1,r,optr,optr);
    else rec(mid+1,r,j,optr);

    while(cnt4)
    {
        cnt4--;
        rollback();
    }
}

void solve()
{
    for(int i=1;i<=k;i++)
    {
        if(q[i].second<c[q[i].first])cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	read();
	for(int i=1;i<=n;i++)
        p[i]={i,0},sz[i]=1;
    rec(1,m,1,m+1);
	solve();

	return 0;
}
/*
6 8 2
1 3
1 5
1 6
2 5
2 6
3 4
3 5
5 6

1 8
8 8
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 448 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 448 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 3 ms 348 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 3 ms 348 KB Output is correct
34 Correct 4 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 3 ms 344 KB Output is correct
37 Correct 4 ms 600 KB Output is correct
38 Correct 3 ms 604 KB Output is correct
39 Correct 3 ms 532 KB Output is correct
40 Correct 3 ms 348 KB Output is correct
41 Correct 3 ms 348 KB Output is correct
42 Correct 3 ms 348 KB Output is correct
43 Correct 3 ms 348 KB Output is correct
44 Correct 3 ms 348 KB Output is correct
45 Correct 3 ms 604 KB Output is correct
46 Correct 4 ms 620 KB Output is correct
47 Correct 3 ms 348 KB Output is correct
48 Correct 3 ms 348 KB Output is correct
49 Correct 4 ms 604 KB Output is correct
50 Correct 4 ms 612 KB Output is correct
51 Correct 5 ms 348 KB Output is correct
52 Correct 5 ms 488 KB Output is correct
53 Correct 3 ms 604 KB Output is correct
54 Correct 4 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 295 ms 7684 KB Output is correct
4 Correct 322 ms 10560 KB Output is correct
5 Correct 259 ms 9876 KB Output is correct
6 Correct 275 ms 7220 KB Output is correct
7 Correct 269 ms 7792 KB Output is correct
8 Correct 281 ms 8396 KB Output is correct
9 Correct 294 ms 9952 KB Output is correct
10 Correct 322 ms 11808 KB Output is correct
11 Correct 307 ms 11496 KB Output is correct
12 Correct 303 ms 13360 KB Output is correct
13 Correct 286 ms 9552 KB Output is correct
14 Correct 283 ms 10576 KB Output is correct
15 Correct 338 ms 12580 KB Output is correct
16 Correct 328 ms 13604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 448 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 295 ms 7684 KB Output is correct
30 Correct 322 ms 10560 KB Output is correct
31 Correct 259 ms 9876 KB Output is correct
32 Correct 275 ms 7220 KB Output is correct
33 Correct 269 ms 7792 KB Output is correct
34 Correct 281 ms 8396 KB Output is correct
35 Correct 294 ms 9952 KB Output is correct
36 Correct 322 ms 11808 KB Output is correct
37 Correct 307 ms 11496 KB Output is correct
38 Correct 303 ms 13360 KB Output is correct
39 Correct 286 ms 9552 KB Output is correct
40 Correct 283 ms 10576 KB Output is correct
41 Correct 338 ms 12580 KB Output is correct
42 Correct 328 ms 13604 KB Output is correct
43 Correct 319 ms 12020 KB Output is correct
44 Correct 306 ms 14408 KB Output is correct
45 Correct 316 ms 15060 KB Output is correct
46 Correct 277 ms 11460 KB Output is correct
47 Correct 290 ms 12144 KB Output is correct
48 Correct 316 ms 11588 KB Output is correct
49 Correct 326 ms 13672 KB Output is correct
50 Correct 295 ms 11404 KB Output is correct
51 Correct 341 ms 12844 KB Output is correct
52 Correct 313 ms 13840 KB Output is correct
53 Correct 280 ms 9540 KB Output is correct
54 Correct 312 ms 11536 KB Output is correct
55 Correct 335 ms 12956 KB Output is correct
56 Correct 337 ms 13904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 448 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 3 ms 348 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 3 ms 348 KB Output is correct
34 Correct 4 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 3 ms 344 KB Output is correct
37 Correct 4 ms 600 KB Output is correct
38 Correct 3 ms 604 KB Output is correct
39 Correct 3 ms 532 KB Output is correct
40 Correct 3 ms 348 KB Output is correct
41 Correct 3 ms 348 KB Output is correct
42 Correct 3 ms 348 KB Output is correct
43 Correct 3 ms 348 KB Output is correct
44 Correct 3 ms 348 KB Output is correct
45 Correct 3 ms 604 KB Output is correct
46 Correct 4 ms 620 KB Output is correct
47 Correct 3 ms 348 KB Output is correct
48 Correct 3 ms 348 KB Output is correct
49 Correct 4 ms 604 KB Output is correct
50 Correct 4 ms 612 KB Output is correct
51 Correct 5 ms 348 KB Output is correct
52 Correct 5 ms 488 KB Output is correct
53 Correct 3 ms 604 KB Output is correct
54 Correct 4 ms 604 KB Output is correct
55 Correct 95 ms 7796 KB Output is correct
56 Correct 94 ms 10824 KB Output is correct
57 Correct 50 ms 10340 KB Output is correct
58 Correct 60 ms 7876 KB Output is correct
59 Correct 96 ms 7872 KB Output is correct
60 Correct 129 ms 9260 KB Output is correct
61 Correct 104 ms 7752 KB Output is correct
62 Correct 106 ms 9608 KB Output is correct
63 Correct 76 ms 6104 KB Output is correct
64 Correct 108 ms 8336 KB Output is correct
65 Correct 131 ms 9536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 448 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 344 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 3 ms 348 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 3 ms 348 KB Output is correct
33 Correct 3 ms 348 KB Output is correct
34 Correct 4 ms 604 KB Output is correct
35 Correct 3 ms 604 KB Output is correct
36 Correct 3 ms 344 KB Output is correct
37 Correct 4 ms 600 KB Output is correct
38 Correct 3 ms 604 KB Output is correct
39 Correct 3 ms 532 KB Output is correct
40 Correct 3 ms 348 KB Output is correct
41 Correct 3 ms 348 KB Output is correct
42 Correct 3 ms 348 KB Output is correct
43 Correct 3 ms 348 KB Output is correct
44 Correct 3 ms 348 KB Output is correct
45 Correct 3 ms 604 KB Output is correct
46 Correct 4 ms 620 KB Output is correct
47 Correct 3 ms 348 KB Output is correct
48 Correct 3 ms 348 KB Output is correct
49 Correct 4 ms 604 KB Output is correct
50 Correct 4 ms 612 KB Output is correct
51 Correct 5 ms 348 KB Output is correct
52 Correct 5 ms 488 KB Output is correct
53 Correct 3 ms 604 KB Output is correct
54 Correct 4 ms 604 KB Output is correct
55 Correct 295 ms 7684 KB Output is correct
56 Correct 322 ms 10560 KB Output is correct
57 Correct 259 ms 9876 KB Output is correct
58 Correct 275 ms 7220 KB Output is correct
59 Correct 269 ms 7792 KB Output is correct
60 Correct 281 ms 8396 KB Output is correct
61 Correct 294 ms 9952 KB Output is correct
62 Correct 322 ms 11808 KB Output is correct
63 Correct 307 ms 11496 KB Output is correct
64 Correct 303 ms 13360 KB Output is correct
65 Correct 286 ms 9552 KB Output is correct
66 Correct 283 ms 10576 KB Output is correct
67 Correct 338 ms 12580 KB Output is correct
68 Correct 328 ms 13604 KB Output is correct
69 Correct 319 ms 12020 KB Output is correct
70 Correct 306 ms 14408 KB Output is correct
71 Correct 316 ms 15060 KB Output is correct
72 Correct 277 ms 11460 KB Output is correct
73 Correct 290 ms 12144 KB Output is correct
74 Correct 316 ms 11588 KB Output is correct
75 Correct 326 ms 13672 KB Output is correct
76 Correct 295 ms 11404 KB Output is correct
77 Correct 341 ms 12844 KB Output is correct
78 Correct 313 ms 13840 KB Output is correct
79 Correct 280 ms 9540 KB Output is correct
80 Correct 312 ms 11536 KB Output is correct
81 Correct 335 ms 12956 KB Output is correct
82 Correct 337 ms 13904 KB Output is correct
83 Correct 95 ms 7796 KB Output is correct
84 Correct 94 ms 10824 KB Output is correct
85 Correct 50 ms 10340 KB Output is correct
86 Correct 60 ms 7876 KB Output is correct
87 Correct 96 ms 7872 KB Output is correct
88 Correct 129 ms 9260 KB Output is correct
89 Correct 104 ms 7752 KB Output is correct
90 Correct 106 ms 9608 KB Output is correct
91 Correct 76 ms 6104 KB Output is correct
92 Correct 108 ms 8336 KB Output is correct
93 Correct 131 ms 9536 KB Output is correct
94 Correct 322 ms 12584 KB Output is correct
95 Correct 332 ms 15536 KB Output is correct
96 Correct 273 ms 15184 KB Output is correct
97 Correct 282 ms 12684 KB Output is correct
98 Correct 276 ms 12708 KB Output is correct
99 Correct 287 ms 11484 KB Output is correct
100 Correct 325 ms 14896 KB Output is correct
101 Correct 311 ms 12016 KB Output is correct
102 Correct 326 ms 13576 KB Output is correct
103 Correct 361 ms 14660 KB Output is correct
104 Correct 302 ms 10964 KB Output is correct
105 Correct 321 ms 13264 KB Output is correct
106 Correct 345 ms 14340 KB Output is correct
107 Correct 257 ms 15852 KB Output is correct
108 Correct 317 ms 12400 KB Output is correct
109 Correct 326 ms 12532 KB Output is correct
110 Correct 309 ms 12592 KB Output is correct
111 Correct 317 ms 12524 KB Output is correct
112 Correct 312 ms 12404 KB Output is correct
113 Correct 304 ms 12428 KB Output is correct
114 Correct 301 ms 12548 KB Output is correct
115 Correct 306 ms 12404 KB Output is correct
116 Correct 300 ms 12376 KB Output is correct