Submission #256124

# Submission time Handle Problem Language Result Execution time Memory
256124 2020-08-02T10:06:17 Z 문홍윤(#5033) Joker (BOI20_joker) C++17
25 / 100
339 ms 8036 KB
#include <bits/stdc++.h>
#define pb emplace_back
#define mp make_pair
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const int inf=987654321;

struct UNION_FIND{
    int par[400010], sz[400010];
    vector<int> vc;
    UNION_FIND(){for(int i=1; i<=400000; i++)par[i]=i, sz[i]=1;}
    int findpar(int num){return num==par[num]?num:findpar(par[num]);}
    void mergepar(int a, int b){
        a=findpar(a);
        b=findpar(b);
        if(a==b)return;
        if(sz[a]<sz[b])swap(a, b);
        vc.pb(b);
        par[b]=a;
        sz[a]+=sz[b];
    }
    void rollback(){
        int tmp=vc.back();
        vc.pop_back();
        sz[par[tmp]]-=sz[tmp];
        par[tmp]=tmp;
    }
}uf;

int n, m, q, ans[200010], l, r;
pii edg[200010];

int link(int a, int b){
    uf.mergepar(2*a-1, 2*b);
    uf.mergepar(2*a, 2*b-1);
    if(uf.findpar(2*a)==uf.findpar(2*a-1))return 1;
    return 0;
}

void dnc(int sa, int ea, int sb, int eb){
    if(sa>ea)return;
    int mid=(sa+ea)/2;
    int tmp1=uf.vc.size();
    for(int i=l+1; i<=mid; i++)link(edg[i].F, edg[i].S);
    l=mid;
    int tmp2=uf.vc.size();
    for(int i=r-1; i>l&&i>=sb; i--){
        int sz=uf.vc.size();
        int tmp=link(edg[i].F, edg[i].S);
        if(tmp){
            while(sz<uf.vc.size())uf.rollback();
            r=i+1;
            break;
        }
    }
    ans[mid]=r;
    while(tmp2<uf.vc.size())uf.rollback();
    r=eb;
    link(edg[mid+1].F, edg[mid+1].S);
    l=mid+1;
    dnc(mid+1, ea, ans[mid], eb);
    while(tmp1<uf.vc.size())uf.rollback();
    l=sa;
    for(int i=r-1; i>=ans[mid]; i--)link(edg[i].F, edg[i].S);
    r=ans[mid];
    dnc(sa, mid-1, sb, ans[mid]);
    while(tmp1<uf.vc.size())uf.rollback();
    r=eb;
}

int main(){
    scanf("%d %d %d", &n, &m, &q);
    int np=0;
    for(int i=1; i<=m; i++)scanf("%d %d", &edg[i].F, &edg[i].S);
    int ll=m, lr=1;
    for(int i=1; i<=m; i++){
        if(link(edg[i].F, edg[i].S)){
            ll=i-1;
            break;
        }
        if(i==m)np=1;
    }
    while(uf.vc.size())uf.rollback();
    r=m+1;
    if(!np)dnc(0, ll, 1, m+1);
    for(int i=ll+1; i<=m; i++)ans[i]=inf;
    //for(int i=0; i<=m; i++)printf("! %d : %d\n", i, ans[i]);
    for(int i=1; i<=q; i++){
        int a, b;
        scanf("%d %d", &a, &b);
        if(np)puts("NO");
        else if(ans[a-1]<=b+1)puts("NO");
        else puts("YES");
    }
}

Compilation message

Joker.cpp: In function 'void dnc(int, int, int, int)':
Joker.cpp:54:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
             while(sz<uf.vc.size())uf.rollback();
                   ~~^~~~~~~~~~~~~
Joker.cpp:60:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(tmp2<uf.vc.size())uf.rollback();
           ~~~~^~~~~~~~~~~~~
Joker.cpp:65:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(tmp1<uf.vc.size())uf.rollback();
           ~~~~^~~~~~~~~~~~~
Joker.cpp:70:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(tmp1<uf.vc.size())uf.rollback();
           ~~~~^~~~~~~~~~~~~
Joker.cpp: In function 'int main()':
Joker.cpp:78:15: warning: unused variable 'lr' [-Wunused-variable]
     int ll=m, lr=1;
               ^~
Joker.cpp:75:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d %d", &n, &m, &q);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:77:33: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(int i=1; i<=m; i++)scanf("%d %d", &edg[i].F, &edg[i].S);
                            ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:93:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 3 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 2 ms 3456 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 3 ms 3456 KB Output is correct
8 Incorrect 2 ms 3456 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 3 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 2 ms 3456 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 3 ms 3456 KB Output is correct
8 Incorrect 2 ms 3456 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 3 ms 3456 KB Output is correct
3 Correct 229 ms 7404 KB Output is correct
4 Correct 118 ms 7396 KB Output is correct
5 Correct 223 ms 8036 KB Output is correct
6 Correct 178 ms 7404 KB Output is correct
7 Correct 187 ms 7656 KB Output is correct
8 Correct 202 ms 7148 KB Output is correct
9 Correct 242 ms 7404 KB Output is correct
10 Correct 304 ms 7536 KB Output is correct
11 Correct 226 ms 7276 KB Output is correct
12 Correct 268 ms 7660 KB Output is correct
13 Correct 194 ms 6680 KB Output is correct
14 Correct 199 ms 7020 KB Output is correct
15 Correct 282 ms 7276 KB Output is correct
16 Correct 339 ms 7404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 3 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 2 ms 3456 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 3 ms 3456 KB Output is correct
8 Incorrect 2 ms 3456 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 3 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 2 ms 3456 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 3 ms 3456 KB Output is correct
8 Incorrect 2 ms 3456 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3456 KB Output is correct
2 Correct 3 ms 3456 KB Output is correct
3 Correct 2 ms 3456 KB Output is correct
4 Correct 2 ms 3456 KB Output is correct
5 Correct 2 ms 3456 KB Output is correct
6 Correct 2 ms 3456 KB Output is correct
7 Correct 3 ms 3456 KB Output is correct
8 Incorrect 2 ms 3456 KB Output isn't correct
9 Halted 0 ms 0 KB -