Submission #827026

# Submission time Handle Problem Language Result Execution time Memory
827026 2023-08-16T08:09:11 Z bachhoangxuan Werewolf (IOI18_werewolf) C++17
100 / 100
664 ms 100632 KB
#include "werewolf.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=2e5+5;
const int maxl=20;
#define pii pair<int,int>
#define piii pair<pii,int>
#define fi first
#define se second

int par[maxn];
int findpar(int u){
    if(u!=par[u]) return par[u]=findpar(par[u]);
    return u;
}

struct Tree{
    vector<int> edge[maxn];
    int n,L[maxn],R[maxn],num,p[maxn][maxl];
    void add(int u,int v){
        par[v]=p[v][0]=u;
        edge[u].push_back(v);
    }
    void dfs(int u){
        L[u]=++num;
        for(int i=1;i<18;i++) p[u][i]=p[p[u][i-1]][i-1];
        for(int v:edge[u]) dfs(v);
        R[u]=num;
    }
    void build(vector<pii> e,int root){
        for(int i=1;i<=n;i++) par[i]=i;
        for(auto &[u,v]:e){
            u=findpar(u);v=findpar(v);
            if(u!=v) add(u,v);
        }
        dfs(root);
    }
    int get(int u,int l,int r){
        for(int i=17;i>=0;i--) if(p[u][i]>=l && p[u][i]<=r) u=p[u][i];
        return u;
    }
}T1,T2;

namespace BIT{
    int n,bit[maxn];
    void update(int x){
        for(int i=x;i<=n;i+=(i&(-i))) bit[i]++;
    }
    int query(int x){
        int res=0;
        for(int i=x;i>=1;i-=(i&(-i))) res+=bit[i];
        return res;
    }
}

vector<int> check_validity(int N, vector<int> U, vector<int> V,
                                vector<int> s, vector<int> t,
                                vector<int> l, vector<int> r) {
    int m=(int)U.size();
    T1.n=T2.n=BIT::n=N;

    vector<pii> e;
    for(int i=0;i<m;i++){
        U[i]++;V[i]++;
        if(U[i]>V[i]) swap(U[i],V[i]);
        e.push_back({U[i],V[i]});
    }
    sort(e.begin(),e.end(),greater<pii>());
    T1.build(e,1);

    e.clear();
    for(int i=0;i<m;i++) e.push_back({V[i],U[i]});
    sort(e.begin(),e.end());
    T2.build(e,N);

    int q=(int)s.size();
    vector<int> ans(q);
    vector<piii> query;
    for(int i=1;i<=N;i++) query.push_back({{T1.L[i],T2.L[i]},-q-1});
    for(int i=0;i<q;i++){
        s[i]++;t[i]++;l[i]++;r[i]++;
        s[i]=T1.get(s[i],l[i],N);
        t[i]=T2.get(t[i],1,r[i]);
        query.push_back({{T1.R[s[i]],T2.R[t[i]]},i+1});
        query.push_back({{T1.L[s[i]]-1,T2.R[t[i]]},-i-1});
        query.push_back({{T1.R[s[i]],T2.L[t[i]]-1},-i-1});
        query.push_back({{T1.L[s[i]]-1,T2.L[t[i]]-1},i+1});
    }
    sort(query.begin(),query.end());
    for(auto &[d,id]:query){
        if(id==-q-1) BIT::update(d.se);
        else ans[abs(id)-1]+=(id<0?-1:1)*BIT::query(d.se);
    }

    for(int i=0;i<q;i++) ans[i]=(ans[i]>=1);
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9732 KB Output is correct
2 Correct 5 ms 9724 KB Output is correct
3 Correct 5 ms 9664 KB Output is correct
4 Correct 5 ms 9720 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9724 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9732 KB Output is correct
2 Correct 5 ms 9724 KB Output is correct
3 Correct 5 ms 9664 KB Output is correct
4 Correct 5 ms 9720 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9724 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 9 ms 11040 KB Output is correct
11 Correct 10 ms 10992 KB Output is correct
12 Correct 13 ms 10992 KB Output is correct
13 Correct 10 ms 11116 KB Output is correct
14 Correct 9 ms 11080 KB Output is correct
15 Correct 11 ms 11104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 493 ms 85692 KB Output is correct
2 Correct 501 ms 87648 KB Output is correct
3 Correct 460 ms 86436 KB Output is correct
4 Correct 461 ms 85932 KB Output is correct
5 Correct 461 ms 85908 KB Output is correct
6 Correct 476 ms 85836 KB Output is correct
7 Correct 523 ms 85792 KB Output is correct
8 Correct 446 ms 87792 KB Output is correct
9 Correct 413 ms 86460 KB Output is correct
10 Correct 400 ms 89108 KB Output is correct
11 Correct 411 ms 89084 KB Output is correct
12 Correct 423 ms 89040 KB Output is correct
13 Correct 550 ms 95748 KB Output is correct
14 Correct 571 ms 95812 KB Output is correct
15 Correct 557 ms 95816 KB Output is correct
16 Correct 532 ms 95764 KB Output is correct
17 Correct 545 ms 89024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9732 KB Output is correct
2 Correct 5 ms 9724 KB Output is correct
3 Correct 5 ms 9664 KB Output is correct
4 Correct 5 ms 9720 KB Output is correct
5 Correct 5 ms 9684 KB Output is correct
6 Correct 5 ms 9684 KB Output is correct
7 Correct 5 ms 9684 KB Output is correct
8 Correct 5 ms 9724 KB Output is correct
9 Correct 5 ms 9684 KB Output is correct
10 Correct 9 ms 11040 KB Output is correct
11 Correct 10 ms 10992 KB Output is correct
12 Correct 13 ms 10992 KB Output is correct
13 Correct 10 ms 11116 KB Output is correct
14 Correct 9 ms 11080 KB Output is correct
15 Correct 11 ms 11104 KB Output is correct
16 Correct 493 ms 85692 KB Output is correct
17 Correct 501 ms 87648 KB Output is correct
18 Correct 460 ms 86436 KB Output is correct
19 Correct 461 ms 85932 KB Output is correct
20 Correct 461 ms 85908 KB Output is correct
21 Correct 476 ms 85836 KB Output is correct
22 Correct 523 ms 85792 KB Output is correct
23 Correct 446 ms 87792 KB Output is correct
24 Correct 413 ms 86460 KB Output is correct
25 Correct 400 ms 89108 KB Output is correct
26 Correct 411 ms 89084 KB Output is correct
27 Correct 423 ms 89040 KB Output is correct
28 Correct 550 ms 95748 KB Output is correct
29 Correct 571 ms 95812 KB Output is correct
30 Correct 557 ms 95816 KB Output is correct
31 Correct 532 ms 95764 KB Output is correct
32 Correct 545 ms 89024 KB Output is correct
33 Correct 553 ms 88844 KB Output is correct
34 Correct 358 ms 54516 KB Output is correct
35 Correct 560 ms 91104 KB Output is correct
36 Correct 583 ms 89624 KB Output is correct
37 Correct 563 ms 90308 KB Output is correct
38 Correct 603 ms 90148 KB Output is correct
39 Correct 511 ms 95488 KB Output is correct
40 Correct 664 ms 100632 KB Output is correct
41 Correct 514 ms 89840 KB Output is correct
42 Correct 624 ms 89580 KB Output is correct
43 Correct 613 ms 94900 KB Output is correct
44 Correct 543 ms 90292 KB Output is correct
45 Correct 489 ms 96092 KB Output is correct
46 Correct 475 ms 95460 KB Output is correct
47 Correct 555 ms 96088 KB Output is correct
48 Correct 555 ms 95804 KB Output is correct
49 Correct 573 ms 96128 KB Output is correct
50 Correct 536 ms 95748 KB Output is correct
51 Correct 634 ms 99832 KB Output is correct
52 Correct 645 ms 99924 KB Output is correct