Submission #915799

# Submission time Handle Problem Language Result Execution time Memory
915799 2024-01-24T17:45:12 Z Amr Joker (BOI20_joker) C++14
71 / 100
2000 ms 32256 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=2e5+7;
#define ll int
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==1)
    {
    siz[y] -= siz[x];
    p[x] = {x,0};
    return;
    }
    else
    {
        if(b==2) cycles--; return;
    }
}
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,2});}
        else
        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(1,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++)
    {
        if(i!=1&&qe[i-1][0]/sqr!=qe[i][0]/sqr)
        {
            while(roll.sz)
            {
            nonmerge(roll.back());
            roll.pop_back();
            }
        st = 0, en = m+1;
        while((st+1)/sqr<qe[i][0]/sqr)
        {

            st++;
            merg(a[st].first,a[st].second);
        }
        }
        ll l = qe[i][0] , r = qe[i][1];


        while(roll.sz&&st!=0&&st/sqr>=l/sqr)
        {
            //
            nonmerge(roll.back());
            roll.pop_back();
            st--;
        }
        //cout << 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;
}

Compilation message

Joker.cpp: In function 'void nonmerge(std::vector<int>)':
Joker.cpp:62:9: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   62 |         if(b==2) cycles--; return;
      |         ^~
Joker.cpp:62:28: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   62 |         if(b==2) cycles--; return;
      |                            ^~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15452 KB Output is correct
2 Correct 11 ms 15452 KB Output is correct
3 Correct 11 ms 15452 KB Output is correct
4 Correct 11 ms 15448 KB Output is correct
5 Correct 14 ms 15452 KB Output is correct
6 Correct 11 ms 15452 KB Output is correct
7 Correct 10 ms 15452 KB Output is correct
8 Correct 10 ms 15372 KB Output is correct
9 Correct 10 ms 15452 KB Output is correct
10 Correct 11 ms 15416 KB Output is correct
11 Correct 11 ms 15452 KB Output is correct
12 Correct 10 ms 15452 KB Output is correct
13 Correct 11 ms 15452 KB Output is correct
14 Correct 11 ms 15448 KB Output is correct
15 Correct 10 ms 15452 KB Output is correct
16 Correct 11 ms 15452 KB Output is correct
17 Correct 11 ms 15452 KB Output is correct
18 Correct 10 ms 15452 KB Output is correct
19 Correct 14 ms 15452 KB Output is correct
20 Correct 11 ms 15704 KB Output is correct
21 Correct 11 ms 15704 KB Output is correct
22 Correct 12 ms 15448 KB Output is correct
23 Correct 10 ms 15452 KB Output is correct
24 Correct 10 ms 15452 KB Output is correct
25 Correct 10 ms 15444 KB Output is correct
26 Correct 11 ms 15452 KB Output is correct
27 Correct 10 ms 15452 KB Output is correct
28 Correct 11 ms 15452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15452 KB Output is correct
2 Correct 11 ms 15452 KB Output is correct
3 Correct 11 ms 15452 KB Output is correct
4 Correct 11 ms 15448 KB Output is correct
5 Correct 14 ms 15452 KB Output is correct
6 Correct 11 ms 15452 KB Output is correct
7 Correct 10 ms 15452 KB Output is correct
8 Correct 10 ms 15372 KB Output is correct
9 Correct 10 ms 15452 KB Output is correct
10 Correct 11 ms 15416 KB Output is correct
11 Correct 11 ms 15452 KB Output is correct
12 Correct 10 ms 15452 KB Output is correct
13 Correct 11 ms 15452 KB Output is correct
14 Correct 11 ms 15448 KB Output is correct
15 Correct 10 ms 15452 KB Output is correct
16 Correct 11 ms 15452 KB Output is correct
17 Correct 11 ms 15452 KB Output is correct
18 Correct 10 ms 15452 KB Output is correct
19 Correct 14 ms 15452 KB Output is correct
20 Correct 11 ms 15704 KB Output is correct
21 Correct 11 ms 15704 KB Output is correct
22 Correct 12 ms 15448 KB Output is correct
23 Correct 10 ms 15452 KB Output is correct
24 Correct 10 ms 15452 KB Output is correct
25 Correct 10 ms 15444 KB Output is correct
26 Correct 11 ms 15452 KB Output is correct
27 Correct 10 ms 15452 KB Output is correct
28 Correct 11 ms 15452 KB Output is correct
29 Correct 15 ms 15452 KB Output is correct
30 Correct 17 ms 15536 KB Output is correct
31 Correct 21 ms 15452 KB Output is correct
32 Correct 18 ms 15656 KB Output is correct
33 Correct 18 ms 15452 KB Output is correct
34 Correct 19 ms 15656 KB Output is correct
35 Correct 19 ms 15652 KB Output is correct
36 Correct 17 ms 15640 KB Output is correct
37 Correct 18 ms 15652 KB Output is correct
38 Correct 19 ms 15448 KB Output is correct
39 Correct 20 ms 15452 KB Output is correct
40 Correct 25 ms 15644 KB Output is correct
41 Correct 22 ms 15452 KB Output is correct
42 Correct 18 ms 15652 KB Output is correct
43 Correct 20 ms 15448 KB Output is correct
44 Correct 19 ms 15452 KB Output is correct
45 Correct 20 ms 15652 KB Output is correct
46 Correct 20 ms 15452 KB Output is correct
47 Correct 19 ms 15448 KB Output is correct
48 Correct 19 ms 15452 KB Output is correct
49 Correct 19 ms 15620 KB Output is correct
50 Correct 19 ms 15452 KB Output is correct
51 Correct 20 ms 15452 KB Output is correct
52 Correct 19 ms 15452 KB Output is correct
53 Correct 19 ms 15452 KB Output is correct
54 Correct 19 ms 15452 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15452 KB Output is correct
2 Correct 11 ms 15452 KB Output is correct
3 Correct 261 ms 28412 KB Output is correct
4 Correct 223 ms 28916 KB Output is correct
5 Correct 222 ms 27912 KB Output is correct
6 Correct 253 ms 27384 KB Output is correct
7 Correct 246 ms 28416 KB Output is correct
8 Correct 221 ms 27888 KB Output is correct
9 Correct 238 ms 28412 KB Output is correct
10 Correct 243 ms 28928 KB Output is correct
11 Correct 233 ms 28156 KB Output is correct
12 Correct 225 ms 28164 KB Output is correct
13 Correct 239 ms 28048 KB Output is correct
14 Correct 264 ms 27888 KB Output is correct
15 Correct 230 ms 27636 KB Output is correct
16 Correct 239 ms 28920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15452 KB Output is correct
2 Correct 11 ms 15452 KB Output is correct
3 Correct 11 ms 15452 KB Output is correct
4 Correct 11 ms 15448 KB Output is correct
5 Correct 14 ms 15452 KB Output is correct
6 Correct 11 ms 15452 KB Output is correct
7 Correct 10 ms 15452 KB Output is correct
8 Correct 10 ms 15372 KB Output is correct
9 Correct 10 ms 15452 KB Output is correct
10 Correct 11 ms 15416 KB Output is correct
11 Correct 11 ms 15452 KB Output is correct
12 Correct 10 ms 15452 KB Output is correct
13 Correct 11 ms 15452 KB Output is correct
14 Correct 11 ms 15448 KB Output is correct
15 Correct 10 ms 15452 KB Output is correct
16 Correct 11 ms 15452 KB Output is correct
17 Correct 11 ms 15452 KB Output is correct
18 Correct 10 ms 15452 KB Output is correct
19 Correct 14 ms 15452 KB Output is correct
20 Correct 11 ms 15704 KB Output is correct
21 Correct 11 ms 15704 KB Output is correct
22 Correct 12 ms 15448 KB Output is correct
23 Correct 10 ms 15452 KB Output is correct
24 Correct 10 ms 15452 KB Output is correct
25 Correct 10 ms 15444 KB Output is correct
26 Correct 11 ms 15452 KB Output is correct
27 Correct 10 ms 15452 KB Output is correct
28 Correct 11 ms 15452 KB Output is correct
29 Correct 261 ms 28412 KB Output is correct
30 Correct 223 ms 28916 KB Output is correct
31 Correct 222 ms 27912 KB Output is correct
32 Correct 253 ms 27384 KB Output is correct
33 Correct 246 ms 28416 KB Output is correct
34 Correct 221 ms 27888 KB Output is correct
35 Correct 238 ms 28412 KB Output is correct
36 Correct 243 ms 28928 KB Output is correct
37 Correct 233 ms 28156 KB Output is correct
38 Correct 225 ms 28164 KB Output is correct
39 Correct 239 ms 28048 KB Output is correct
40 Correct 264 ms 27888 KB Output is correct
41 Correct 230 ms 27636 KB Output is correct
42 Correct 239 ms 28920 KB Output is correct
43 Correct 1114 ms 27632 KB Output is correct
44 Correct 1124 ms 27704 KB Output is correct
45 Correct 1095 ms 28696 KB Output is correct
46 Correct 1059 ms 27388 KB Output is correct
47 Correct 1144 ms 27376 KB Output is correct
48 Correct 1194 ms 27412 KB Output is correct
49 Correct 1237 ms 27644 KB Output is correct
50 Correct 1130 ms 27384 KB Output is correct
51 Correct 1174 ms 27848 KB Output is correct
52 Correct 1159 ms 28564 KB Output is correct
53 Correct 1144 ms 27648 KB Output is correct
54 Correct 1186 ms 27640 KB Output is correct
55 Correct 1148 ms 28656 KB Output is correct
56 Correct 1196 ms 27904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15452 KB Output is correct
2 Correct 11 ms 15452 KB Output is correct
3 Correct 11 ms 15452 KB Output is correct
4 Correct 11 ms 15448 KB Output is correct
5 Correct 14 ms 15452 KB Output is correct
6 Correct 11 ms 15452 KB Output is correct
7 Correct 10 ms 15452 KB Output is correct
8 Correct 10 ms 15372 KB Output is correct
9 Correct 10 ms 15452 KB Output is correct
10 Correct 11 ms 15416 KB Output is correct
11 Correct 11 ms 15452 KB Output is correct
12 Correct 10 ms 15452 KB Output is correct
13 Correct 11 ms 15452 KB Output is correct
14 Correct 11 ms 15448 KB Output is correct
15 Correct 10 ms 15452 KB Output is correct
16 Correct 11 ms 15452 KB Output is correct
17 Correct 11 ms 15452 KB Output is correct
18 Correct 10 ms 15452 KB Output is correct
19 Correct 14 ms 15452 KB Output is correct
20 Correct 11 ms 15704 KB Output is correct
21 Correct 11 ms 15704 KB Output is correct
22 Correct 12 ms 15448 KB Output is correct
23 Correct 10 ms 15452 KB Output is correct
24 Correct 10 ms 15452 KB Output is correct
25 Correct 10 ms 15444 KB Output is correct
26 Correct 11 ms 15452 KB Output is correct
27 Correct 10 ms 15452 KB Output is correct
28 Correct 11 ms 15452 KB Output is correct
29 Correct 15 ms 15452 KB Output is correct
30 Correct 17 ms 15536 KB Output is correct
31 Correct 21 ms 15452 KB Output is correct
32 Correct 18 ms 15656 KB Output is correct
33 Correct 18 ms 15452 KB Output is correct
34 Correct 19 ms 15656 KB Output is correct
35 Correct 19 ms 15652 KB Output is correct
36 Correct 17 ms 15640 KB Output is correct
37 Correct 18 ms 15652 KB Output is correct
38 Correct 19 ms 15448 KB Output is correct
39 Correct 20 ms 15452 KB Output is correct
40 Correct 25 ms 15644 KB Output is correct
41 Correct 22 ms 15452 KB Output is correct
42 Correct 18 ms 15652 KB Output is correct
43 Correct 20 ms 15448 KB Output is correct
44 Correct 19 ms 15452 KB Output is correct
45 Correct 20 ms 15652 KB Output is correct
46 Correct 20 ms 15452 KB Output is correct
47 Correct 19 ms 15448 KB Output is correct
48 Correct 19 ms 15452 KB Output is correct
49 Correct 19 ms 15620 KB Output is correct
50 Correct 19 ms 15452 KB Output is correct
51 Correct 20 ms 15452 KB Output is correct
52 Correct 19 ms 15452 KB Output is correct
53 Correct 19 ms 15452 KB Output is correct
54 Correct 19 ms 15452 KB Output is correct
55 Correct 816 ms 27652 KB Output is correct
56 Correct 888 ms 30528 KB Output is correct
57 Correct 987 ms 30444 KB Output is correct
58 Correct 1037 ms 29572 KB Output is correct
59 Correct 1309 ms 29948 KB Output is correct
60 Correct 1327 ms 29932 KB Output is correct
61 Correct 985 ms 30676 KB Output is correct
62 Correct 1106 ms 30320 KB Output is correct
63 Correct 1087 ms 29552 KB Output is correct
64 Correct 1434 ms 30044 KB Output is correct
65 Correct 1253 ms 30324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 15452 KB Output is correct
2 Correct 11 ms 15452 KB Output is correct
3 Correct 11 ms 15452 KB Output is correct
4 Correct 11 ms 15448 KB Output is correct
5 Correct 14 ms 15452 KB Output is correct
6 Correct 11 ms 15452 KB Output is correct
7 Correct 10 ms 15452 KB Output is correct
8 Correct 10 ms 15372 KB Output is correct
9 Correct 10 ms 15452 KB Output is correct
10 Correct 11 ms 15416 KB Output is correct
11 Correct 11 ms 15452 KB Output is correct
12 Correct 10 ms 15452 KB Output is correct
13 Correct 11 ms 15452 KB Output is correct
14 Correct 11 ms 15448 KB Output is correct
15 Correct 10 ms 15452 KB Output is correct
16 Correct 11 ms 15452 KB Output is correct
17 Correct 11 ms 15452 KB Output is correct
18 Correct 10 ms 15452 KB Output is correct
19 Correct 14 ms 15452 KB Output is correct
20 Correct 11 ms 15704 KB Output is correct
21 Correct 11 ms 15704 KB Output is correct
22 Correct 12 ms 15448 KB Output is correct
23 Correct 10 ms 15452 KB Output is correct
24 Correct 10 ms 15452 KB Output is correct
25 Correct 10 ms 15444 KB Output is correct
26 Correct 11 ms 15452 KB Output is correct
27 Correct 10 ms 15452 KB Output is correct
28 Correct 11 ms 15452 KB Output is correct
29 Correct 15 ms 15452 KB Output is correct
30 Correct 17 ms 15536 KB Output is correct
31 Correct 21 ms 15452 KB Output is correct
32 Correct 18 ms 15656 KB Output is correct
33 Correct 18 ms 15452 KB Output is correct
34 Correct 19 ms 15656 KB Output is correct
35 Correct 19 ms 15652 KB Output is correct
36 Correct 17 ms 15640 KB Output is correct
37 Correct 18 ms 15652 KB Output is correct
38 Correct 19 ms 15448 KB Output is correct
39 Correct 20 ms 15452 KB Output is correct
40 Correct 25 ms 15644 KB Output is correct
41 Correct 22 ms 15452 KB Output is correct
42 Correct 18 ms 15652 KB Output is correct
43 Correct 20 ms 15448 KB Output is correct
44 Correct 19 ms 15452 KB Output is correct
45 Correct 20 ms 15652 KB Output is correct
46 Correct 20 ms 15452 KB Output is correct
47 Correct 19 ms 15448 KB Output is correct
48 Correct 19 ms 15452 KB Output is correct
49 Correct 19 ms 15620 KB Output is correct
50 Correct 19 ms 15452 KB Output is correct
51 Correct 20 ms 15452 KB Output is correct
52 Correct 19 ms 15452 KB Output is correct
53 Correct 19 ms 15452 KB Output is correct
54 Correct 19 ms 15452 KB Output is correct
55 Correct 261 ms 28412 KB Output is correct
56 Correct 223 ms 28916 KB Output is correct
57 Correct 222 ms 27912 KB Output is correct
58 Correct 253 ms 27384 KB Output is correct
59 Correct 246 ms 28416 KB Output is correct
60 Correct 221 ms 27888 KB Output is correct
61 Correct 238 ms 28412 KB Output is correct
62 Correct 243 ms 28928 KB Output is correct
63 Correct 233 ms 28156 KB Output is correct
64 Correct 225 ms 28164 KB Output is correct
65 Correct 239 ms 28048 KB Output is correct
66 Correct 264 ms 27888 KB Output is correct
67 Correct 230 ms 27636 KB Output is correct
68 Correct 239 ms 28920 KB Output is correct
69 Correct 1114 ms 27632 KB Output is correct
70 Correct 1124 ms 27704 KB Output is correct
71 Correct 1095 ms 28696 KB Output is correct
72 Correct 1059 ms 27388 KB Output is correct
73 Correct 1144 ms 27376 KB Output is correct
74 Correct 1194 ms 27412 KB Output is correct
75 Correct 1237 ms 27644 KB Output is correct
76 Correct 1130 ms 27384 KB Output is correct
77 Correct 1174 ms 27848 KB Output is correct
78 Correct 1159 ms 28564 KB Output is correct
79 Correct 1144 ms 27648 KB Output is correct
80 Correct 1186 ms 27640 KB Output is correct
81 Correct 1148 ms 28656 KB Output is correct
82 Correct 1196 ms 27904 KB Output is correct
83 Correct 816 ms 27652 KB Output is correct
84 Correct 888 ms 30528 KB Output is correct
85 Correct 987 ms 30444 KB Output is correct
86 Correct 1037 ms 29572 KB Output is correct
87 Correct 1309 ms 29948 KB Output is correct
88 Correct 1327 ms 29932 KB Output is correct
89 Correct 985 ms 30676 KB Output is correct
90 Correct 1106 ms 30320 KB Output is correct
91 Correct 1087 ms 29552 KB Output is correct
92 Correct 1434 ms 30044 KB Output is correct
93 Correct 1253 ms 30324 KB Output is correct
94 Execution timed out 2017 ms 32256 KB Time limit exceeded
95 Halted 0 ms 0 KB -