답안 #432861

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
432861 2021-06-18T14:21:14 Z Bench0310 늑대인간 (IOI18_werewolf) C++17
100 / 100
1441 ms 119000 KB
#include <bits/stdc++.h>
#include "werewolf.h"

using namespace std;
typedef long long ll;

const int N=200005;

struct DSU
{
    int n;
    int root;
    vector<int> p;
    vector<int> sz;
    vector<vector<int>> g;
    vector<int> tin;
    vector<int> tout;
    int tcnt;
    vector<array<int,18>> up;
    int edges;
    DSU(int nn,int r)
    {
        n=nn;
        root=r;
        edges=n-1;
        tcnt=0;
        p.assign(n,0);
        for(int i=0;i<n;i++) p[i]=i;
        sz.assign(n,1);
        g.resize(n);
        tin.assign(n,-1);
        tout.assign(n,-1);
        up.resize(n);
        for(int i=0;i<n;i++) up[i].fill(-1);
    }
    int find_set(int a)
    {
        if(a==p[a]) return a;
        else return (p[a]=find_set(p[a]));
    }
    void merge_sets(int a,int b) //a should be parent if mergeable
    {
        a=find_set(a);
        b=find_set(b);
        if(a==b) return;
        g[a].push_back(b);
        p[b]=a;
        sz[a]+=sz[b];
        if((--edges)==0) dfs(root);
    }
    void dfs(int a)
    {
        tin[a]=tcnt++;
        for(int i=1;i<18;i++)
        {
            if(up[a][i-1]==-1) break;
            up[a][i]=up[up[a][i-1]][i-1];
        }
        for(int to:g[a])
        {
            up[to][0]=a;
            dfs(to);
        }
        tout[a]=tcnt-1;
    }
    int find_up(int a,auto f)
    {
        for(int i=17;i>=0;i--) if(up[a][i]!=-1&&f(up[a][i])==1) a=up[a][i];
        return a;
    }
};

vector<int> tree(4*N,0);

void update(int idx,int l,int r,int pos,int x)
{
    if(l==r) tree[idx]+=x;
    else
    {
        int m=(l+r)/2;
        if(pos<=m) update(2*idx,l,m,pos,x);
        else update(2*idx+1,m+1,r,pos,x);
        tree[idx]=tree[2*idx]+tree[2*idx+1];
    }
}

int query(int idx,int l,int r,int ql,int qr)
{
    if(ql>qr) return 0;
    if(l==ql&&r==qr) return tree[idx];
    int m=(l+r)/2;
    return query(2*idx,l,m,ql,min(qr,m))+query(2*idx+1,m+1,r,max(ql,m+1),qr);
}

vector<int> check_validity(int n,vector<int> x,vector<int> y,vector<int> s,vector<int> e,vector<int> l,vector<int> r)
{
    int m=x.size();
    int q=s.size();
    vector<int> v[n];
    for(int i=0;i<m;i++)
    {
        v[x[i]].push_back(y[i]);
        v[y[i]].push_back(x[i]);
    }
    DSU one(n,0);
    for(int i=n-1;i>=0;i--)
    {
        for(int to:v[i]) if(to>i) one.merge_sets(i,to);
    }
    DSU two(n,n-1);
    for(int i=0;i<n;i++)
    {
        for(int to:v[i]) if(to<i) two.merge_sets(i,to);
    }
    vector<array<int,2>> points(n);
    for(int i=0;i<n;i++) points[i]={one.tin[i],two.tin[i]};
    vector<int> add[n];
    for(int i=0;i<n;i++) add[points[i][0]].push_back(points[i][1]);
    vector<int> res(q,0);
    vector<array<int,4>> queries[n]; //l,r,id,d
    for(int i=0;i<q;i++)
    {
        int u=one.find_up(s[i],[&](int a)->bool{return (a>=l[i]);});
        int lone=one.tin[u];
        int rone=one.tout[u];
        u=two.find_up(e[i],[&](int a)->bool{return (a<=r[i]);});
        int ltwo=two.tin[u];
        int rtwo=two.tout[u];
        if(lone>0) queries[lone-1].push_back({ltwo,rtwo,i,-1});
        queries[rone].push_back({ltwo,rtwo,i,1});
    }
    for(int i=0;i<n;i++)
    {
        for(int a:add[i]) update(1,0,n-1,a,1);
        for(auto [a,b,id,d]:queries[i]) res[id]+=(d*query(1,0,n-1,a,b));
    }
    for(int i=0;i<q;i++) res[i]=(res[i]>0);
    return res;
}

//int main()
//{
//    
//    return 0;
//}

Compilation message

werewolf.cpp:66:23: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   66 |     int find_up(int a,auto f)
      |                       ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 3 ms 3404 KB Output is correct
3 Correct 2 ms 3436 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3444 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 2 ms 3432 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 3 ms 3404 KB Output is correct
3 Correct 2 ms 3436 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3444 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 2 ms 3432 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 11 ms 4940 KB Output is correct
11 Correct 10 ms 4940 KB Output is correct
12 Correct 9 ms 5016 KB Output is correct
13 Correct 10 ms 4984 KB Output is correct
14 Correct 10 ms 4980 KB Output is correct
15 Correct 11 ms 5068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 960 ms 112068 KB Output is correct
2 Correct 1143 ms 111856 KB Output is correct
3 Correct 960 ms 111428 KB Output is correct
4 Correct 840 ms 110268 KB Output is correct
5 Correct 889 ms 110640 KB Output is correct
6 Correct 949 ms 112068 KB Output is correct
7 Correct 864 ms 110292 KB Output is correct
8 Correct 977 ms 111664 KB Output is correct
9 Correct 807 ms 108980 KB Output is correct
10 Correct 659 ms 110068 KB Output is correct
11 Correct 739 ms 109976 KB Output is correct
12 Correct 768 ms 109712 KB Output is correct
13 Correct 1082 ms 114784 KB Output is correct
14 Correct 1101 ms 114676 KB Output is correct
15 Correct 1088 ms 114748 KB Output is correct
16 Correct 1068 ms 114824 KB Output is correct
17 Correct 867 ms 110392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3404 KB Output is correct
2 Correct 3 ms 3404 KB Output is correct
3 Correct 2 ms 3436 KB Output is correct
4 Correct 2 ms 3404 KB Output is correct
5 Correct 2 ms 3444 KB Output is correct
6 Correct 2 ms 3404 KB Output is correct
7 Correct 2 ms 3404 KB Output is correct
8 Correct 2 ms 3432 KB Output is correct
9 Correct 2 ms 3404 KB Output is correct
10 Correct 11 ms 4940 KB Output is correct
11 Correct 10 ms 4940 KB Output is correct
12 Correct 9 ms 5016 KB Output is correct
13 Correct 10 ms 4984 KB Output is correct
14 Correct 10 ms 4980 KB Output is correct
15 Correct 11 ms 5068 KB Output is correct
16 Correct 960 ms 112068 KB Output is correct
17 Correct 1143 ms 111856 KB Output is correct
18 Correct 960 ms 111428 KB Output is correct
19 Correct 840 ms 110268 KB Output is correct
20 Correct 889 ms 110640 KB Output is correct
21 Correct 949 ms 112068 KB Output is correct
22 Correct 864 ms 110292 KB Output is correct
23 Correct 977 ms 111664 KB Output is correct
24 Correct 807 ms 108980 KB Output is correct
25 Correct 659 ms 110068 KB Output is correct
26 Correct 739 ms 109976 KB Output is correct
27 Correct 768 ms 109712 KB Output is correct
28 Correct 1082 ms 114784 KB Output is correct
29 Correct 1101 ms 114676 KB Output is correct
30 Correct 1088 ms 114748 KB Output is correct
31 Correct 1068 ms 114824 KB Output is correct
32 Correct 867 ms 110392 KB Output is correct
33 Correct 1189 ms 111852 KB Output is correct
34 Correct 409 ms 42464 KB Output is correct
35 Correct 1269 ms 112712 KB Output is correct
36 Correct 1117 ms 112384 KB Output is correct
37 Correct 1205 ms 112272 KB Output is correct
38 Correct 1133 ms 112648 KB Output is correct
39 Correct 1130 ms 113748 KB Output is correct
40 Correct 1255 ms 118932 KB Output is correct
41 Correct 996 ms 110928 KB Output is correct
42 Correct 861 ms 109524 KB Output is correct
43 Correct 1441 ms 116060 KB Output is correct
44 Correct 1300 ms 111940 KB Output is correct
45 Correct 901 ms 112116 KB Output is correct
46 Correct 1022 ms 112560 KB Output is correct
47 Correct 1103 ms 114876 KB Output is correct
48 Correct 1148 ms 114704 KB Output is correct
49 Correct 1120 ms 114856 KB Output is correct
50 Correct 1115 ms 114796 KB Output is correct
51 Correct 1184 ms 118588 KB Output is correct
52 Correct 1143 ms 119000 KB Output is correct