답안 #751889

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
751889 2023-06-01T17:31:51 Z Ronin13 Joker (BOI20_joker) C++17
0 / 100
2000 ms 12300 KB
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pll pair<ll,ll>
#define pb push_back
#define epb emplace_back
#define ull unsigned ll
#define pii pair<int,int>
using namespace std;
const int nmax = 400001;

stack <pair<pair<int, bool> , pair<int, bool> > > st;

pii p[nmax];
int sz[nmax];
bool good[nmax];
void make_set(int v){
    p[v] = {v, 0};
    sz[v] = 1;
    good[v] = true;
}

pair <int,int> find_set(int v){
    if(v == p[v].f){
        return {v, 0};
    }
    pii x = find_set(p[v].f);
    return {x.f, x.s ^ p[v].s};
}

bool union_sets(int a, int b){
    pii A = find_set(a);
    pii B = find_set(b);
    if(A.f == B.f){
        st.push({{A.f, good[A.f]}, {A.f, good[A.f]}});
        good[A.f] &= (A.s != B.s);
        return good[A.f];
    }
    if(sz[A.f] < sz[B.f])
        swap(A, B);
    st.push({{B.f, good[B.f]}, {A.f, good[A.f]}});
    good[A.f] &= good[B.f];
    sz[A.f] += sz[B.f];
    p[B.f] = {A.f, A.s ^ B.s ^ 1};

    return good[A.f];
}

void rollback(int sz){
    while(st.size() > sz){
        int x = st.top().f.f;
        p[x] = {x, 0};
        good[x] = st.top().f.s;
        good[st.top().s.f] = st.top().s.s;
        st.pop();
    }
}

int u[nmax], v[nmax];
int ans[nmax];
bool good1;
void divi(int l1, int l2, int r1, int r2){
    if(l1 > l2) return;
    int m = (l1 + l2) / 2;
    int s1 = st.size();
    bool good = good1;
    bool pr = good1;
    for(int i = l1; i < m; i++)
        good &= union_sets(u[i], v[i]);
    good1 = good;
    int s = st.size();
    for(int i = r2; i >= r1; i--){
        if(!good){ ans[m] = i + 1; break;}
        if(i == m){
            ans[m] = i;
            break;
        }
        good &= union_sets(u[i], v[i]);
    }
    rollback(s);
    good1 &= union_sets(u[m], v[m]);
    divi(m + 1, l2, ans[m], r2);
    rollback(s1);
    int s2 = st.size();
    bool pr1 = pr;
    good1 = pr;
    for(int i = r2; i > ans[m]; i--){
        good1 &= union_sets(v[i], u[i]);
    }
    divi(l1, m - 1, r1, ans[m]);
    rollback(s2);
    good1 = pr1;
}

int main(){
    good1 = true;
    int n, m, q; cin >> n >> m >> q;
    for(int i = 1; i <= n; i++)
        make_set(i);
    for(int i = 1; i <= m; i++){
        cin >> u[i] >> v[i];
    }
    divi(1, m, 0, m);

    while(q--){
        int l, r; cin >>l >> r;
        r < ans[l] ? cout << "YES\n" : cout << "NO\n";
    }
}

Compilation message

Joker.cpp: In function 'void rollback(int)':
Joker.cpp:51:21: warning: comparison of integer expressions of different signedness: 'std::stack<std::pair<std::pair<int, bool>, std::pair<int, bool> > >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   51 |     while(st.size() > sz){
      |           ~~~~~~~~~~^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Execution timed out 2050 ms 12300 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 312 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Incorrect 1 ms 340 KB Output isn't correct
5 Halted 0 ms 0 KB -