답안 #134935

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
134935 2019-07-23T12:42:22 Z thebes 늑대인간 (IOI18_werewolf) C++14
100 / 100
946 ms 103192 KB
#include <bits/stdc++.h>
using namespace std;

const int MN = 4e5+5, LG = 20;
int ds[MN], p[MN], rep[MN], N, M, Q, i, j, vis[MN][2], nxt, sp[MN][LG], rev[MN], mp[MN], ans[MN];
struct edge{int x, y;}; vector<edge> ee;
vector<int> adj[MN];
int fnd(int x){return ds[x]=ds[x]==x?x:fnd(ds[x]);}
pair<int,int> a[MN]; set<int> st[MN];
struct qur{int s, r, id;}; vector<qur> q;

void dfs(int n){
    vis[n][0]=++nxt; rev[nxt]=n; mp[n]=nxt;
    sp[n][0]=p[n];
    for(auto v : adj[n])
        dfs(v);
    vis[n][1]=nxt;
}

int anc(int n,int h){
    for(int i=LG-1;i>=0;i--){
        if(sp[n][i]>=h) n=sp[n][i];
    }
    return n;
}

vector<int> check_validity(int n,vector<int> x,vector<int> y,vector<int> s,vector<int> e,vector<int> l,vector<int> r){
    N = n; M = x.size(); Q = s.size();
    for(i=0;i<M;i++) ee.push_back({x[i]+1,y[i]+1});
    for(i=0;i<Q;i++) s[i]++,e[i]++,l[i]++,r[i]++;
    for(i=1;i<=N;i++) ds[i]=i,rep[i]=i;
    for(i=0;i<ee.size();i++){if(ee[i].x<ee[i].y)swap(ee[i].x,ee[i].y);}
    sort(ee.begin(),ee.end(),[](edge i,edge j){return i.y>j.y;});
    for(auto v : ee){
        if(fnd(v.x)!=fnd(v.y)){
            int x = fnd(v.x), y = fnd(v.y);
            if(rep[x]>rep[y]) swap(x,y);
            adj[rep[x]].push_back(rep[y]);
            ds[y] = x; p[y] = x;
        }
    }
    dfs(1);
    for(j=1;j<LG;j++){
        for(i=1;i<=N;i++)
            sp[i][j]=sp[sp[i][j-1]][j-1];
    }
    for(i=0;i<Q;i++){
        int x = anc(s[i], l[i]);
        a[i+1]={vis[x][0],vis[x][1]};
        q.push_back({e[i],r[i],i+1});
    }
    sort(q.begin(),q.end(),[](qur i,qur j){return i.r<j.r;});
    for(i=1;i<=N;i++) ds[i]=i,st[i].insert(i);
    for(i=0;i<ee.size();i++) swap(ee[i].x,ee[i].y);
    sort(ee.begin(),ee.end(),[](edge i,edge j){return i.y<j.y;});
    i = 0;
    for(auto v : ee){
        while(i<q.size()&&q[i].r<v.y){
            int x = fnd(mp[q[i].s]);
            int id = q[i].id;
            auto it = st[x].lower_bound(a[id].first);
            if(it!=st[x].end()&&*it<=a[id].second) ans[id]=1;
            i++;
        }
        if(fnd(mp[v.x])!=fnd(mp[v.y])){
            int x = fnd(mp[v.x]), y = fnd(mp[v.y]);
            if(st[x].size()>st[y].size()) swap(x,y);
            for(auto v : st[x]) st[y].insert(v);
            st[x].clear();
            ds[x] = y;
        }
    }
    while(i<q.size()){
        int x = fnd(q[i].s);
        int id = q[i].id;
        auto it = st[x].lower_bound(a[id].first);
        if(it!=st[x].end()&&*it<=a[id].second) ans[id]=1;
        i++;
    }
    vector<int> res;
    for(i=1;i<=Q;i++) res.push_back(ans[i]);
    return res;
}

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:32:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<ee.size();i++){if(ee[i].x<ee[i].y)swap(ee[i].x,ee[i].y);}
             ~^~~~~~~~~~
werewolf.cpp:54:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(i=0;i<ee.size();i++) swap(ee[i].x,ee[i].y);
             ~^~~~~~~~~~
werewolf.cpp:58:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while(i<q.size()&&q[i].r<v.y){
               ~^~~~~~~~~
werewolf.cpp:73:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while(i<q.size()){
           ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 28664 KB Output is correct
2 Correct 29 ms 28664 KB Output is correct
3 Correct 29 ms 28664 KB Output is correct
4 Correct 28 ms 28536 KB Output is correct
5 Correct 28 ms 28664 KB Output is correct
6 Correct 28 ms 28636 KB Output is correct
7 Correct 28 ms 28664 KB Output is correct
8 Correct 28 ms 28664 KB Output is correct
9 Correct 28 ms 28536 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 28664 KB Output is correct
2 Correct 29 ms 28664 KB Output is correct
3 Correct 29 ms 28664 KB Output is correct
4 Correct 28 ms 28536 KB Output is correct
5 Correct 28 ms 28664 KB Output is correct
6 Correct 28 ms 28636 KB Output is correct
7 Correct 28 ms 28664 KB Output is correct
8 Correct 28 ms 28664 KB Output is correct
9 Correct 28 ms 28536 KB Output is correct
10 Correct 35 ms 29560 KB Output is correct
11 Correct 35 ms 29532 KB Output is correct
12 Correct 35 ms 29560 KB Output is correct
13 Correct 35 ms 29560 KB Output is correct
14 Correct 34 ms 29432 KB Output is correct
15 Correct 36 ms 29688 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 899 ms 92984 KB Output is correct
2 Correct 657 ms 89832 KB Output is correct
3 Correct 604 ms 89284 KB Output is correct
4 Correct 652 ms 89272 KB Output is correct
5 Correct 711 ms 89572 KB Output is correct
6 Correct 792 ms 89852 KB Output is correct
7 Correct 920 ms 92424 KB Output is correct
8 Correct 590 ms 89980 KB Output is correct
9 Correct 505 ms 89316 KB Output is correct
10 Correct 544 ms 89316 KB Output is correct
11 Correct 568 ms 89444 KB Output is correct
12 Correct 698 ms 90340 KB Output is correct
13 Correct 661 ms 99172 KB Output is correct
14 Correct 677 ms 99132 KB Output is correct
15 Correct 643 ms 99108 KB Output is correct
16 Correct 656 ms 99172 KB Output is correct
17 Correct 920 ms 92504 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 28664 KB Output is correct
2 Correct 29 ms 28664 KB Output is correct
3 Correct 29 ms 28664 KB Output is correct
4 Correct 28 ms 28536 KB Output is correct
5 Correct 28 ms 28664 KB Output is correct
6 Correct 28 ms 28636 KB Output is correct
7 Correct 28 ms 28664 KB Output is correct
8 Correct 28 ms 28664 KB Output is correct
9 Correct 28 ms 28536 KB Output is correct
10 Correct 35 ms 29560 KB Output is correct
11 Correct 35 ms 29532 KB Output is correct
12 Correct 35 ms 29560 KB Output is correct
13 Correct 35 ms 29560 KB Output is correct
14 Correct 34 ms 29432 KB Output is correct
15 Correct 36 ms 29688 KB Output is correct
16 Correct 899 ms 92984 KB Output is correct
17 Correct 657 ms 89832 KB Output is correct
18 Correct 604 ms 89284 KB Output is correct
19 Correct 652 ms 89272 KB Output is correct
20 Correct 711 ms 89572 KB Output is correct
21 Correct 792 ms 89852 KB Output is correct
22 Correct 920 ms 92424 KB Output is correct
23 Correct 590 ms 89980 KB Output is correct
24 Correct 505 ms 89316 KB Output is correct
25 Correct 544 ms 89316 KB Output is correct
26 Correct 568 ms 89444 KB Output is correct
27 Correct 698 ms 90340 KB Output is correct
28 Correct 661 ms 99172 KB Output is correct
29 Correct 677 ms 99132 KB Output is correct
30 Correct 643 ms 99108 KB Output is correct
31 Correct 656 ms 99172 KB Output is correct
32 Correct 920 ms 92504 KB Output is correct
33 Correct 866 ms 90368 KB Output is correct
34 Correct 419 ms 63968 KB Output is correct
35 Correct 871 ms 91876 KB Output is correct
36 Correct 810 ms 90136 KB Output is correct
37 Correct 854 ms 91088 KB Output is correct
38 Correct 835 ms 90708 KB Output is correct
39 Correct 859 ms 88420 KB Output is correct
40 Correct 931 ms 102624 KB Output is correct
41 Correct 757 ms 90596 KB Output is correct
42 Correct 709 ms 90404 KB Output is correct
43 Correct 946 ms 96608 KB Output is correct
44 Correct 807 ms 90936 KB Output is correct
45 Correct 699 ms 88932 KB Output is correct
46 Correct 760 ms 88368 KB Output is correct
47 Correct 664 ms 99364 KB Output is correct
48 Correct 663 ms 99172 KB Output is correct
49 Correct 738 ms 99284 KB Output is correct
50 Correct 678 ms 99088 KB Output is correct
51 Correct 910 ms 103192 KB Output is correct
52 Correct 945 ms 103136 KB Output is correct