답안 #417955

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
417955 2021-06-04T16:52:58 Z nicolaalexandra Joker (BOI20_joker) C++14
100 / 100
989 ms 9652 KB
#include <bits/stdc++.h>
#define DIM 400010
using namespace std;

int fth[DIM],Size[DIM],dp[DIM];
pair <int,int> mch[DIM];
deque <pair<int,int> > s;
int n,m,q,x,y,i,first;

int get_rad (int x){
    while (fth[x] != x)
        x = fth[x];
    return x;
}

int uneste (int x, int y){
    int radx = get_rad (x), rady = get_rad (y);
    if (radx == rady)
        return 0;

    if (Size[radx] < Size[rady])
        swap (radx,rady);

    s.push_back(make_pair(radx,rady));
    Size[radx] += Size[rady];
    fth[rady] = radx;

    return 1;
}

void undo(){
    int x = s.back().first, y = s.back().second;
    s.pop_back();
    Size[x] -= Size[y];
    fth[y] = y;
}

int verif (int x, int y){
    int radx = get_rad(x), rady = get_rad(y);
    return radx == rady;
}

void solve (int st, int dr, int opt_st, int opt_dr){
    if (st > dr)
        return;
    int mid = (st+dr)>>1, opt_mid = m;

    /// adaug tot pana la mid

    int cnt = 0, ok = 0;
    for (int i=st;i<mid;i++){
        int x = mch[i].first, y = mch[i].second;
        cnt += uneste(x,y+n);
        cnt += uneste(x+n,y);

        if (verif(x,x+n)){ /// am ciclu impar deja
            ok = 1;
            break;
        }
    }

    if (ok){
        dp[mid] = opt_mid = m+1;
    } else {

        /// adaug muchii din dreapta si vad daca se pastreaza propr de bipartit
        if (mid == 188)
            mid = 188;
        for (opt_mid = opt_dr; opt_mid >= opt_st && opt_mid >= mid; opt_mid--){
            if (opt_mid == m+1)
                continue;

            int x = mch[opt_mid].first, y = mch[opt_mid].second;
            cnt += uneste(x,y+n);
            cnt += uneste(x+n,y);

            if (verif(x,x+n))
                break;
        }
        dp[mid] = opt_mid;

        if (dp[mid] == 201)
            dp[mid] = 201;
    }

    while (cnt > 0){
        undo();
        cnt--;
    }

    /// acum trb sa refac padurile a.i. sa se potriveasca pt intervalele urmatoare

    ok = 0;
    for (int i=opt_mid+1;i<=opt_dr;i++){
        if (i == m+1)
            continue;

        int x = mch[i].first, y = mch[i].second;
        cnt += uneste(x,y+n);
        cnt += uneste(x+n,y);

        if (verif(x,x+n)){
            ok = 1;
            while (cnt > 0){
                undo();
                cnt--;
            }
            for (int j=st;j<mid;j++)
                dp[j] = m+1;

            break;
        }
    }

    if (!ok){
        solve (st,mid-1,opt_st,opt_mid);


        /// iar undo
        while (cnt > 0){
            undo();
            cnt--;
        }
    }
    /// reconstructie

    ok = 0;
    for (int i=st;i<=mid;i++){
        int x = mch[i].first, y = mch[i].second;
        cnt += uneste(x,y+n);
        cnt += uneste(x+n,y);

        if (verif(x,x+n)){
            ok = 1;
            while (cnt > 0){
                undo();
                cnt--;
            }

            for (int j=mid+1;j<=dr;j++)
                dp[j] = m+1;

            break;
        }
    }

    if (!ok){
        solve (mid+1,dr,opt_mid,opt_dr);
        while (cnt > 0){
            undo();
            cnt--;
        }
    }

}



int main (){

    //ifstream cin ("date.in");
    //ofstream cout ("date.out");

    cin>>n>>m>>q;
    for (i=1;i<=m;i++)
        cin>>mch[i].first>>mch[i].second;

    for (i=1;i<=2*n;i++)
        fth[i] = i, Size[i] = 1;

    solve (1,m,1,m+1);

    //for (i=1;i<=m;i++)
        //cout<<dp[i]<<"\n";

    for (;q--;){
        cin>>x>>y;

        if (y >= dp[x])
            cout<<"NO\n";
        else cout<<"YES\n";

    }


    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 216 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 216 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 6 ms 332 KB Output is correct
30 Correct 7 ms 332 KB Output is correct
31 Correct 7 ms 332 KB Output is correct
32 Correct 6 ms 332 KB Output is correct
33 Correct 6 ms 332 KB Output is correct
34 Correct 7 ms 332 KB Output is correct
35 Correct 7 ms 332 KB Output is correct
36 Correct 10 ms 332 KB Output is correct
37 Correct 8 ms 332 KB Output is correct
38 Correct 9 ms 332 KB Output is correct
39 Correct 8 ms 332 KB Output is correct
40 Correct 7 ms 332 KB Output is correct
41 Correct 7 ms 332 KB Output is correct
42 Correct 7 ms 332 KB Output is correct
43 Correct 7 ms 332 KB Output is correct
44 Correct 7 ms 332 KB Output is correct
45 Correct 7 ms 384 KB Output is correct
46 Correct 8 ms 280 KB Output is correct
47 Correct 7 ms 332 KB Output is correct
48 Correct 7 ms 332 KB Output is correct
49 Correct 7 ms 332 KB Output is correct
50 Correct 7 ms 388 KB Output is correct
51 Correct 7 ms 332 KB Output is correct
52 Correct 7 ms 332 KB Output is correct
53 Correct 7 ms 332 KB Output is correct
54 Correct 7 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 769 ms 6460 KB Output is correct
4 Correct 941 ms 9652 KB Output is correct
5 Correct 765 ms 8996 KB Output is correct
6 Correct 729 ms 5852 KB Output is correct
7 Correct 751 ms 5848 KB Output is correct
8 Correct 722 ms 5316 KB Output is correct
9 Correct 810 ms 5948 KB Output is correct
10 Correct 853 ms 8356 KB Output is correct
11 Correct 800 ms 6284 KB Output is correct
12 Correct 800 ms 7700 KB Output is correct
13 Correct 702 ms 3944 KB Output is correct
14 Correct 743 ms 5108 KB Output is correct
15 Correct 891 ms 6520 KB Output is correct
16 Correct 886 ms 7976 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 216 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 769 ms 6460 KB Output is correct
30 Correct 941 ms 9652 KB Output is correct
31 Correct 765 ms 8996 KB Output is correct
32 Correct 729 ms 5852 KB Output is correct
33 Correct 751 ms 5848 KB Output is correct
34 Correct 722 ms 5316 KB Output is correct
35 Correct 810 ms 5948 KB Output is correct
36 Correct 853 ms 8356 KB Output is correct
37 Correct 800 ms 6284 KB Output is correct
38 Correct 800 ms 7700 KB Output is correct
39 Correct 702 ms 3944 KB Output is correct
40 Correct 743 ms 5108 KB Output is correct
41 Correct 891 ms 6520 KB Output is correct
42 Correct 886 ms 7976 KB Output is correct
43 Correct 752 ms 6440 KB Output is correct
44 Correct 951 ms 9568 KB Output is correct
45 Correct 924 ms 9636 KB Output is correct
46 Correct 689 ms 6016 KB Output is correct
47 Correct 719 ms 5852 KB Output is correct
48 Correct 810 ms 6028 KB Output is correct
49 Correct 947 ms 8120 KB Output is correct
50 Correct 758 ms 5736 KB Output is correct
51 Correct 775 ms 6944 KB Output is correct
52 Correct 840 ms 8176 KB Output is correct
53 Correct 728 ms 3896 KB Output is correct
54 Correct 841 ms 5576 KB Output is correct
55 Correct 855 ms 6540 KB Output is correct
56 Correct 896 ms 8044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 216 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 6 ms 332 KB Output is correct
30 Correct 7 ms 332 KB Output is correct
31 Correct 7 ms 332 KB Output is correct
32 Correct 6 ms 332 KB Output is correct
33 Correct 6 ms 332 KB Output is correct
34 Correct 7 ms 332 KB Output is correct
35 Correct 7 ms 332 KB Output is correct
36 Correct 10 ms 332 KB Output is correct
37 Correct 8 ms 332 KB Output is correct
38 Correct 9 ms 332 KB Output is correct
39 Correct 8 ms 332 KB Output is correct
40 Correct 7 ms 332 KB Output is correct
41 Correct 7 ms 332 KB Output is correct
42 Correct 7 ms 332 KB Output is correct
43 Correct 7 ms 332 KB Output is correct
44 Correct 7 ms 332 KB Output is correct
45 Correct 7 ms 384 KB Output is correct
46 Correct 8 ms 280 KB Output is correct
47 Correct 7 ms 332 KB Output is correct
48 Correct 7 ms 332 KB Output is correct
49 Correct 7 ms 332 KB Output is correct
50 Correct 7 ms 388 KB Output is correct
51 Correct 7 ms 332 KB Output is correct
52 Correct 7 ms 332 KB Output is correct
53 Correct 7 ms 332 KB Output is correct
54 Correct 7 ms 332 KB Output is correct
55 Correct 354 ms 5920 KB Output is correct
56 Correct 532 ms 8976 KB Output is correct
57 Correct 345 ms 8416 KB Output is correct
58 Correct 272 ms 5804 KB Output is correct
59 Correct 401 ms 5536 KB Output is correct
60 Correct 479 ms 6684 KB Output is correct
61 Correct 363 ms 5548 KB Output is correct
62 Correct 387 ms 7188 KB Output is correct
63 Correct 296 ms 3852 KB Output is correct
64 Correct 425 ms 5896 KB Output is correct
65 Correct 500 ms 7096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 2 ms 212 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Correct 1 ms 204 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 204 KB Output is correct
15 Correct 2 ms 204 KB Output is correct
16 Correct 1 ms 204 KB Output is correct
17 Correct 1 ms 296 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 2 ms 204 KB Output is correct
21 Correct 1 ms 216 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 1 ms 204 KB Output is correct
26 Correct 1 ms 204 KB Output is correct
27 Correct 1 ms 204 KB Output is correct
28 Correct 1 ms 204 KB Output is correct
29 Correct 6 ms 332 KB Output is correct
30 Correct 7 ms 332 KB Output is correct
31 Correct 7 ms 332 KB Output is correct
32 Correct 6 ms 332 KB Output is correct
33 Correct 6 ms 332 KB Output is correct
34 Correct 7 ms 332 KB Output is correct
35 Correct 7 ms 332 KB Output is correct
36 Correct 10 ms 332 KB Output is correct
37 Correct 8 ms 332 KB Output is correct
38 Correct 9 ms 332 KB Output is correct
39 Correct 8 ms 332 KB Output is correct
40 Correct 7 ms 332 KB Output is correct
41 Correct 7 ms 332 KB Output is correct
42 Correct 7 ms 332 KB Output is correct
43 Correct 7 ms 332 KB Output is correct
44 Correct 7 ms 332 KB Output is correct
45 Correct 7 ms 384 KB Output is correct
46 Correct 8 ms 280 KB Output is correct
47 Correct 7 ms 332 KB Output is correct
48 Correct 7 ms 332 KB Output is correct
49 Correct 7 ms 332 KB Output is correct
50 Correct 7 ms 388 KB Output is correct
51 Correct 7 ms 332 KB Output is correct
52 Correct 7 ms 332 KB Output is correct
53 Correct 7 ms 332 KB Output is correct
54 Correct 7 ms 332 KB Output is correct
55 Correct 769 ms 6460 KB Output is correct
56 Correct 941 ms 9652 KB Output is correct
57 Correct 765 ms 8996 KB Output is correct
58 Correct 729 ms 5852 KB Output is correct
59 Correct 751 ms 5848 KB Output is correct
60 Correct 722 ms 5316 KB Output is correct
61 Correct 810 ms 5948 KB Output is correct
62 Correct 853 ms 8356 KB Output is correct
63 Correct 800 ms 6284 KB Output is correct
64 Correct 800 ms 7700 KB Output is correct
65 Correct 702 ms 3944 KB Output is correct
66 Correct 743 ms 5108 KB Output is correct
67 Correct 891 ms 6520 KB Output is correct
68 Correct 886 ms 7976 KB Output is correct
69 Correct 752 ms 6440 KB Output is correct
70 Correct 951 ms 9568 KB Output is correct
71 Correct 924 ms 9636 KB Output is correct
72 Correct 689 ms 6016 KB Output is correct
73 Correct 719 ms 5852 KB Output is correct
74 Correct 810 ms 6028 KB Output is correct
75 Correct 947 ms 8120 KB Output is correct
76 Correct 758 ms 5736 KB Output is correct
77 Correct 775 ms 6944 KB Output is correct
78 Correct 840 ms 8176 KB Output is correct
79 Correct 728 ms 3896 KB Output is correct
80 Correct 841 ms 5576 KB Output is correct
81 Correct 855 ms 6540 KB Output is correct
82 Correct 896 ms 8044 KB Output is correct
83 Correct 354 ms 5920 KB Output is correct
84 Correct 532 ms 8976 KB Output is correct
85 Correct 345 ms 8416 KB Output is correct
86 Correct 272 ms 5804 KB Output is correct
87 Correct 401 ms 5536 KB Output is correct
88 Correct 479 ms 6684 KB Output is correct
89 Correct 363 ms 5548 KB Output is correct
90 Correct 387 ms 7188 KB Output is correct
91 Correct 296 ms 3852 KB Output is correct
92 Correct 425 ms 5896 KB Output is correct
93 Correct 500 ms 7096 KB Output is correct
94 Correct 794 ms 6596 KB Output is correct
95 Correct 942 ms 9584 KB Output is correct
96 Correct 800 ms 9168 KB Output is correct
97 Correct 739 ms 6004 KB Output is correct
98 Correct 789 ms 6056 KB Output is correct
99 Correct 824 ms 5284 KB Output is correct
100 Correct 960 ms 8348 KB Output is correct
101 Correct 809 ms 5652 KB Output is correct
102 Correct 863 ms 7072 KB Output is correct
103 Correct 903 ms 8400 KB Output is correct
104 Correct 792 ms 4572 KB Output is correct
105 Correct 924 ms 6224 KB Output is correct
106 Correct 989 ms 7236 KB Output is correct
107 Correct 737 ms 9568 KB Output is correct
108 Correct 778 ms 6488 KB Output is correct
109 Correct 776 ms 6424 KB Output is correct
110 Correct 774 ms 6608 KB Output is correct
111 Correct 788 ms 6436 KB Output is correct
112 Correct 773 ms 6400 KB Output is correct
113 Correct 782 ms 6392 KB Output is correct
114 Correct 796 ms 6456 KB Output is correct
115 Correct 769 ms 6364 KB Output is correct
116 Correct 777 ms 6392 KB Output is correct