답안 #720344

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
720344 2023-04-08T04:24:08 Z n0sk1ll Joker (BOI20_joker) C++14
0 / 100
210 ms 11692 KB
#include <bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) x.begin(),x.end()
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
const int mod = 1000000007;







//Note to self: Check for overflow

int up[200005];
bool wh[200005];
bool isbip=true;
int kolkosamlos=0;

stack<pair<int,pii>> stek;

void dsu(int a, int b)
{
    int wa=wh[a],wb=wh[b];
    while (up[a]>=0)
    {
        a=up[a];
        wa^=wh[a];
    }
    while (up[b]>=0)
    {
        b=up[b];
        wb^=wh[b];
    }

    if (a==b || !isbip)
    {
        if (!isbip || wa==wb) isbip=false,stek.push({-1,{-1,-1}}),stek.push({-1,{-1,-1}}),kolkosamlos+=2;
        else stek.push({0,{0,0}}),stek.push({0,{0,0}});
    }
    else
    {
        if (up[a]<up[b]) swap(a,b);
        stek.push({b,{up[b],0}});
        stek.push({a,{up[a],0}});
        if (wa==wb) wh[a]^=1,stek.top().yy.yy=1;
        up[b]+=up[a],up[a]=b;
    }
}

void rollback()
{
    int rep=2;
    while (rep--)
    {
        auto it=stek.top(); stek.pop();
        if (it.xx!=-1){
            up[it.xx]=it.yy.xx,wh[it.xx]=it.yy.yy;
        }
        else
        {
            kolkosamlos--;
            if (kolkosamlos==0) isbip=true;
        }
    }
}

void printstack()
{
    vector<pair<int,pii>> sta;
    while (!stek.empty())
    {
        sta.pb(stek.top());
        stek.pop();
    }

    for (auto it : sta) cout<<it.xx<<": "<<it.yy.xx<<","<<it.yy.yy<<endl;
    cout<<endl;

    while (!sta.empty())
    {
        stek.push(sta.back());
        sta.popb();
    }
}

pii eds[200005];
int rmost[200005]; //prvi za koji zabrana [i,rmost[i]] daje bipartitivan graf

void binarna(int l, int r, int okle, int dokle) //popunjeni su [1,okle-1] i [r+1,n]
{
    //cout<<"["<<okle<<","<<dokle<<"] se slika u ["<<l<<","<<r<<"]"<<endl;
    //printstack();
    if (okle>dokle) return;

    if (l==r)
    {
        fff(i,okle,dokle) rmost[i]=l;
    }
    else
    {
        int mid=(l+r)/2;
        fff(i,mid+1,r) dsu(eds[i].xx,eds[i].yy);
        if (!isbip)
        {
            fff(i,mid+1,r) rollback();
            binarna(mid+1,r,okle,dokle);
        }
        else
        {
            int mokle=okle,kokle=0; //mid [okle,dokle]
            while (mokle<dokle)
            {
                dsu(eds[mokle].xx,eds[mokle].yy),kokle++;
                if (!isbip) break; mokle++;
            }
            //dakle, [okle,mokle] predstavlja one koji SU bipartitivni, [mokle,dokle] one koji NISU

            while (kokle--) rollback();
            binarna(l,mid,okle,mokle);

            fff(i,mid+1,r) rollback();
            fff(i,okle,mokle) dsu(eds[i].xx,eds[i].yy);
            binarna(mid+1,r,mokle+1,dokle);
            fff(i,okle,mokle) rollback();
        }
    }
}

int main()
{
    FAST;

    int n,m,q; cin>>n>>m>>q;
    fff(i,1,n) up[i]=-1,wh[i]=0; isbip=true;
    fff(i,1,m) cin>>eds[i].xx>>eds[i].yy;
    binarna(0,m,1,m);

    while (!stek.empty()) rollback();
    fff(i,1,m)
    {
        if (!isbip) rmost[i]=m+1;
        dsu(eds[i].xx,eds[i].yy);
    }
    //fff(i,1,m) cout<<i<<": "<<rmost[i]<<endl;

    while (q--)
    {
        int ll,rr; cin>>ll>>rr;
        if (rr>=rmost[ll]) cout<<"NO\n";
        else cout<<"YES\n";
    }




    /*fff(i,1,1000) up[i]=-1,wh[i]=0; isbip=true;

    while (true)
    {
        string t; cin>>t;
        if (t=="add")
        {
            int u,v; cin>>u>>v;
            dsu(u,v);
        }
        else if (t=="rollback")
        {
            rollback();
        }
        else cout<<"unsupported command!"<<endl;
        cout<<(isbip?"bipartite":"has odd cycle")<<endl;
    }*/
}

//Note to self: Check for overflow

/*

3 3 0
1 2
2 3
3 1

4 4 0
1 2
2 3
3 4
4 1

*/

Compilation message

Joker.cpp: In function 'void binarna(int, int, int, int)':
Joker.cpp:137:17: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  137 |                 if (!isbip) break; mokle++;
      |                 ^~
Joker.cpp:137:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  137 |                 if (!isbip) break; mokle++;
      |                                    ^~~~~
Joker.cpp: In function 'int main()':
Joker.cpp:13:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   13 | #define fff(i,a,b) for (int i = a; i <= b; i++)
      |                    ^~~
Joker.cpp:157:5: note: in expansion of macro 'fff'
  157 |     fff(i,1,n) up[i]=-1,wh[i]=0; isbip=true;
      |     ^~~
Joker.cpp:157:34: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  157 |     fff(i,1,n) up[i]=-1,wh[i]=0; isbip=true;
      |                                  ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 158 ms 8548 KB Output is correct
4 Correct 210 ms 11692 KB Output is correct
5 Incorrect 109 ms 8964 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Incorrect 1 ms 340 KB Output isn't correct
9 Halted 0 ms 0 KB -