Submission #914678

# Submission time Handle Problem Language Result Execution time Memory
914678 2024-01-22T14:07:54 Z Amr Joker (BOI20_joker) C++14
49 / 100
2000 ms 42360 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define S second
//#define F first
#define all(x) (x).begin(),(x).end()
#define sz size()
#define Yes cout << "YES" << endl
#define No cout << "NO" << endl
#define pb(x) push_back(x);
#define endl '\n'
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
const int N=3e5+7;
ll INF=INT_MAX,mod=1e9+7;
int TT=1;
ll power(ll x, unsigned int y)
{
    ll res = 1;
    x = x; // % mod;
    if (x == 0) return 0;
    while (y > 0)
    {
        if (y & 1) res = (res*x)  ; // % mod;
        y = y>>1;
        x = (x*x) ; // % mod;
    }
    return res;
}
ll n , m , q;
pair<ll,ll> p[N];
pair<ll,ll>  a[N];
vector<vector<ll> > qe(N,vector<ll> (3));
ll ans[N];
ll siz[N];
ll cycles = 0;
vector<vector<ll>> roll;
ll sqr = 4;
bool cmp(vector<ll> x, vector<ll> y)
{
    if(x[0]/sqr==y[0]/sqr) return x[1] < y[1];
    return x[0]<y[0];
}
pair<ll,ll> get(ll x)
{
    if(p[x].first==x) return {x,0};
    pair<ll,ll> ho = get(p[x].first);
    return {ho.first, p[x].second^ho.second};
}
void nonmerge(vector<ll> v)
{
    ll x= v[0] , y = v[1] , b = v[2];
    if(b)
    {
    siz[y] -= siz[x];
    p[x] = {x,0};
    return;
    }
    else
    {
        pair<ll,ll> paix = get(x);
        pair<ll,ll> paiy = get(y);
        if(paix.second==paiy.second) cycles--;
    }
}
void merg(ll x, ll y)
{

    pair<ll,ll> paix = get(x);
    pair<ll,ll> paiy = get(y);
    if(paix.first==paiy.first)
    {
        if(paix.second==paiy.second) cycles++;
        roll.push_back({x,y,0});
    }
    else
    {
        ll xx = paix.first , yy = paiy.first;
        if(siz[xx]<siz[yy])
        {
            p[xx] = {yy,(paix.second==paiy.second)};
            siz[yy] +=siz[xx];
            roll.push_back({xx,yy,1});
        }
        else
        {
            p[yy] = {xx,(paix.second==paiy.second)};
            siz[xx]+=siz[yy];
            roll.push_back({yy,xx,1});
        }
    }
}
void solve()
{

    cin >> n >> m >> q;
    sqr = max(2LL,m/int(sqrt(q)));
    for(int i = 1; i <= n; i++) p[i] = {i,0},siz[i] = 1;
    for(int i = 1; i <= m; i++) cin >> a[i].first >> a[i].second;
    for(int i = 1; i <= q; i++)
    {
        cin >> qe[i][0] >> qe[i][1];
    }
    for(int i = 1; i <= q; i++) qe[i][2] = i;
    sort(qe.begin()+1,qe.begin()+q+1,cmp);
    //for(int i = 1; i <= q; i++) cout << qe[i][1] << " "; cout << endl;
    ll st = 0, en = m+1;
    for(int i = 1; i <= q; i++)
    {
        ll l = qe[i][0] , r = qe[i][1];
        while(roll.sz&&st>0)
        {
            //
            nonmerge(roll.back());
            roll.pop_back();
            st--;
        }

        while(roll.sz&&en<=r)
        {
            //
            nonmerge(roll.back());
            roll.pop_back();
            en++;
        }
        while(en>r+1)
        {
            en--;
            merg(a[en].first,a[en].second);

            // mege en
        }
        while(st<l-1)
        {
            st++;
            merg(a[st].first,a[st].second);
          //  cout << cycles << endl;
            // merge st;
        }
        //cout << endl;
        //for(int i = 1; i <= n; i++) cout << p[i].first << " " << p[i].second << endl;
       // cout << l << " " << r << ": " << st << " " << en<< " " << cycles  << endl;
         ans[qe[i][2]] = bool(cycles);
    }
    for(int i = 1; i <= q; i++)
    {
        if(ans[i]) Yes; else No;
    }
}
int main(){
    //freopen("friday.in","r",stdin);
    //freopen("friday.out","w",stdout);
    fast;
    //cin >> TT;
    while(TT--)
        solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 15 ms 22876 KB Output is correct
2 Correct 14 ms 22956 KB Output is correct
3 Correct 20 ms 23132 KB Output is correct
4 Correct 14 ms 22876 KB Output is correct
5 Correct 14 ms 23064 KB Output is correct
6 Correct 14 ms 22876 KB Output is correct
7 Correct 14 ms 23036 KB Output is correct
8 Correct 15 ms 22872 KB Output is correct
9 Correct 15 ms 22876 KB Output is correct
10 Correct 15 ms 23040 KB Output is correct
11 Correct 15 ms 22872 KB Output is correct
12 Correct 16 ms 22876 KB Output is correct
13 Correct 15 ms 22876 KB Output is correct
14 Correct 15 ms 22876 KB Output is correct
15 Correct 16 ms 22876 KB Output is correct
16 Correct 15 ms 22840 KB Output is correct
17 Correct 15 ms 22876 KB Output is correct
18 Correct 16 ms 23128 KB Output is correct
19 Correct 16 ms 22876 KB Output is correct
20 Correct 16 ms 22848 KB Output is correct
21 Correct 16 ms 22876 KB Output is correct
22 Correct 16 ms 23064 KB Output is correct
23 Correct 16 ms 22876 KB Output is correct
24 Correct 16 ms 22872 KB Output is correct
25 Correct 19 ms 23132 KB Output is correct
26 Correct 16 ms 22832 KB Output is correct
27 Correct 16 ms 22872 KB Output is correct
28 Correct 15 ms 22932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 22876 KB Output is correct
2 Correct 14 ms 22956 KB Output is correct
3 Correct 20 ms 23132 KB Output is correct
4 Correct 14 ms 22876 KB Output is correct
5 Correct 14 ms 23064 KB Output is correct
6 Correct 14 ms 22876 KB Output is correct
7 Correct 14 ms 23036 KB Output is correct
8 Correct 15 ms 22872 KB Output is correct
9 Correct 15 ms 22876 KB Output is correct
10 Correct 15 ms 23040 KB Output is correct
11 Correct 15 ms 22872 KB Output is correct
12 Correct 16 ms 22876 KB Output is correct
13 Correct 15 ms 22876 KB Output is correct
14 Correct 15 ms 22876 KB Output is correct
15 Correct 16 ms 22876 KB Output is correct
16 Correct 15 ms 22840 KB Output is correct
17 Correct 15 ms 22876 KB Output is correct
18 Correct 16 ms 23128 KB Output is correct
19 Correct 16 ms 22876 KB Output is correct
20 Correct 16 ms 22848 KB Output is correct
21 Correct 16 ms 22876 KB Output is correct
22 Correct 16 ms 23064 KB Output is correct
23 Correct 16 ms 22876 KB Output is correct
24 Correct 16 ms 22872 KB Output is correct
25 Correct 19 ms 23132 KB Output is correct
26 Correct 16 ms 22832 KB Output is correct
27 Correct 16 ms 22872 KB Output is correct
28 Correct 15 ms 22932 KB Output is correct
29 Correct 57 ms 22876 KB Output is correct
30 Correct 97 ms 23128 KB Output is correct
31 Correct 125 ms 23320 KB Output is correct
32 Correct 134 ms 23132 KB Output is correct
33 Correct 149 ms 23128 KB Output is correct
34 Correct 116 ms 23176 KB Output is correct
35 Correct 121 ms 23172 KB Output is correct
36 Correct 106 ms 23172 KB Output is correct
37 Correct 101 ms 23132 KB Output is correct
38 Correct 100 ms 23128 KB Output is correct
39 Correct 103 ms 23132 KB Output is correct
40 Correct 128 ms 23128 KB Output is correct
41 Correct 126 ms 23128 KB Output is correct
42 Correct 121 ms 23160 KB Output is correct
43 Correct 164 ms 23380 KB Output is correct
44 Correct 157 ms 23132 KB Output is correct
45 Correct 146 ms 23132 KB Output is correct
46 Correct 130 ms 23128 KB Output is correct
47 Correct 125 ms 23160 KB Output is correct
48 Correct 127 ms 23128 KB Output is correct
49 Correct 117 ms 23132 KB Output is correct
50 Correct 109 ms 23152 KB Output is correct
51 Correct 150 ms 23376 KB Output is correct
52 Correct 137 ms 23128 KB Output is correct
53 Correct 128 ms 23128 KB Output is correct
54 Correct 118 ms 23132 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 22876 KB Output is correct
2 Correct 14 ms 22956 KB Output is correct
3 Correct 244 ms 41060 KB Output is correct
4 Correct 223 ms 42008 KB Output is correct
5 Correct 235 ms 41004 KB Output is correct
6 Correct 215 ms 41208 KB Output is correct
7 Correct 245 ms 40952 KB Output is correct
8 Correct 273 ms 39264 KB Output is correct
9 Correct 221 ms 41728 KB Output is correct
10 Correct 238 ms 41464 KB Output is correct
11 Correct 224 ms 40952 KB Output is correct
12 Correct 228 ms 41568 KB Output is correct
13 Correct 221 ms 36856 KB Output is correct
14 Correct 224 ms 39252 KB Output is correct
15 Correct 242 ms 40956 KB Output is correct
16 Correct 234 ms 42128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 22876 KB Output is correct
2 Correct 14 ms 22956 KB Output is correct
3 Correct 20 ms 23132 KB Output is correct
4 Correct 14 ms 22876 KB Output is correct
5 Correct 14 ms 23064 KB Output is correct
6 Correct 14 ms 22876 KB Output is correct
7 Correct 14 ms 23036 KB Output is correct
8 Correct 15 ms 22872 KB Output is correct
9 Correct 15 ms 22876 KB Output is correct
10 Correct 15 ms 23040 KB Output is correct
11 Correct 15 ms 22872 KB Output is correct
12 Correct 16 ms 22876 KB Output is correct
13 Correct 15 ms 22876 KB Output is correct
14 Correct 15 ms 22876 KB Output is correct
15 Correct 16 ms 22876 KB Output is correct
16 Correct 15 ms 22840 KB Output is correct
17 Correct 15 ms 22876 KB Output is correct
18 Correct 16 ms 23128 KB Output is correct
19 Correct 16 ms 22876 KB Output is correct
20 Correct 16 ms 22848 KB Output is correct
21 Correct 16 ms 22876 KB Output is correct
22 Correct 16 ms 23064 KB Output is correct
23 Correct 16 ms 22876 KB Output is correct
24 Correct 16 ms 22872 KB Output is correct
25 Correct 19 ms 23132 KB Output is correct
26 Correct 16 ms 22832 KB Output is correct
27 Correct 16 ms 22872 KB Output is correct
28 Correct 15 ms 22932 KB Output is correct
29 Correct 244 ms 41060 KB Output is correct
30 Correct 223 ms 42008 KB Output is correct
31 Correct 235 ms 41004 KB Output is correct
32 Correct 215 ms 41208 KB Output is correct
33 Correct 245 ms 40952 KB Output is correct
34 Correct 273 ms 39264 KB Output is correct
35 Correct 221 ms 41728 KB Output is correct
36 Correct 238 ms 41464 KB Output is correct
37 Correct 224 ms 40952 KB Output is correct
38 Correct 228 ms 41568 KB Output is correct
39 Correct 221 ms 36856 KB Output is correct
40 Correct 224 ms 39252 KB Output is correct
41 Correct 242 ms 40956 KB Output is correct
42 Correct 234 ms 42128 KB Output is correct
43 Correct 1117 ms 41676 KB Output is correct
44 Correct 1027 ms 42360 KB Output is correct
45 Correct 1041 ms 42120 KB Output is correct
46 Correct 1101 ms 42228 KB Output is correct
47 Correct 1124 ms 41072 KB Output is correct
48 Correct 1286 ms 42196 KB Output is correct
49 Correct 1236 ms 41140 KB Output is correct
50 Correct 1240 ms 42020 KB Output is correct
51 Correct 1141 ms 41948 KB Output is correct
52 Correct 1098 ms 41976 KB Output is correct
53 Correct 1305 ms 37216 KB Output is correct
54 Correct 1139 ms 41072 KB Output is correct
55 Correct 1105 ms 42024 KB Output is correct
56 Correct 1076 ms 42188 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 22876 KB Output is correct
2 Correct 14 ms 22956 KB Output is correct
3 Correct 20 ms 23132 KB Output is correct
4 Correct 14 ms 22876 KB Output is correct
5 Correct 14 ms 23064 KB Output is correct
6 Correct 14 ms 22876 KB Output is correct
7 Correct 14 ms 23036 KB Output is correct
8 Correct 15 ms 22872 KB Output is correct
9 Correct 15 ms 22876 KB Output is correct
10 Correct 15 ms 23040 KB Output is correct
11 Correct 15 ms 22872 KB Output is correct
12 Correct 16 ms 22876 KB Output is correct
13 Correct 15 ms 22876 KB Output is correct
14 Correct 15 ms 22876 KB Output is correct
15 Correct 16 ms 22876 KB Output is correct
16 Correct 15 ms 22840 KB Output is correct
17 Correct 15 ms 22876 KB Output is correct
18 Correct 16 ms 23128 KB Output is correct
19 Correct 16 ms 22876 KB Output is correct
20 Correct 16 ms 22848 KB Output is correct
21 Correct 16 ms 22876 KB Output is correct
22 Correct 16 ms 23064 KB Output is correct
23 Correct 16 ms 22876 KB Output is correct
24 Correct 16 ms 22872 KB Output is correct
25 Correct 19 ms 23132 KB Output is correct
26 Correct 16 ms 22832 KB Output is correct
27 Correct 16 ms 22872 KB Output is correct
28 Correct 15 ms 22932 KB Output is correct
29 Correct 57 ms 22876 KB Output is correct
30 Correct 97 ms 23128 KB Output is correct
31 Correct 125 ms 23320 KB Output is correct
32 Correct 134 ms 23132 KB Output is correct
33 Correct 149 ms 23128 KB Output is correct
34 Correct 116 ms 23176 KB Output is correct
35 Correct 121 ms 23172 KB Output is correct
36 Correct 106 ms 23172 KB Output is correct
37 Correct 101 ms 23132 KB Output is correct
38 Correct 100 ms 23128 KB Output is correct
39 Correct 103 ms 23132 KB Output is correct
40 Correct 128 ms 23128 KB Output is correct
41 Correct 126 ms 23128 KB Output is correct
42 Correct 121 ms 23160 KB Output is correct
43 Correct 164 ms 23380 KB Output is correct
44 Correct 157 ms 23132 KB Output is correct
45 Correct 146 ms 23132 KB Output is correct
46 Correct 130 ms 23128 KB Output is correct
47 Correct 125 ms 23160 KB Output is correct
48 Correct 127 ms 23128 KB Output is correct
49 Correct 117 ms 23132 KB Output is correct
50 Correct 109 ms 23152 KB Output is correct
51 Correct 150 ms 23376 KB Output is correct
52 Correct 137 ms 23128 KB Output is correct
53 Correct 128 ms 23128 KB Output is correct
54 Correct 118 ms 23132 KB Output is correct
55 Execution timed out 2040 ms 41452 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 15 ms 22876 KB Output is correct
2 Correct 14 ms 22956 KB Output is correct
3 Correct 20 ms 23132 KB Output is correct
4 Correct 14 ms 22876 KB Output is correct
5 Correct 14 ms 23064 KB Output is correct
6 Correct 14 ms 22876 KB Output is correct
7 Correct 14 ms 23036 KB Output is correct
8 Correct 15 ms 22872 KB Output is correct
9 Correct 15 ms 22876 KB Output is correct
10 Correct 15 ms 23040 KB Output is correct
11 Correct 15 ms 22872 KB Output is correct
12 Correct 16 ms 22876 KB Output is correct
13 Correct 15 ms 22876 KB Output is correct
14 Correct 15 ms 22876 KB Output is correct
15 Correct 16 ms 22876 KB Output is correct
16 Correct 15 ms 22840 KB Output is correct
17 Correct 15 ms 22876 KB Output is correct
18 Correct 16 ms 23128 KB Output is correct
19 Correct 16 ms 22876 KB Output is correct
20 Correct 16 ms 22848 KB Output is correct
21 Correct 16 ms 22876 KB Output is correct
22 Correct 16 ms 23064 KB Output is correct
23 Correct 16 ms 22876 KB Output is correct
24 Correct 16 ms 22872 KB Output is correct
25 Correct 19 ms 23132 KB Output is correct
26 Correct 16 ms 22832 KB Output is correct
27 Correct 16 ms 22872 KB Output is correct
28 Correct 15 ms 22932 KB Output is correct
29 Correct 57 ms 22876 KB Output is correct
30 Correct 97 ms 23128 KB Output is correct
31 Correct 125 ms 23320 KB Output is correct
32 Correct 134 ms 23132 KB Output is correct
33 Correct 149 ms 23128 KB Output is correct
34 Correct 116 ms 23176 KB Output is correct
35 Correct 121 ms 23172 KB Output is correct
36 Correct 106 ms 23172 KB Output is correct
37 Correct 101 ms 23132 KB Output is correct
38 Correct 100 ms 23128 KB Output is correct
39 Correct 103 ms 23132 KB Output is correct
40 Correct 128 ms 23128 KB Output is correct
41 Correct 126 ms 23128 KB Output is correct
42 Correct 121 ms 23160 KB Output is correct
43 Correct 164 ms 23380 KB Output is correct
44 Correct 157 ms 23132 KB Output is correct
45 Correct 146 ms 23132 KB Output is correct
46 Correct 130 ms 23128 KB Output is correct
47 Correct 125 ms 23160 KB Output is correct
48 Correct 127 ms 23128 KB Output is correct
49 Correct 117 ms 23132 KB Output is correct
50 Correct 109 ms 23152 KB Output is correct
51 Correct 150 ms 23376 KB Output is correct
52 Correct 137 ms 23128 KB Output is correct
53 Correct 128 ms 23128 KB Output is correct
54 Correct 118 ms 23132 KB Output is correct
55 Correct 244 ms 41060 KB Output is correct
56 Correct 223 ms 42008 KB Output is correct
57 Correct 235 ms 41004 KB Output is correct
58 Correct 215 ms 41208 KB Output is correct
59 Correct 245 ms 40952 KB Output is correct
60 Correct 273 ms 39264 KB Output is correct
61 Correct 221 ms 41728 KB Output is correct
62 Correct 238 ms 41464 KB Output is correct
63 Correct 224 ms 40952 KB Output is correct
64 Correct 228 ms 41568 KB Output is correct
65 Correct 221 ms 36856 KB Output is correct
66 Correct 224 ms 39252 KB Output is correct
67 Correct 242 ms 40956 KB Output is correct
68 Correct 234 ms 42128 KB Output is correct
69 Correct 1117 ms 41676 KB Output is correct
70 Correct 1027 ms 42360 KB Output is correct
71 Correct 1041 ms 42120 KB Output is correct
72 Correct 1101 ms 42228 KB Output is correct
73 Correct 1124 ms 41072 KB Output is correct
74 Correct 1286 ms 42196 KB Output is correct
75 Correct 1236 ms 41140 KB Output is correct
76 Correct 1240 ms 42020 KB Output is correct
77 Correct 1141 ms 41948 KB Output is correct
78 Correct 1098 ms 41976 KB Output is correct
79 Correct 1305 ms 37216 KB Output is correct
80 Correct 1139 ms 41072 KB Output is correct
81 Correct 1105 ms 42024 KB Output is correct
82 Correct 1076 ms 42188 KB Output is correct
83 Execution timed out 2040 ms 41452 KB Time limit exceeded
84 Halted 0 ms 0 KB -