답안 #1052240

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1052240 2024-08-10T12:39:40 Z Ahmed57 늑대인간 (IOI18_werewolf) C++17
15 / 100
125 ms 60548 KB
#include "bits/stdc++.h"

using namespace std;
int pr[100001];
int sp[100001];
int val1[100001];
int val2[100001];
vector<int> MI[100001];
vector<int> MA[100001];
int find(int x){
    if(x==pr[x])return x;
    return pr[x] = find(pr[x]);
}
bool mergegroup(int a,int b){
    a = find(a) , b = find(b);
    if(a==b)return 0;
    pr[a] = b;
    return 1;
}
int P[100001][20][2];
int timer = 0;
int in[100001][2];
int out[100001][2];
void dfs1(int i,int pr){
    P[i][0][0] = pr;
    in[i][0] = ++timer;
    for(int j = 1;j<20;j++){
        P[i][j][0] = P[P[i][j-1][0]][j-1][0];
    }
    for(auto j:MI[i]){
        if(j==pr)continue;
        dfs1(j,i);
    }
    out[i][0] = timer;
}
int rev[100001];
int n,m,q;
void dfs2(int i,int pr){
    in[i][1] = ++timer;
    if(i<n)rev[timer] = i;
    else rev[timer] = -1;
    P[i][0][1] = pr;
    for(int j = 1;j<20;j++){
        P[i][j][1] = P[P[i][j-1][1]][j-1][1];
    }
    for(auto j:MA[i]){
        if(j==pr)continue;
        dfs2(j,i);
    }
    out[i][1] = timer;
}
int seg[400001];
void build(int p,int l,int r){
    seg[p] = 1e9;
    if(l==r)return ;
    int md = (l+r)/2;
    build(p*2,l,md);
    build(p*2+1,md+1,r);
}
void update(int p,int l,int r,int idx,int val){
    if(l==r){
        seg[p] = val;
        return ;
    }
    int md = (l+r)/2;
    if(idx<=md)update(p*2,l,md,idx,val);
    else update(p*2+1,md+1,r,idx,val);
    seg[p] = min(seg[p*2],seg[p*2+1]);
}
int query(int p,int l,int r,int lq,int rq){
    if(l>=lq&&r<=rq)return seg[p];
    if(r<lq||l>rq)return 1e9;
    int md = (l+r)/2;
    return min(query(p*2,l,md,lq,rq),query(p*2+1,md+1,r,lq,rq));
}
vector<int> check_validity(int N,vector<int> X,vector<int> Y,vector<int> S,vector<int> E,vector<int> L,vector<int> R){
    m = X.size();
    q = L.size();
    n = N;
    vector<array<int,3>> mi,ma;
    for(int i = 0;i<m;i++){
        mi.push_back({max(X[i],Y[i]),X[i],Y[i]});
        ma.push_back({min(X[i],Y[i]),X[i],Y[i]});
    }
    sort(mi.begin(),mi.end());
    sort(ma.begin(),ma.end());
    reverse(ma.begin(),ma.end());
    for(int i = 0;i<n;i++){
        pr[i] = i;
        sp[i] = i;
        val1[i] = i;
    }
    int nc = n;
    for(auto i:mi){
        if(find(i[1])==find(i[2]))continue;
        int A = find(i[1]);
        int B = find(i[2]);
        MI[nc].push_back(sp[A]);
        MI[nc].push_back(sp[B]);
        val1[nc] = i[0];
        mergegroup(i[1],i[2]);
        sp[find(i[1])] = nc;
        nc++;
    }
    for(int i = 0;i<n;i++){
        pr[i] = i;
        sp[i] = i;
        val2[i] = i;
    }
    nc = n;
    for(auto i:ma){
        if(find(i[1])==find(i[2]))continue;
        int A = find(i[1]);
        int B = find(i[2]);
        MA[nc].push_back(sp[A]);
        MA[nc].push_back(sp[B]);
        val2[nc] = i[0];
        mergegroup(i[1],i[2]);
        sp[find(i[1])] = nc;
        nc++;
    }
    timer = 0;
    dfs1(nc-1,nc-1);
    int nah = timer;
    timer = 0;
    dfs2(nc-1,nc-1);
    vector<array<int,4>> rngs[100001];
    for(int i = 0;i<q;i++){
        for(int j = 19;j>=0;j--){
            if(val2[P[S[i]][j][1]]>=L[i]){
                S[i] = P[S[i]][j][1];
            }
        }
        for(int j = 19;j>=0;j--){
            if(val1[P[E[i]][j][0]]<=R[i]){
                E[i] = P[E[i]][j][0];
            }
        }
        rngs[in[S[i]][1]].push_back({out[S[i]][1],in[E[i]][0],out[E[i]][0],i});
    }
    build(1,1,timer);
    vector<int> ANS(q,0);
    for(int i = timer;i>=1;i--){
        if(rev[i]!=-1){
            int no = rev[i];
            update(1,1,timer,in[no][0],i);
        }
        for(auto j:rngs[i]){
            if(query(1,1,timer,j[1],j[2])<=j[0]){
                ANS[j[3]] = 1;
            }else ANS[j[3]] = 0;
        }
    }
    return ANS;
}

Compilation message

werewolf.cpp: In function 'std::vector<int> check_validity(int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
werewolf.cpp:124:9: warning: unused variable 'nah' [-Wunused-variable]
  124 |     int nah = timer;
      |         ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 13144 KB Output is correct
5 Correct 2 ms 12984 KB Output is correct
6 Correct 3 ms 12892 KB Output is correct
7 Correct 3 ms 13148 KB Output is correct
8 Correct 3 ms 12892 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 13144 KB Output is correct
5 Correct 2 ms 12984 KB Output is correct
6 Correct 3 ms 12892 KB Output is correct
7 Correct 3 ms 13148 KB Output is correct
8 Correct 3 ms 12892 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 9 ms 15964 KB Output is correct
11 Correct 6 ms 15708 KB Output is correct
12 Correct 6 ms 15708 KB Output is correct
13 Correct 6 ms 15804 KB Output is correct
14 Correct 7 ms 15768 KB Output is correct
15 Correct 7 ms 15784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 125 ms 60548 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 2 ms 12892 KB Output is correct
3 Correct 2 ms 12892 KB Output is correct
4 Correct 2 ms 13144 KB Output is correct
5 Correct 2 ms 12984 KB Output is correct
6 Correct 3 ms 12892 KB Output is correct
7 Correct 3 ms 13148 KB Output is correct
8 Correct 3 ms 12892 KB Output is correct
9 Correct 2 ms 12892 KB Output is correct
10 Correct 9 ms 15964 KB Output is correct
11 Correct 6 ms 15708 KB Output is correct
12 Correct 6 ms 15708 KB Output is correct
13 Correct 6 ms 15804 KB Output is correct
14 Correct 7 ms 15768 KB Output is correct
15 Correct 7 ms 15784 KB Output is correct
16 Runtime error 125 ms 60548 KB Execution killed with signal 11
17 Halted 0 ms 0 KB -