답안 #990645

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
990645 2024-05-30T21:54:49 Z imarn Joker (BOI20_joker) C++14
25 / 100
225 ms 15636 KB
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,ll>
#define f first
#define s second
#define pb push_back
#define all(x) x.begin(),x.end()
using namespace std;
const int mxn=4e5+5;
vector<pii>edge;
int pr[mxn]{0},m,n;
int dp[mxn]{0};
int sz[mxn]{0};
stack<pii>st;
void rollback(int x){
    while(st.size()>x){
        pr[st.top().f]=st.top().f;
        sz[st.top().s]-=sz[st.top().f];
        st.pop();
    }
}
int get(int r){
    return pr[r]==r?r:get(pr[r]);
}
void uni(int a,int b){
    a=get(a),b=get(b);
    if(a==b)return;
    if(sz[a]>sz[b])swap(a,b);
    pr[a]=b;sz[b]+=sz[a];
    st.push({a,b});
}
void solve(int l1,int r1,int l2,int r2,bool ok){
    if(l1>r1)return;
    if(ok&&r2==m){
        for(int i=l1;i<=r1;i++)dp[i]=r2+1;
        return;
    }
    int md=(l1+r1)>>1,md2=-1;
    int pv1=st.size();
    bool ok2=ok;
    for(int i=l1;i<=md-1;i++){
        uni(edge[i-1].f,edge[i-1].s+n);
        uni(edge[i-1].f+n,edge[i-1].s);
        if(get(edge[i-1].f)==get(edge[i-1].f+n)||get(edge[i-1].s)==get(edge[i-1].s+n))ok2|=1;
    }int pv2=st.size();
    for(int i=r2;i>=max(l2,md);i--){
        uni(edge[i-1].f,edge[i-1].s+n);
        uni(edge[i-1].f+n,edge[i-1].s);
        if(get(edge[i-1].f)==get(edge[i-1].f+n)||get(edge[i-1].s)==get(edge[i-1].s+n)){md2=i;break;}
    }if(md2==-1)md2=md-1;
    dp[md]=md2;rollback(pv2);uni(edge[md-1].f,edge[md-1].s+n);
    uni(edge[md-1].f+n,edge[md-1].s);
    if(get(edge[md-1].f)==get(edge[md-1].f+n)||get(edge[md-1].s)==get(edge[md-1].s+n))ok2|=1;
    solve(md+1,r1,md2,r2,ok2);
    rollback(pv1);ok2=ok;
    for(int i=r2;i>=md2+1;i--){
        uni(edge[i-1].f,edge[i-1].s+n);
        uni(edge[i-1].f+n,edge[i-1].s);
        if(get(edge[i-1].f)==get(edge[i-1].f+n)||get(edge[i-1].s)==get(edge[i-1].s+n))ok2|=1;
    }
    solve(l1,md-1,l2,md2,ok2);rollback(pv1);
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int q;cin>>n>>m>>q;iota(pr,pr+2*n+1,0);
    for(int i=1;i<=2*n;i++)sz[i]=1;
    for(int i=0;i<m;i++){
        int u,v;cin>>u>>v;
        edge.pb({u,v});
    }solve(1,m,1,m,0);
    while(q--){
        int l,r;cin>>l>>r;
        cout<<(r<dp[l]?"YES\n":"NO\n");
    }
}

Compilation message

Joker.cpp: In function 'void rollback(int)':
Joker.cpp:16:20: warning: comparison of integer expressions of different signedness: 'std::stack<std::pair<int, long long int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   16 |     while(st.size()>x){
      |           ~~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Incorrect 1 ms 4444 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Incorrect 1 ms 4444 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 118 ms 11708 KB Output is correct
4 Correct 225 ms 15636 KB Output is correct
5 Correct 109 ms 15136 KB Output is correct
6 Correct 102 ms 11964 KB Output is correct
7 Correct 104 ms 12220 KB Output is correct
8 Correct 119 ms 11200 KB Output is correct
9 Correct 139 ms 11968 KB Output is correct
10 Correct 213 ms 13504 KB Output is correct
11 Correct 144 ms 11712 KB Output is correct
12 Correct 165 ms 13564 KB Output is correct
13 Correct 112 ms 8896 KB Output is correct
14 Correct 125 ms 10720 KB Output is correct
15 Correct 187 ms 12224 KB Output is correct
16 Correct 213 ms 13500 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Incorrect 1 ms 4444 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Incorrect 1 ms 4444 KB Output isn't correct
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 1 ms 4444 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4444 KB Output is correct
6 Incorrect 1 ms 4444 KB Output isn't correct
7 Halted 0 ms 0 KB -