Submission #306049

# Submission time Handle Problem Language Result Execution time Memory
306049 2020-09-24T11:34:24 Z 2fat2code Joker (BOI20_joker) C++17
0 / 100
2000 ms 8556 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define all(a) (a).begin(), (a).end()
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define fr first
#define sc second
//#define int long long
//#define mp make_pair
#define rc(s) return cout<<s,0
#define rcc(s) cout<<s,exit(0)

const int nmax = 200005;

int n,m,q,frbipartid[nmax],siz[nmax];
pair<int,int>par[nmax];
vector<int>rollback;
vector<pair<int,int>>edges;

void roll(int sz){
    assert((int)rollback.size() >= sz);
    while((int)rollback.size() > sz){
        auto it = rollback.back();
        siz[par[it].fr] -= siz[it];
        par[it].fr = it;
        par[it].sc = 0;
        rollback.pop_back();
    }
}

pair<int,int>findpar(int x){
    pair<int,int>ans = {par[x].fr, 0};
    if(x != par[x].fr){
        ans = findpar(par[x].fr);
        ans.sc ^= par[x].sc;
    }
    return ans;
}

bool onion(int x,int y){
    pair<int,int>x1,y1;
    x1 = findpar(x);
    y1 = findpar(y);
    if(x1.fr == y1.fr){
        if(x1.sc == y1.sc){
            return false;
        }
        else{
            return true;
        }
    }
    else{
        if(siz[x1.fr] > siz[y1.fr]){
            swap(x,y);
        }
        siz[y1.fr] += siz[x1.fr];
        par[x1.fr].fr = y1.fr;
        if(x1.sc == y1.sc){
            par[x1.fr].sc = 1;
        }
        else{
            par[x1.fr].sc = 0;
        }
        rollback.push_back(x1.fr);
        return true;
    }
}

void DAC(int l_nod,int r_nod,int l_range,int r_range){
    if(r_nod < l_nod) return;
    if(l_range == r_range){
        for(int j=l_nod;j<=r_nod;j++){
            frbipartid[j] = l_range;
        }
        return;
    }
    else{
        int mid = l_range + (r_range - l_range) / 2;
        bool bl = false;
        int sz_roll = rollback.size();
        for(int j=r_range;j>mid;j--){
            if(j == m + 1){ continue; }
            else{
                if(!onion(edges[j-1].fr,edges[j-1].sc)){
                    bl = true;
                    break;
                }
            }
        }
        int indx = l_nod;
        if(bl == false){
            int sz_roll2=(int)rollback.size();
            indx = -1;
            for(int j=l_nod;j<=min(r_nod,mid);j++){
                if(onion(edges[j-1].fr,edges[j-1].sc) == false){
                    indx = j + 1;
                    break;
                }
            }
            if(indx == -1) indx = min(r_nod,mid) + 1;
            roll(sz_roll2);
            DAC(l_nod,indx-1,l_range,mid);
        }
        roll(sz_roll);
        int sz_roll3 = (int)rollback.size();
        for(int j=l_nod;j<indx;j++){
            onion(edges[j-1].fr,edges[j-1].sc);
        }
        DAC(indx,r_nod,mid+1,r_range);
        roll(sz_roll3);
    }
}

int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    srand(chrono::steady_clock::now().time_since_epoch().count());
   // freopen("input.in","r",stdin);
    cin >> n >> m >> q;
    for(int i=1;i<=n;i++){
        par[i] = {i, 0};
        siz[i] = 1;
    }
    for(int i=1;i<=m;i++){
        int x,y;
        cin >> x >> y;
        edges.push_back({x,y});
    }
    DAC(1,m,1,m+1);
    for(int i=1;i<=q;i++){
        int x,y;
        cin >> x >> y;
        if(frbipartid[x] <= y){
            cout << "NO" << '\n';
        }
        else{
            cout << "YES" << '\n';
        }
    }
}


# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 214 ms 6244 KB Output is correct
4 Correct 463 ms 8168 KB Output is correct
5 Correct 251 ms 8556 KB Output is correct
6 Correct 212 ms 5604 KB Output is correct
7 Correct 237 ms 5480 KB Output is correct
8 Execution timed out 2064 ms 3192 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Incorrect 1 ms 384 KB Output isn't correct
9 Halted 0 ms 0 KB -