답안 #306127

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
306127 2020-09-24T15:09:26 Z 2fat2code Joker (BOI20_joker) C++17
100 / 100
368 ms 12776 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
//#define int long long
//#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)

const int nmax = 200005;

int n,m,q,frbipartid[nmax],siz[nmax];
pair<int,int>par[nmax];
vector<int>rollback;
vector<pair<int,int>>edges;

void roll(int sz){
    while((int)rollback.size() > sz){
        auto it = rollback.back();
        siz[par[it].fr] -= siz[it];
        par[it].fr = it;
        par[it].sc = 0;
        rollback.pop_back();
    }
}

pair<int,int>findpar(int x,int path){
    pair<int,int>ans = {par[x].fr, 0};
    if(x != par[x].fr){
        ans = findpar(par[x].fr,path+1);
        ans.sc ^= par[x].sc;
    }
    return ans;
}

bool onion(int x,int y){
    pair<int,int>x1,y1;
    x1 = findpar(x,0);
    y1 = findpar(y,0);
    if(x1.fr == y1.fr){
        if(x1.sc == y1.sc){
            return false;
        }
        else{
            return true;
        }
    }
    else{
        if(siz[x1.fr] > siz[y1.fr]) swap(x1,y1);
        siz[y1.fr] += siz[x1.fr];
        par[x1.fr].fr = y1.fr;
        if(x1.sc == y1.sc){
            par[x1.fr].sc = 1;
        }
        else{
            par[x1.fr].sc = 0;
        }
        rollback.push_back(x1.fr);
        return true;
    }
}

void DAC(int l_nod,int r_nod,int l_range,int r_range,int funct){
    if(r_nod < l_nod) return;
    if(l_range == r_range){
        for(int j=l_nod;j<=r_nod;j++){
            frbipartid[j] = l_range;
        }
        return;
    }
    else{
        int mid = l_range + (r_range - l_range) / 2;
        bool bl = false;
        int sz_roll = rollback.size();
        for(int j=r_range;j>mid;j--){
            if(j == m + 1){ continue; }
            else{
                if(!onion(edges[j-1].fr,edges[j-1].sc)){
                    bl = true;
                    break;
                }
            }
        }
        int indx = l_nod;
        if(bl == false){
            int sz_roll2=(int)rollback.size();
            indx = -1;
            for(int j=l_nod;j<=min(r_nod,mid);j++){
                if(onion(edges[j-1].fr,edges[j-1].sc) == false){
                    indx = j + 1;
                    break;
                }
            }
            if(indx == -1) indx = min(r_nod,mid) + 1;
            roll(sz_roll2);
            DAC(l_nod,indx-1,l_range,mid,funct + 1);
        }
        roll(sz_roll);
        int sz_roll3 = (int)rollback.size();
        bool bllmao = false;
        for(int j=l_nod;j<indx;j++){
            if(onion(edges[j-1].fr,edges[j-1].sc) == false){
                bllmao = true;
                break;
            }
        }
        if(bllmao == false){
            DAC(indx,r_nod,mid+1,r_range,funct + 1);
        }
        else{
            for(int j=indx;j<=r_nod;j++){
                frbipartid[j] = m + 1;
            }
        }
        roll(sz_roll3);
    }
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    srand(chrono::steady_clock::now().time_since_epoch().count());
    cin >> n >> m >> q;
    for(int i=1;i<=n;i++){
        par[i] = {i, 0};
        siz[i] = 1;
    }
    for(int i=1;i<=m;i++){
        int x,y;
        cin >> x >> y;
        edges.push_back({x,y});
    }
    DAC(1,m,1,m+1,1);
    for(int i=1;i<=q;i++){
        int x,y;
        cin >> x >> y;
        if(frbipartid[x] <= y){
            cout << "NO" << '\n';
        }
        else{
            cout << "YES" << '\n';
        }
    }
}

# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 2 ms 384 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 2 ms 384 KB Output is correct
51 Correct 2 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 2 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 175 ms 5480 KB Output is correct
4 Correct 309 ms 7504 KB Output is correct
5 Correct 148 ms 7272 KB Output is correct
6 Correct 135 ms 5480 KB Output is correct
7 Correct 150 ms 5476 KB Output is correct
8 Correct 140 ms 5608 KB Output is correct
9 Correct 157 ms 8808 KB Output is correct
10 Correct 246 ms 10344 KB Output is correct
11 Correct 170 ms 9364 KB Output is correct
12 Correct 204 ms 10476 KB Output is correct
13 Correct 106 ms 7656 KB Output is correct
14 Correct 144 ms 8736 KB Output is correct
15 Correct 202 ms 10192 KB Output is correct
16 Correct 252 ms 10728 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 175 ms 5480 KB Output is correct
30 Correct 309 ms 7504 KB Output is correct
31 Correct 148 ms 7272 KB Output is correct
32 Correct 135 ms 5480 KB Output is correct
33 Correct 150 ms 5476 KB Output is correct
34 Correct 140 ms 5608 KB Output is correct
35 Correct 157 ms 8808 KB Output is correct
36 Correct 246 ms 10344 KB Output is correct
37 Correct 170 ms 9364 KB Output is correct
38 Correct 204 ms 10476 KB Output is correct
39 Correct 106 ms 7656 KB Output is correct
40 Correct 144 ms 8736 KB Output is correct
41 Correct 202 ms 10192 KB Output is correct
42 Correct 252 ms 10728 KB Output is correct
43 Correct 185 ms 9764 KB Output is correct
44 Correct 368 ms 11496 KB Output is correct
45 Correct 174 ms 11880 KB Output is correct
46 Correct 135 ms 9704 KB Output is correct
47 Correct 155 ms 9704 KB Output is correct
48 Correct 188 ms 9452 KB Output is correct
49 Correct 251 ms 10728 KB Output is correct
50 Correct 167 ms 9324 KB Output is correct
51 Correct 191 ms 10600 KB Output is correct
52 Correct 212 ms 11000 KB Output is correct
53 Correct 114 ms 7912 KB Output is correct
54 Correct 169 ms 9448 KB Output is correct
55 Correct 214 ms 10344 KB Output is correct
56 Correct 251 ms 11116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 2 ms 384 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 2 ms 384 KB Output is correct
51 Correct 2 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 2 ms 384 KB Output is correct
55 Correct 131 ms 4840 KB Output is correct
56 Correct 265 ms 6816 KB Output is correct
57 Correct 89 ms 6508 KB Output is correct
58 Correct 100 ms 4840 KB Output is correct
59 Correct 134 ms 4788 KB Output is correct
60 Correct 180 ms 8040 KB Output is correct
61 Correct 120 ms 7020 KB Output is correct
62 Correct 162 ms 8280 KB Output is correct
63 Correct 83 ms 5864 KB Output is correct
64 Correct 149 ms 7460 KB Output is correct
65 Correct 187 ms 8296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 1 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 1 ms 384 KB Output is correct
23 Correct 1 ms 384 KB Output is correct
24 Correct 1 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 2 ms 384 KB Output is correct
30 Correct 2 ms 384 KB Output is correct
31 Correct 2 ms 384 KB Output is correct
32 Correct 2 ms 384 KB Output is correct
33 Correct 1 ms 384 KB Output is correct
34 Correct 2 ms 384 KB Output is correct
35 Correct 2 ms 512 KB Output is correct
36 Correct 2 ms 384 KB Output is correct
37 Correct 2 ms 384 KB Output is correct
38 Correct 2 ms 384 KB Output is correct
39 Correct 2 ms 384 KB Output is correct
40 Correct 2 ms 384 KB Output is correct
41 Correct 2 ms 384 KB Output is correct
42 Correct 2 ms 384 KB Output is correct
43 Correct 1 ms 384 KB Output is correct
44 Correct 2 ms 384 KB Output is correct
45 Correct 2 ms 384 KB Output is correct
46 Correct 2 ms 384 KB Output is correct
47 Correct 2 ms 384 KB Output is correct
48 Correct 2 ms 384 KB Output is correct
49 Correct 2 ms 384 KB Output is correct
50 Correct 2 ms 384 KB Output is correct
51 Correct 2 ms 384 KB Output is correct
52 Correct 2 ms 384 KB Output is correct
53 Correct 2 ms 384 KB Output is correct
54 Correct 2 ms 384 KB Output is correct
55 Correct 175 ms 5480 KB Output is correct
56 Correct 309 ms 7504 KB Output is correct
57 Correct 148 ms 7272 KB Output is correct
58 Correct 135 ms 5480 KB Output is correct
59 Correct 150 ms 5476 KB Output is correct
60 Correct 140 ms 5608 KB Output is correct
61 Correct 157 ms 8808 KB Output is correct
62 Correct 246 ms 10344 KB Output is correct
63 Correct 170 ms 9364 KB Output is correct
64 Correct 204 ms 10476 KB Output is correct
65 Correct 106 ms 7656 KB Output is correct
66 Correct 144 ms 8736 KB Output is correct
67 Correct 202 ms 10192 KB Output is correct
68 Correct 252 ms 10728 KB Output is correct
69 Correct 185 ms 9764 KB Output is correct
70 Correct 368 ms 11496 KB Output is correct
71 Correct 174 ms 11880 KB Output is correct
72 Correct 135 ms 9704 KB Output is correct
73 Correct 155 ms 9704 KB Output is correct
74 Correct 188 ms 9452 KB Output is correct
75 Correct 251 ms 10728 KB Output is correct
76 Correct 167 ms 9324 KB Output is correct
77 Correct 191 ms 10600 KB Output is correct
78 Correct 212 ms 11000 KB Output is correct
79 Correct 114 ms 7912 KB Output is correct
80 Correct 169 ms 9448 KB Output is correct
81 Correct 214 ms 10344 KB Output is correct
82 Correct 251 ms 11116 KB Output is correct
83 Correct 131 ms 4840 KB Output is correct
84 Correct 265 ms 6816 KB Output is correct
85 Correct 89 ms 6508 KB Output is correct
86 Correct 100 ms 4840 KB Output is correct
87 Correct 134 ms 4788 KB Output is correct
88 Correct 180 ms 8040 KB Output is correct
89 Correct 120 ms 7020 KB Output is correct
90 Correct 162 ms 8280 KB Output is correct
91 Correct 83 ms 5864 KB Output is correct
92 Correct 149 ms 7460 KB Output is correct
93 Correct 187 ms 8296 KB Output is correct
94 Correct 209 ms 10728 KB Output is correct
95 Correct 287 ms 12648 KB Output is correct
96 Correct 179 ms 12524 KB Output is correct
97 Correct 161 ms 10472 KB Output is correct
98 Correct 189 ms 10480 KB Output is correct
99 Correct 149 ms 9580 KB Output is correct
100 Correct 294 ms 11884 KB Output is correct
101 Correct 193 ms 10088 KB Output is correct
102 Correct 224 ms 11056 KB Output is correct
103 Correct 232 ms 11880 KB Output is correct
104 Correct 138 ms 9192 KB Output is correct
105 Correct 203 ms 10856 KB Output is correct
106 Correct 259 ms 11624 KB Output is correct
107 Correct 110 ms 12776 KB Output is correct
108 Correct 188 ms 10256 KB Output is correct
109 Correct 188 ms 10216 KB Output is correct
110 Correct 190 ms 10228 KB Output is correct
111 Correct 192 ms 10300 KB Output is correct
112 Correct 196 ms 10216 KB Output is correct
113 Correct 199 ms 10300 KB Output is correct
114 Correct 196 ms 10344 KB Output is correct
115 Correct 189 ms 10212 KB Output is correct
116 Correct 191 ms 10216 KB Output is correct