답안 #1047723

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1047723 2024-08-07T15:20:41 Z Lobo Joker (BOI20_joker) C++17
100 / 100
168 ms 16072 KB
#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 10;
// #define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxn = 2e5+10;
// L,R
// (1,L) + (R,M)
// (L+1,R-1)

int n, m, q, isbip = 1, dsz[maxn], ans[maxn];
pair<int,int> ds[maxn], edg[maxn];
vector<pair<pair<int,int>,int>> roll;

pair<int,int> find(int u) {
    if(ds[u].fr == u) return mp(u,0);
    auto aux = find(ds[u].fr);
    return mp(aux.fr,(ds[u].sc^aux.sc));
}
void add(int i) {
    if(i == 0 or i == m+1) {
        roll.pb(mp(mp(0,0),0));
        return;
    }
        // cout << edg[i].fr << " " << edg[i].sc << endl;
    int u = edg[i].fr;
    auto auxu = find(u);
    u = auxu.fr;
    int paru = auxu.sc;

    int v = edg[i].sc;
    auto auxv = find(v);
    v = auxv.fr;
    int parv = auxv.sc;
    
    if(u == v && paru == parv) {
        roll.pb(mp(mp(u,v),isbip));
        // cout << " " << u << " " << v << " " << ds[ds[edg[i].sc].fr].sc << endl;
        isbip = 0;
    }
    else if(u != v) {
        if(dsz[u] < dsz[v]) {
            swap(u,v);
            swap(paru,parv);
        }
        roll.pb(mp(mp(u,v),isbip));
        dsz[u]+= dsz[v];
        ds[v].fr = u;
        ds[v].sc = (1^paru^parv);
    }
    else {
        roll.pb(mp(mp(u,v),isbip));
    }
}

void rollback() {
    assert(roll.size());
    if(roll.back().fr.fr == 0) {
        roll.pop_back();
        return;
    }
    int u = roll.back().fr.fr;
    int v = roll.back().fr.sc;
    isbip = roll.back().sc;
    roll.pop_back();
    if(u == v) return;
    ds[u] = mp(u,0);
    ds[v] = mp(v,0);
    dsz[u]-= dsz[v];
}

// pra cada l, eu vejo qual o menor r em que
// cada l, min r -> (1,l) + (r,m) é bipartido
// comeca sendo 0 m 1 m+1
// (5,7,1,2)

void sol(int l1, int l2, int r1, int r2) {
    if(l1 > l2) return;
    int l = (l1+l2)/2;
    // cout << l1 << " " << l2 << " " << r1 << " " << r2 << " " << isbip << endl;
    // if(!(l1==0 and l2==m)) exit(0);
    // if(!(l1==0 and l2==m) and !(l1==5 and l2==8) and !(l1==7 and l2==8) and (l1==8 and l2==8)) exit(0);
    for(int i = l1+1; i <= l; i++) {
        add(i);
    }
    if(isbip == false) {
        for(int i = l; i <= l2; i++) {
            ans[i] = inf;
        }
        for(int i = l; i >= l1+1; i--) {
            rollback();
        }
        sol(l1,l-1,r1,r2);
        return;
    }
    // cout << " " << isbip << " " << roll.size() << endl;
    int r = r2;
    if(isbip == true) {
        while(r-1 >= r1) {
            r--;
            add(r);
            if(isbip == false) {
                rollback();
                r++;
                break;
            }
        }
    }
    // cout << l << " " << r << " " << isbip << " " << roll.size() << endl;
    // if(l == 6) exit(0);
    ans[l] = r;
    // if(isbip == 0) ans[l] = inf;
    int R = r;
    while(r != r2) {
        r++;
        rollback();
    }
    // r = r2
    add(l+1);
    sol(l+1,l2,R,r2);
    for(int i = l+1; i >= l1+1; i--) {
        rollback();
    }
    while(r != R) {
        r--;
        add(r);
    }
    // r = R
    sol(l1,l-1,r1,R);

    while(r != r2) {
        r++;
        rollback();
    }
    // r = r2
}

void solve() {
    cin >> n >> m >> q;

    for(int i = 1; i <= n; i++) {
        ds[i] = mp(i,0);
        dsz[i] = 1;
    }

    for(int i = 1; i <= m; i++) {
        int u,v;
        cin >> u >> v;
        edg[i] = mp(u,v);
    }
    
    isbip = 1;
    roll.pb(mp(mp(0,0),0));
    roll.pb(mp(mp(0,0),0));
    sol(0,m,1,m+1);
    for(int i = 1; i <= q; i++) {
        int l,r;
        cin >> l >> r;
        if(ans[l-1] <= r+1) {
            cout << "NO" << endl;
        }
        else {
            cout << "YES" << endl;
        }
    }
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    #ifndef ONLINE_JUDGE
    // freopen("in.in", "r", stdin);
    // freopen("out.out", "w", stdout);
    #endif

    int tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
    }

}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4448 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4564 KB Output is correct
6 Correct 0 ms 4564 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4564 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 0 ms 4444 KB Output is correct
25 Correct 1 ms 4528 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 0 ms 4444 KB Output is correct
28 Correct 0 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4448 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4564 KB Output is correct
6 Correct 0 ms 4564 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4564 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 0 ms 4444 KB Output is correct
25 Correct 1 ms 4528 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 0 ms 4444 KB Output is correct
28 Correct 0 ms 4444 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 1 ms 4576 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 2 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4580 KB Output is correct
45 Correct 2 ms 4444 KB Output is correct
46 Correct 1 ms 4584 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 2 ms 4664 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4440 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4448 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 84 ms 11108 KB Output is correct
4 Correct 168 ms 14772 KB Output is correct
5 Correct 68 ms 12208 KB Output is correct
6 Correct 67 ms 11212 KB Output is correct
7 Correct 68 ms 11708 KB Output is correct
8 Correct 77 ms 10580 KB Output is correct
9 Correct 114 ms 10768 KB Output is correct
10 Correct 107 ms 11972 KB Output is correct
11 Correct 116 ms 12280 KB Output is correct
12 Correct 96 ms 12736 KB Output is correct
13 Correct 94 ms 11100 KB Output is correct
14 Correct 79 ms 12340 KB Output is correct
15 Correct 104 ms 11400 KB Output is correct
16 Correct 120 ms 12496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4448 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4564 KB Output is correct
6 Correct 0 ms 4564 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4564 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 0 ms 4444 KB Output is correct
25 Correct 1 ms 4528 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 0 ms 4444 KB Output is correct
28 Correct 0 ms 4444 KB Output is correct
29 Correct 84 ms 11108 KB Output is correct
30 Correct 168 ms 14772 KB Output is correct
31 Correct 68 ms 12208 KB Output is correct
32 Correct 67 ms 11212 KB Output is correct
33 Correct 68 ms 11708 KB Output is correct
34 Correct 77 ms 10580 KB Output is correct
35 Correct 114 ms 10768 KB Output is correct
36 Correct 107 ms 11972 KB Output is correct
37 Correct 116 ms 12280 KB Output is correct
38 Correct 96 ms 12736 KB Output is correct
39 Correct 94 ms 11100 KB Output is correct
40 Correct 79 ms 12340 KB Output is correct
41 Correct 104 ms 11400 KB Output is correct
42 Correct 120 ms 12496 KB Output is correct
43 Correct 95 ms 11468 KB Output is correct
44 Correct 150 ms 16072 KB Output is correct
45 Correct 121 ms 12624 KB Output is correct
46 Correct 65 ms 11508 KB Output is correct
47 Correct 67 ms 12732 KB Output is correct
48 Correct 97 ms 11252 KB Output is correct
49 Correct 131 ms 12224 KB Output is correct
50 Correct 111 ms 11964 KB Output is correct
51 Correct 91 ms 11668 KB Output is correct
52 Correct 119 ms 11960 KB Output is correct
53 Correct 91 ms 12252 KB Output is correct
54 Correct 102 ms 11360 KB Output is correct
55 Correct 154 ms 11784 KB Output is correct
56 Correct 113 ms 12024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4448 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4564 KB Output is correct
6 Correct 0 ms 4564 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4564 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 0 ms 4444 KB Output is correct
25 Correct 1 ms 4528 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 0 ms 4444 KB Output is correct
28 Correct 0 ms 4444 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 1 ms 4576 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 2 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4580 KB Output is correct
45 Correct 2 ms 4444 KB Output is correct
46 Correct 1 ms 4584 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 2 ms 4664 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4440 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 59 ms 11212 KB Output is correct
56 Correct 134 ms 15556 KB Output is correct
57 Correct 49 ms 10704 KB Output is correct
58 Correct 49 ms 10120 KB Output is correct
59 Correct 108 ms 11004 KB Output is correct
60 Correct 101 ms 10696 KB Output is correct
61 Correct 76 ms 10448 KB Output is correct
62 Correct 75 ms 10956 KB Output is correct
63 Correct 60 ms 11120 KB Output is correct
64 Correct 83 ms 10440 KB Output is correct
65 Correct 135 ms 10696 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4448 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 0 ms 4564 KB Output is correct
6 Correct 0 ms 4564 KB Output is correct
7 Correct 1 ms 4444 KB Output is correct
8 Correct 1 ms 4444 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 1 ms 4440 KB Output is correct
12 Correct 1 ms 4444 KB Output is correct
13 Correct 1 ms 4444 KB Output is correct
14 Correct 1 ms 4444 KB Output is correct
15 Correct 1 ms 4564 KB Output is correct
16 Correct 1 ms 4444 KB Output is correct
17 Correct 1 ms 4444 KB Output is correct
18 Correct 1 ms 4444 KB Output is correct
19 Correct 1 ms 4444 KB Output is correct
20 Correct 1 ms 4444 KB Output is correct
21 Correct 1 ms 4444 KB Output is correct
22 Correct 1 ms 4440 KB Output is correct
23 Correct 1 ms 4440 KB Output is correct
24 Correct 0 ms 4444 KB Output is correct
25 Correct 1 ms 4528 KB Output is correct
26 Correct 1 ms 4444 KB Output is correct
27 Correct 0 ms 4444 KB Output is correct
28 Correct 0 ms 4444 KB Output is correct
29 Correct 2 ms 4444 KB Output is correct
30 Correct 1 ms 4576 KB Output is correct
31 Correct 1 ms 4444 KB Output is correct
32 Correct 1 ms 4444 KB Output is correct
33 Correct 1 ms 4444 KB Output is correct
34 Correct 1 ms 4444 KB Output is correct
35 Correct 1 ms 4444 KB Output is correct
36 Correct 2 ms 4444 KB Output is correct
37 Correct 1 ms 4444 KB Output is correct
38 Correct 2 ms 4700 KB Output is correct
39 Correct 1 ms 4444 KB Output is correct
40 Correct 1 ms 4444 KB Output is correct
41 Correct 2 ms 4444 KB Output is correct
42 Correct 2 ms 4444 KB Output is correct
43 Correct 1 ms 4444 KB Output is correct
44 Correct 1 ms 4580 KB Output is correct
45 Correct 2 ms 4444 KB Output is correct
46 Correct 1 ms 4584 KB Output is correct
47 Correct 1 ms 4444 KB Output is correct
48 Correct 1 ms 4444 KB Output is correct
49 Correct 2 ms 4664 KB Output is correct
50 Correct 1 ms 4444 KB Output is correct
51 Correct 1 ms 4440 KB Output is correct
52 Correct 1 ms 4444 KB Output is correct
53 Correct 1 ms 4444 KB Output is correct
54 Correct 1 ms 4444 KB Output is correct
55 Correct 84 ms 11108 KB Output is correct
56 Correct 168 ms 14772 KB Output is correct
57 Correct 68 ms 12208 KB Output is correct
58 Correct 67 ms 11212 KB Output is correct
59 Correct 68 ms 11708 KB Output is correct
60 Correct 77 ms 10580 KB Output is correct
61 Correct 114 ms 10768 KB Output is correct
62 Correct 107 ms 11972 KB Output is correct
63 Correct 116 ms 12280 KB Output is correct
64 Correct 96 ms 12736 KB Output is correct
65 Correct 94 ms 11100 KB Output is correct
66 Correct 79 ms 12340 KB Output is correct
67 Correct 104 ms 11400 KB Output is correct
68 Correct 120 ms 12496 KB Output is correct
69 Correct 95 ms 11468 KB Output is correct
70 Correct 150 ms 16072 KB Output is correct
71 Correct 121 ms 12624 KB Output is correct
72 Correct 65 ms 11508 KB Output is correct
73 Correct 67 ms 12732 KB Output is correct
74 Correct 97 ms 11252 KB Output is correct
75 Correct 131 ms 12224 KB Output is correct
76 Correct 111 ms 11964 KB Output is correct
77 Correct 91 ms 11668 KB Output is correct
78 Correct 119 ms 11960 KB Output is correct
79 Correct 91 ms 12252 KB Output is correct
80 Correct 102 ms 11360 KB Output is correct
81 Correct 154 ms 11784 KB Output is correct
82 Correct 113 ms 12024 KB Output is correct
83 Correct 59 ms 11212 KB Output is correct
84 Correct 134 ms 15556 KB Output is correct
85 Correct 49 ms 10704 KB Output is correct
86 Correct 49 ms 10120 KB Output is correct
87 Correct 108 ms 11004 KB Output is correct
88 Correct 101 ms 10696 KB Output is correct
89 Correct 76 ms 10448 KB Output is correct
90 Correct 75 ms 10956 KB Output is correct
91 Correct 60 ms 11120 KB Output is correct
92 Correct 83 ms 10440 KB Output is correct
93 Correct 135 ms 10696 KB Output is correct
94 Correct 124 ms 13508 KB Output is correct
95 Correct 114 ms 13128 KB Output is correct
96 Correct 89 ms 14012 KB Output is correct
97 Correct 78 ms 13308 KB Output is correct
98 Correct 79 ms 12536 KB Output is correct
99 Correct 101 ms 12216 KB Output is correct
100 Correct 107 ms 12668 KB Output is correct
101 Correct 109 ms 12096 KB Output is correct
102 Correct 116 ms 13188 KB Output is correct
103 Correct 118 ms 13096 KB Output is correct
104 Correct 108 ms 12476 KB Output is correct
105 Correct 107 ms 12372 KB Output is correct
106 Correct 124 ms 12728 KB Output is correct
107 Correct 89 ms 13496 KB Output is correct
108 Correct 79 ms 13244 KB Output is correct
109 Correct 79 ms 12024 KB Output is correct
110 Correct 108 ms 12592 KB Output is correct
111 Correct 97 ms 13248 KB Output is correct
112 Correct 80 ms 12020 KB Output is correct
113 Correct 108 ms 11960 KB Output is correct
114 Correct 79 ms 12024 KB Output is correct
115 Correct 86 ms 13008 KB Output is correct
116 Correct 85 ms 12028 KB Output is correct