Submission #877343

# Submission time Handle Problem Language Result Execution time Memory
877343 2023-11-23T07:12:27 Z damwuan Joker (BOI20_joker) C++17
100 / 100
175 ms 24548 KB


#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define for1(i,j,k) for(int i=j;i<=k;i++)
#define for2(i,j,k) for(int i=j;i>=k;i--)
#define for3(i,j,k,l) for(int i=j;i<=k;i+=l)
#define bit(n,i) ((n>>i)&1)
#define all(x) x.begin(),x.end()
//#pragma GCC optimize("O2,unroll-loops")
//#pragma GCC target("avx,avx2,bmi,bmi2,sse,sse2,sse3,ssse3,sse4,popcnt")
#define int long long
typedef long long ll;
typedef pair<int,int> pii;
typedef double ld;
typedef pair<ld,ld> pdd;
typedef pair<ll,ll> pll;
const ll maxn=3e5+69;
const ll offset=1e9;
const ll block_sz=317;
const ll inf=1e18;
const ll mod=1e9+7;
int n,m,q,par[maxn],col[maxn];
pii E[maxn];
int qr[maxn];
vector<pair<int,pii>> save;
pii Find(int u)
{
    int c=0;
    while (par[u]>0)
    {
        c^=col[u];
        u=par[u];
    }
    return {u,c};
}
bool Union(int u,int v)
{
    auto x=Find(u);
    u=x.fi;
    int cu=x.se;
    auto y=Find(v);
    v=y.fi;
    int cv=y.se;
    if (u==v)
    {
        if (cu==cv) return 0;
    }
    else
    {
        if (par[u]>par[v])
        {
            swap(u,v);
        }
        save.pb({v,{par[v],col[v]}});
        if (cu==cv)
        {
            col[v]=1;
        }
        else col[v]=0;
        par[u]+=par[v];
        par[v]=u;
    }
    return 1;
}
void undo(int x)
{
    while(save.size()>x)
    {
        int v=save.back().fi;
        int p=save.back().se.fi;
        int c=save.back().se.se;
        save.pop_back();
        int u=par[v];
        par[v]=p;
        col[v]=c;
        par[u]-=par[v];
    }
}
int dp[maxn];
void Compute(int l,int r,int optl, int optr)
{
    if (l>r) return;
    int snap2=save.size();
    int mid=l+r>>1;
    bool ok=1;
    for1(i,max(1LL,l),mid)
    {
        if (!Union(E[i].fi,E[i].se))
        {
            ok=0;
//            cerr<< "ads\n";
        }
    }
    int snap1=save.size();
    if (ok)
    {
        int opt=min(optr,m);
        while (opt>=max(optl,mid+1) &&Union(E[opt].fi,E[opt].se))
        {
            opt--;
        }
        dp[mid]=opt;
        undo(snap1);
        Compute(mid+1,r,dp[mid],optr);
    }
    undo(snap2);
    for2(i,optr,dp[mid]+1) Union(E[i].fi,E[i].se);
    Compute(l,mid-1,optl,dp[mid]);
    undo(snap2);
}
void sol()
{

    cin >> n>> m>> q;
    for1(i,1,n) par[i]=-1;
    for1(i,1,m)
    {
        cin >> E[i].fi>> E[i].se;
        dp[i]=m+1;
    }
    Compute(0,m,1,m+1);
//    for1(i,1,m) cout<< dp[i]<<' ';
    while (q--)
    {
        int l,r;cin>>l>>r;
        if (dp[l-1]>r )
        {
            cout << "YES\n";
        }
        else
        {
            cout << "NO\n";
        }
    }



}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
//    freopen("AAA.inp","r",stdin);
//    freopen("AAA.out","w",stdout);

    int t=1;//cin >> t;
    while (t--)
    {
        sol();
    }
}

/*
6 8 2
1 3
1 5
1 6
2 5
2 6
3 4
3 5
5 6


*/


Compilation message

Joker.cpp: In function 'void undo(long long int)':
Joker.cpp:72:22: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   72 |     while(save.size()>x)
      |           ~~~~~~~~~~~^~
Joker.cpp: In function 'void Compute(long long int, long long int, long long int, long long int)':
Joker.cpp:89:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   89 |     int mid=l+r>>1;
      |             ~^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6612 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 1 ms 6644 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6744 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6612 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 1 ms 6644 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6744 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 6488 KB Output is correct
30 Correct 2 ms 6744 KB Output is correct
31 Correct 2 ms 6752 KB Output is correct
32 Correct 2 ms 6748 KB Output is correct
33 Correct 2 ms 6744 KB Output is correct
34 Correct 2 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 2 ms 6748 KB Output is correct
37 Correct 2 ms 6748 KB Output is correct
38 Correct 3 ms 6744 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6624 KB Output is correct
43 Correct 3 ms 6492 KB Output is correct
44 Correct 3 ms 6748 KB Output is correct
45 Correct 2 ms 6632 KB Output is correct
46 Correct 2 ms 6748 KB Output is correct
47 Correct 2 ms 6744 KB Output is correct
48 Correct 2 ms 6748 KB Output is correct
49 Correct 2 ms 6748 KB Output is correct
50 Correct 2 ms 6636 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6748 KB Output is correct
53 Correct 2 ms 6748 KB Output is correct
54 Correct 2 ms 6748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 97 ms 14800 KB Output is correct
4 Correct 167 ms 22420 KB Output is correct
5 Correct 91 ms 22704 KB Output is correct
6 Correct 85 ms 18828 KB Output is correct
7 Correct 86 ms 18616 KB Output is correct
8 Correct 96 ms 16832 KB Output is correct
9 Correct 109 ms 18640 KB Output is correct
10 Correct 150 ms 23232 KB Output is correct
11 Correct 101 ms 18748 KB Output is correct
12 Correct 114 ms 23244 KB Output is correct
13 Correct 108 ms 16072 KB Output is correct
14 Correct 97 ms 17480 KB Output is correct
15 Correct 126 ms 19904 KB Output is correct
16 Correct 150 ms 22560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6612 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 1 ms 6644 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6744 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 97 ms 14800 KB Output is correct
30 Correct 167 ms 22420 KB Output is correct
31 Correct 91 ms 22704 KB Output is correct
32 Correct 85 ms 18828 KB Output is correct
33 Correct 86 ms 18616 KB Output is correct
34 Correct 96 ms 16832 KB Output is correct
35 Correct 109 ms 18640 KB Output is correct
36 Correct 150 ms 23232 KB Output is correct
37 Correct 101 ms 18748 KB Output is correct
38 Correct 114 ms 23244 KB Output is correct
39 Correct 108 ms 16072 KB Output is correct
40 Correct 97 ms 17480 KB Output is correct
41 Correct 126 ms 19904 KB Output is correct
42 Correct 150 ms 22560 KB Output is correct
43 Correct 100 ms 18956 KB Output is correct
44 Correct 175 ms 23060 KB Output is correct
45 Correct 145 ms 23444 KB Output is correct
46 Correct 82 ms 19128 KB Output is correct
47 Correct 84 ms 19504 KB Output is correct
48 Correct 115 ms 18560 KB Output is correct
49 Correct 141 ms 21960 KB Output is correct
50 Correct 127 ms 19428 KB Output is correct
51 Correct 111 ms 20156 KB Output is correct
52 Correct 118 ms 22720 KB Output is correct
53 Correct 104 ms 16264 KB Output is correct
54 Correct 113 ms 18944 KB Output is correct
55 Correct 126 ms 20156 KB Output is correct
56 Correct 140 ms 22936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6612 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 1 ms 6644 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6744 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 6488 KB Output is correct
30 Correct 2 ms 6744 KB Output is correct
31 Correct 2 ms 6752 KB Output is correct
32 Correct 2 ms 6748 KB Output is correct
33 Correct 2 ms 6744 KB Output is correct
34 Correct 2 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 2 ms 6748 KB Output is correct
37 Correct 2 ms 6748 KB Output is correct
38 Correct 3 ms 6744 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6624 KB Output is correct
43 Correct 3 ms 6492 KB Output is correct
44 Correct 3 ms 6748 KB Output is correct
45 Correct 2 ms 6632 KB Output is correct
46 Correct 2 ms 6748 KB Output is correct
47 Correct 2 ms 6744 KB Output is correct
48 Correct 2 ms 6748 KB Output is correct
49 Correct 2 ms 6748 KB Output is correct
50 Correct 2 ms 6636 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6748 KB Output is correct
53 Correct 2 ms 6748 KB Output is correct
54 Correct 2 ms 6748 KB Output is correct
55 Correct 73 ms 17092 KB Output is correct
56 Correct 137 ms 21652 KB Output is correct
57 Correct 64 ms 22400 KB Output is correct
58 Correct 61 ms 18628 KB Output is correct
59 Correct 87 ms 18436 KB Output is correct
60 Correct 107 ms 18128 KB Output is correct
61 Correct 86 ms 18200 KB Output is correct
62 Correct 89 ms 21904 KB Output is correct
63 Correct 82 ms 14948 KB Output is correct
64 Correct 99 ms 17604 KB Output is correct
65 Correct 117 ms 22136 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6492 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6492 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6612 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6488 KB Output is correct
16 Correct 1 ms 6488 KB Output is correct
17 Correct 1 ms 6644 KB Output is correct
18 Correct 2 ms 6492 KB Output is correct
19 Correct 1 ms 6492 KB Output is correct
20 Correct 1 ms 6492 KB Output is correct
21 Correct 1 ms 6492 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6744 KB Output is correct
24 Correct 1 ms 6492 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 1 ms 6492 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 2 ms 6488 KB Output is correct
30 Correct 2 ms 6744 KB Output is correct
31 Correct 2 ms 6752 KB Output is correct
32 Correct 2 ms 6748 KB Output is correct
33 Correct 2 ms 6744 KB Output is correct
34 Correct 2 ms 6748 KB Output is correct
35 Correct 2 ms 6748 KB Output is correct
36 Correct 2 ms 6748 KB Output is correct
37 Correct 2 ms 6748 KB Output is correct
38 Correct 3 ms 6744 KB Output is correct
39 Correct 2 ms 6748 KB Output is correct
40 Correct 2 ms 6492 KB Output is correct
41 Correct 2 ms 6492 KB Output is correct
42 Correct 2 ms 6624 KB Output is correct
43 Correct 3 ms 6492 KB Output is correct
44 Correct 3 ms 6748 KB Output is correct
45 Correct 2 ms 6632 KB Output is correct
46 Correct 2 ms 6748 KB Output is correct
47 Correct 2 ms 6744 KB Output is correct
48 Correct 2 ms 6748 KB Output is correct
49 Correct 2 ms 6748 KB Output is correct
50 Correct 2 ms 6636 KB Output is correct
51 Correct 2 ms 6492 KB Output is correct
52 Correct 2 ms 6748 KB Output is correct
53 Correct 2 ms 6748 KB Output is correct
54 Correct 2 ms 6748 KB Output is correct
55 Correct 97 ms 14800 KB Output is correct
56 Correct 167 ms 22420 KB Output is correct
57 Correct 91 ms 22704 KB Output is correct
58 Correct 85 ms 18828 KB Output is correct
59 Correct 86 ms 18616 KB Output is correct
60 Correct 96 ms 16832 KB Output is correct
61 Correct 109 ms 18640 KB Output is correct
62 Correct 150 ms 23232 KB Output is correct
63 Correct 101 ms 18748 KB Output is correct
64 Correct 114 ms 23244 KB Output is correct
65 Correct 108 ms 16072 KB Output is correct
66 Correct 97 ms 17480 KB Output is correct
67 Correct 126 ms 19904 KB Output is correct
68 Correct 150 ms 22560 KB Output is correct
69 Correct 100 ms 18956 KB Output is correct
70 Correct 175 ms 23060 KB Output is correct
71 Correct 145 ms 23444 KB Output is correct
72 Correct 82 ms 19128 KB Output is correct
73 Correct 84 ms 19504 KB Output is correct
74 Correct 115 ms 18560 KB Output is correct
75 Correct 141 ms 21960 KB Output is correct
76 Correct 127 ms 19428 KB Output is correct
77 Correct 111 ms 20156 KB Output is correct
78 Correct 118 ms 22720 KB Output is correct
79 Correct 104 ms 16264 KB Output is correct
80 Correct 113 ms 18944 KB Output is correct
81 Correct 126 ms 20156 KB Output is correct
82 Correct 140 ms 22936 KB Output is correct
83 Correct 73 ms 17092 KB Output is correct
84 Correct 137 ms 21652 KB Output is correct
85 Correct 64 ms 22400 KB Output is correct
86 Correct 61 ms 18628 KB Output is correct
87 Correct 87 ms 18436 KB Output is correct
88 Correct 107 ms 18128 KB Output is correct
89 Correct 86 ms 18200 KB Output is correct
90 Correct 89 ms 21904 KB Output is correct
91 Correct 82 ms 14948 KB Output is correct
92 Correct 99 ms 17604 KB Output is correct
93 Correct 117 ms 22136 KB Output is correct
94 Correct 110 ms 19644 KB Output is correct
95 Correct 136 ms 23336 KB Output is correct
96 Correct 97 ms 24412 KB Output is correct
97 Correct 89 ms 19832 KB Output is correct
98 Correct 101 ms 19816 KB Output is correct
99 Correct 118 ms 18412 KB Output is correct
100 Correct 123 ms 22392 KB Output is correct
101 Correct 110 ms 19120 KB Output is correct
102 Correct 119 ms 21184 KB Output is correct
103 Correct 135 ms 22500 KB Output is correct
104 Correct 103 ms 17868 KB Output is correct
105 Correct 128 ms 20344 KB Output is correct
106 Correct 148 ms 23156 KB Output is correct
107 Correct 97 ms 24548 KB Output is correct
108 Correct 100 ms 20076 KB Output is correct
109 Correct 99 ms 19584 KB Output is correct
110 Correct 102 ms 19648 KB Output is correct
111 Correct 99 ms 19388 KB Output is correct
112 Correct 102 ms 19552 KB Output is correct
113 Correct 102 ms 19604 KB Output is correct
114 Correct 112 ms 19696 KB Output is correct
115 Correct 100 ms 19556 KB Output is correct
116 Correct 102 ms 19748 KB Output is correct