답안 #1106650

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1106650 2024-10-30T18:48:39 Z koukirocks Joker (BOI20_joker) C++17
100 / 100
133 ms 21436 KB
#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("popcnt")
 
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
const ll MAX=2e5+10,P=1e9+7;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
const ldb eps=1e-6;
const ldb PI=acos(-1.0);
const int dir[4][2]={{0,1},{0,-1},{1,0},{-1,0}};
template<typename T>
using vvector = vector<vector<T>>;

struct DSU {
    int n;
    vector<ll> fa,sz;
    vector<pll> lnk;
    vector<bool> rev;
    bool isbip;
    DSU(int n):n(n),isbip(true) {
        fa.resize(n+1);
        iota(all(fa),0);
        sz.resize(n+1,1);
        rev.resize(n+1);
    }
    pair<int,bool> get(ll x) {
        if (fa[x]==x) return {x,rev[x]};
        pair<int,bool> now = get(fa[x]);
        return {now.F,now.S^rev[x]};
    }
    void link(int a,int b) {
        auto [na,ra]=get(a);
        auto [nb,rb]=get(b);
        // cout<<na<<" "<<nb<<" nab\n"<<flush;
        // cout<<ra<<" "<<rb<<" rab\n"<<flush;
        if (na==nb) {
            if (ra==rb) {
                isbip=false;
                lnk.emplace_back(-1,-1);
            }
            return;
        }
        if (sz[na]>sz[nb]) {
            swap(na,nb);
            swap(ra,rb);
        }
        fa[na]=nb;
        rev[na]=!(ra^rb);
        sz[nb]+=sz[na];
        lnk.emplace_back(na,nb);
    }
    void unlink() {                                                                                                                                                                                                                                                                    ;
        auto [a,b] = lnk.back();
        if (a==-1) isbip=true;
        else {
            rev[a]=false;
            sz[b]-=sz[a];
            fa[a]=a;
        }
        lnk.pop_back();
    }
};

void del(int sz,DSU &d) {
    // cout<<d.lnk.size()<<" "<<sz<<" sz\n"<<flush;
    while (d.lnk.size()>sz) {
        d.unlink();
        // cout<<d.lnk.size()<<" "<<sz<<" sz\n"<<flush;
    }
}

void getall(DSU &d) {
    for (int i=1;i<=d.n;i++) {
        cout<<d.get(i).F<<" ";
    }
    cout<<" all fa\n";
    for (int i=1;i<=d.n;i++) {
        cout<<d.get(i).S<<" ";
    }
    cout<<" all rev\n";
}

void cal(int l,int r,int fl,int fr,vector<ll> &ans,vector<pll> &E,DSU &d) {
    if (l>r or fl>fr) return;
    if (fl==fr) {
        for (int i=l;i<=r;i++) {
            ans[i]=fl;
        }
        return ;
    }
    // cout<<l<<" "<<r<<" "<<fl<<" "<<fr<<" "<<"lr flr start\n"<<flush;
    // getall(d);
    int mid=l+r>>1;
    // r+1 ~ fl
    int sz=d.lnk.size();
    for (int i=mid;i<=min(fl,r);i++) {
        // cout<<i<<" lk1\n";
        d.link(E[i].F,E[i].S);
    }
    // mid ~ fl
    // getall(d);
    int sz2=d.lnk.size();
    ans[mid]=-1;
    
    // cout<<l<<" "<<r<<" lr start2\n"<<flush;
    for (int i=fl+1;i<=fr;i++) {
        // getall(d);
        // cout<<i<<" lk2\n";
        d.link(E[i].F,E[i].S);
        if (!d.isbip) {
            ans[mid]=i-1;
            // cout<<mid<<" "<<ans[mid]<<" mid ans\n";
            break;
        }
    }
    if (ans[mid]==-1) ans[mid]=fr;
    // mid ~ ans[mid]
    del(sz2,d);
    // mid ~ fl
    cal(l,mid-1,fl,ans[mid],ans,E,d);
    del(sz,d);
    // r+1 ~ fl
    // getall(d);
    // cout<<l<<" "<<r<<" lr start3\n"<<flush;
    for (int i=max(fl,r)+1;i<=ans[mid];i++) {
        // cout<<i<<" Ei\n"<<flush;
        // cout<<i<<" lk3\n";
        d.link(E[i].F,E[i].S);
    }
    // cout<<l<<" "<<r<<" lr start4\n"<<flush;
    cal(mid+1,r,ans[mid],fr,ans,E,d);
    // cout<<l<<" "<<r<<" lr start5\n"<<flush;
    del(sz,d);
}

int main() {
    speed;
    int n,m,q;
    cin>>n>>m>>q;
    vector<pll> E(2*m+10);
    vector<ll> dp(m+10);
    DSU d(n);
    for (int i=1;i<=m;i++) {
        cin>>E[i].F>>E[i].S;
        E[i+m]=E[i];
    }
    cal(2,m+1,m-1,2*m,dp,E,d);
    // for (int i=2;i<=m+1;i++) cout<<dp[i]<<" ";
    // cout<<" dp\n";
    while (q--) {
        int l,r;
        cin>>l>>r;
        if (l+m-1<=dp[r+1]) cout<<"NO\n";
        else cout<<"YES\n";
    }
    return 0;
}

/*
7 7 0
1 2
2 3
3 4
4 5
5 6
6 7
5 7
*/

Compilation message

Joker.cpp: In function 'void del(int, DSU&)':
Joker.cpp:78:24: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   78 |     while (d.lnk.size()>sz) {
      |            ~~~~~~~~~~~~^~~
Joker.cpp: In function 'void cal(int, int, int, int, std::vector<long long int>&, std::vector<std::pair<long long int, long long int> >&, DSU&)':
Joker.cpp:105:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  105 |     int mid=l+r>>1;
      |             ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 508 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 508 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 456 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 508 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 508 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 456 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 624 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 2 ms 592 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 1 ms 592 KB Output is correct
38 Correct 1 ms 592 KB Output is correct
39 Correct 1 ms 592 KB Output is correct
40 Correct 1 ms 472 KB Output is correct
41 Correct 1 ms 592 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 1 ms 592 KB Output is correct
44 Correct 1 ms 592 KB Output is correct
45 Correct 1 ms 592 KB Output is correct
46 Correct 2 ms 592 KB Output is correct
47 Correct 1 ms 592 KB Output is correct
48 Correct 1 ms 592 KB Output is correct
49 Correct 1 ms 592 KB Output is correct
50 Correct 1 ms 760 KB Output is correct
51 Correct 1 ms 476 KB Output is correct
52 Correct 1 ms 592 KB Output is correct
53 Correct 2 ms 760 KB Output is correct
54 Correct 1 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 96 ms 16576 KB Output is correct
4 Correct 120 ms 20172 KB Output is correct
5 Correct 67 ms 20152 KB Output is correct
6 Correct 67 ms 16576 KB Output is correct
7 Correct 71 ms 16492 KB Output is correct
8 Correct 80 ms 15292 KB Output is correct
9 Correct 86 ms 16064 KB Output is correct
10 Correct 121 ms 20252 KB Output is correct
11 Correct 90 ms 16504 KB Output is correct
12 Correct 97 ms 19908 KB Output is correct
13 Correct 70 ms 15176 KB Output is correct
14 Correct 79 ms 16060 KB Output is correct
15 Correct 104 ms 19308 KB Output is correct
16 Correct 124 ms 20264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 508 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 508 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 456 KB Output is correct
29 Correct 96 ms 16576 KB Output is correct
30 Correct 120 ms 20172 KB Output is correct
31 Correct 67 ms 20152 KB Output is correct
32 Correct 67 ms 16576 KB Output is correct
33 Correct 71 ms 16492 KB Output is correct
34 Correct 80 ms 15292 KB Output is correct
35 Correct 86 ms 16064 KB Output is correct
36 Correct 121 ms 20252 KB Output is correct
37 Correct 90 ms 16504 KB Output is correct
38 Correct 97 ms 19908 KB Output is correct
39 Correct 70 ms 15176 KB Output is correct
40 Correct 79 ms 16060 KB Output is correct
41 Correct 104 ms 19308 KB Output is correct
42 Correct 124 ms 20264 KB Output is correct
43 Correct 98 ms 16832 KB Output is correct
44 Correct 125 ms 20160 KB Output is correct
45 Correct 83 ms 20628 KB Output is correct
46 Correct 72 ms 16884 KB Output is correct
47 Correct 73 ms 16832 KB Output is correct
48 Correct 98 ms 16480 KB Output is correct
49 Correct 121 ms 20408 KB Output is correct
50 Correct 84 ms 16572 KB Output is correct
51 Correct 89 ms 17600 KB Output is correct
52 Correct 100 ms 20508 KB Output is correct
53 Correct 72 ms 15556 KB Output is correct
54 Correct 92 ms 16572 KB Output is correct
55 Correct 120 ms 19640 KB Output is correct
56 Correct 123 ms 20508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 508 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 508 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 456 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 624 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 2 ms 592 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 1 ms 592 KB Output is correct
38 Correct 1 ms 592 KB Output is correct
39 Correct 1 ms 592 KB Output is correct
40 Correct 1 ms 472 KB Output is correct
41 Correct 1 ms 592 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 1 ms 592 KB Output is correct
44 Correct 1 ms 592 KB Output is correct
45 Correct 1 ms 592 KB Output is correct
46 Correct 2 ms 592 KB Output is correct
47 Correct 1 ms 592 KB Output is correct
48 Correct 1 ms 592 KB Output is correct
49 Correct 1 ms 592 KB Output is correct
50 Correct 1 ms 760 KB Output is correct
51 Correct 1 ms 476 KB Output is correct
52 Correct 1 ms 592 KB Output is correct
53 Correct 2 ms 760 KB Output is correct
54 Correct 1 ms 592 KB Output is correct
55 Correct 72 ms 15516 KB Output is correct
56 Correct 102 ms 20028 KB Output is correct
57 Correct 47 ms 19900 KB Output is correct
58 Correct 46 ms 15480 KB Output is correct
59 Correct 79 ms 15300 KB Output is correct
60 Correct 98 ms 19388 KB Output is correct
61 Correct 72 ms 15300 KB Output is correct
62 Correct 92 ms 19908 KB Output is correct
63 Correct 51 ms 14276 KB Output is correct
64 Correct 78 ms 15560 KB Output is correct
65 Correct 98 ms 20076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 504 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 1 ms 336 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 508 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 336 KB Output is correct
17 Correct 1 ms 336 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 508 KB Output is correct
20 Correct 1 ms 336 KB Output is correct
21 Correct 1 ms 336 KB Output is correct
22 Correct 1 ms 336 KB Output is correct
23 Correct 1 ms 336 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 336 KB Output is correct
27 Correct 1 ms 336 KB Output is correct
28 Correct 1 ms 456 KB Output is correct
29 Correct 2 ms 592 KB Output is correct
30 Correct 1 ms 592 KB Output is correct
31 Correct 1 ms 592 KB Output is correct
32 Correct 1 ms 624 KB Output is correct
33 Correct 1 ms 592 KB Output is correct
34 Correct 1 ms 592 KB Output is correct
35 Correct 2 ms 592 KB Output is correct
36 Correct 2 ms 592 KB Output is correct
37 Correct 1 ms 592 KB Output is correct
38 Correct 1 ms 592 KB Output is correct
39 Correct 1 ms 592 KB Output is correct
40 Correct 1 ms 472 KB Output is correct
41 Correct 1 ms 592 KB Output is correct
42 Correct 1 ms 596 KB Output is correct
43 Correct 1 ms 592 KB Output is correct
44 Correct 1 ms 592 KB Output is correct
45 Correct 1 ms 592 KB Output is correct
46 Correct 2 ms 592 KB Output is correct
47 Correct 1 ms 592 KB Output is correct
48 Correct 1 ms 592 KB Output is correct
49 Correct 1 ms 592 KB Output is correct
50 Correct 1 ms 760 KB Output is correct
51 Correct 1 ms 476 KB Output is correct
52 Correct 1 ms 592 KB Output is correct
53 Correct 2 ms 760 KB Output is correct
54 Correct 1 ms 592 KB Output is correct
55 Correct 96 ms 16576 KB Output is correct
56 Correct 120 ms 20172 KB Output is correct
57 Correct 67 ms 20152 KB Output is correct
58 Correct 67 ms 16576 KB Output is correct
59 Correct 71 ms 16492 KB Output is correct
60 Correct 80 ms 15292 KB Output is correct
61 Correct 86 ms 16064 KB Output is correct
62 Correct 121 ms 20252 KB Output is correct
63 Correct 90 ms 16504 KB Output is correct
64 Correct 97 ms 19908 KB Output is correct
65 Correct 70 ms 15176 KB Output is correct
66 Correct 79 ms 16060 KB Output is correct
67 Correct 104 ms 19308 KB Output is correct
68 Correct 124 ms 20264 KB Output is correct
69 Correct 98 ms 16832 KB Output is correct
70 Correct 125 ms 20160 KB Output is correct
71 Correct 83 ms 20628 KB Output is correct
72 Correct 72 ms 16884 KB Output is correct
73 Correct 73 ms 16832 KB Output is correct
74 Correct 98 ms 16480 KB Output is correct
75 Correct 121 ms 20408 KB Output is correct
76 Correct 84 ms 16572 KB Output is correct
77 Correct 89 ms 17600 KB Output is correct
78 Correct 100 ms 20508 KB Output is correct
79 Correct 72 ms 15556 KB Output is correct
80 Correct 92 ms 16572 KB Output is correct
81 Correct 120 ms 19640 KB Output is correct
82 Correct 123 ms 20508 KB Output is correct
83 Correct 72 ms 15516 KB Output is correct
84 Correct 102 ms 20028 KB Output is correct
85 Correct 47 ms 19900 KB Output is correct
86 Correct 46 ms 15480 KB Output is correct
87 Correct 79 ms 15300 KB Output is correct
88 Correct 98 ms 19388 KB Output is correct
89 Correct 72 ms 15300 KB Output is correct
90 Correct 92 ms 19908 KB Output is correct
91 Correct 51 ms 14276 KB Output is correct
92 Correct 78 ms 15560 KB Output is correct
93 Correct 98 ms 20076 KB Output is correct
94 Correct 97 ms 17576 KB Output is correct
95 Correct 133 ms 21192 KB Output is correct
96 Correct 74 ms 20924 KB Output is correct
97 Correct 72 ms 17600 KB Output is correct
98 Correct 78 ms 17716 KB Output is correct
99 Correct 88 ms 16900 KB Output is correct
100 Correct 113 ms 21432 KB Output is correct
101 Correct 88 ms 17340 KB Output is correct
102 Correct 98 ms 18380 KB Output is correct
103 Correct 107 ms 21432 KB Output is correct
104 Correct 80 ms 16576 KB Output is correct
105 Correct 118 ms 17860 KB Output is correct
106 Correct 128 ms 21172 KB Output is correct
107 Correct 60 ms 21436 KB Output is correct
108 Correct 98 ms 17412 KB Output is correct
109 Correct 98 ms 17272 KB Output is correct
110 Correct 99 ms 17344 KB Output is correct
111 Correct 102 ms 17352 KB Output is correct
112 Correct 103 ms 17344 KB Output is correct
113 Correct 98 ms 17344 KB Output is correct
114 Correct 99 ms 17352 KB Output is correct
115 Correct 99 ms 17400 KB Output is correct
116 Correct 99 ms 17280 KB Output is correct