Submission #733788

# Submission time Handle Problem Language Result Execution time Memory
733788 2023-05-01T10:15:59 Z neki Werewolf (IOI18_werewolf) C++14
100 / 100
840 ms 125668 KB
#include <bits/stdc++.h>
#include "werewolf.h"
#define vc vector

using namespace std;

vc<int> check_validity(int n, vc<int> a, vc<int> b, vc<int> S, vc<int> E, vc<int> ql, vc<int> qr){
    int m=a.size(), Q=S.size();
    
    for(int i=0;i<m;++i)if(a[i]>b[i])swap(a[i],b[i]);
    vc<vc<int>> ledg(n), redg(n);for(int i=0;i<m;++i)ledg[b[i]].push_back(a[i]),redg[a[i]].push_back(b[i]);
    
    vc<vc<int>> lqs(n), rqs(n);for(int i=0;i<Q;++i)lqs[qr[i]].push_back(i),rqs[ql[i]].push_back(i);
    
    vc<int> ldsu(n),rdsu(n);for(int i=0;i<n;++i)ldsu[i]=i,rdsu[i]=i;
    function<int(int,vc<int>&)> fnd=[&fnd](int u,vc<int>& dsu){return (u==dsu[u])?u:dsu[u]=fnd(dsu[u],dsu);};
    vc<vc<int>> ltr(n),rtr(n);
    vc<int> lranno(Q),rranno(Q);
    for(int u=0;u<n;++u){
        for(auto v:ledg[u]){int pv=fnd(v,ldsu);if(pv!=u)ldsu[pv]=u,ltr[u].push_back(pv);}
        for(auto q:lqs[u])lranno[q]=fnd(E[q],ldsu);
    }
    for(int u=n-1;u>=0;--u){
        for(auto v:redg[u]){int pv=fnd(v,rdsu);if(pv!=u)rdsu[pv]=u,rtr[u].push_back(pv);}
        for(auto q:rqs[u])rranno[q]=fnd(S[q],rdsu);
    }
    
    function<void(int,int&,vc<vc<int>>&,vc<int>&,vc<int>&)> eul=[&eul](int u,int& T,vc<vc<int>>& tr,vc<int>& lran,vc<int>& rran){
        lran[u]=T++;
        for(auto v:tr[u])eul(v,T,tr,lran,rran);
        rran[u]=T;
    };
    int lT=0,rT=0;
    vc<int> lranx(n),rranx(n),lrany(n),rrany(n);
    for(int u=0;u<n;++u)if(u==ldsu[u])eul(u,lT,ltr,lranx,rranx);
    for(int u=n-1;u>=0;--u)if(u==rdsu[u])eul(u,rT,rtr,lrany,rrany);
    assert(lT==n&&rT==n);
    
    vc<array<int,3>> sw;
    
    for(int i=0;i<Q;++i)sw.emplace_back(array<int,3>{lranx[lranno[i]],0,i});
    for(int i=0;i<n;++i)sw.emplace_back(array<int,3>{lranx[i],1,lrany[i]});
    sort(sw.begin(),sw.end());
    
    vc<int> ans(Q,0);
    vc<vc<int>> sgtr(2*n);
    for(auto q:sw){
        if(q[1]==0){
            int i=q[2];
            for(int l=lrany[rranno[i]]+n, r=rrany[rranno[i]]+n;l<r;l>>=1,r>>=1){
                if(l&1)sgtr[l++].push_back(i);
                if(r&1)sgtr[--r].push_back(i);
            }
        }
        if(q[1]==1){
            for(int y=q[2]+n;y>0;y>>=1){
                while(sgtr[y].size()){int i=sgtr[y].back();sgtr[y].pop_back();if(q[0]<rranx[lranno[i]])ans[i]=1;}
            }
        }
        
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 7 ms 1716 KB Output is correct
11 Correct 7 ms 1748 KB Output is correct
12 Correct 9 ms 1792 KB Output is correct
13 Correct 7 ms 2032 KB Output is correct
14 Correct 6 ms 2004 KB Output is correct
15 Correct 7 ms 1876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 704 ms 88272 KB Output is correct
2 Correct 729 ms 115836 KB Output is correct
3 Correct 682 ms 110344 KB Output is correct
4 Correct 667 ms 102772 KB Output is correct
5 Correct 745 ms 101364 KB Output is correct
6 Correct 840 ms 97436 KB Output is correct
7 Correct 598 ms 99556 KB Output is correct
8 Correct 750 ms 115816 KB Output is correct
9 Correct 621 ms 100988 KB Output is correct
10 Correct 543 ms 100856 KB Output is correct
11 Correct 561 ms 97012 KB Output is correct
12 Correct 536 ms 95900 KB Output is correct
13 Correct 697 ms 123700 KB Output is correct
14 Correct 683 ms 125668 KB Output is correct
15 Correct 680 ms 123864 KB Output is correct
16 Correct 686 ms 124440 KB Output is correct
17 Correct 523 ms 100652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 300 KB Output is correct
7 Correct 1 ms 304 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 7 ms 1716 KB Output is correct
11 Correct 7 ms 1748 KB Output is correct
12 Correct 9 ms 1792 KB Output is correct
13 Correct 7 ms 2032 KB Output is correct
14 Correct 6 ms 2004 KB Output is correct
15 Correct 7 ms 1876 KB Output is correct
16 Correct 704 ms 88272 KB Output is correct
17 Correct 729 ms 115836 KB Output is correct
18 Correct 682 ms 110344 KB Output is correct
19 Correct 667 ms 102772 KB Output is correct
20 Correct 745 ms 101364 KB Output is correct
21 Correct 840 ms 97436 KB Output is correct
22 Correct 598 ms 99556 KB Output is correct
23 Correct 750 ms 115816 KB Output is correct
24 Correct 621 ms 100988 KB Output is correct
25 Correct 543 ms 100856 KB Output is correct
26 Correct 561 ms 97012 KB Output is correct
27 Correct 536 ms 95900 KB Output is correct
28 Correct 697 ms 123700 KB Output is correct
29 Correct 683 ms 125668 KB Output is correct
30 Correct 680 ms 123864 KB Output is correct
31 Correct 686 ms 124440 KB Output is correct
32 Correct 523 ms 100652 KB Output is correct
33 Correct 672 ms 97516 KB Output is correct
34 Correct 289 ms 45240 KB Output is correct
35 Correct 739 ms 102908 KB Output is correct
36 Correct 720 ms 98032 KB Output is correct
37 Correct 725 ms 101172 KB Output is correct
38 Correct 744 ms 99068 KB Output is correct
39 Correct 699 ms 120180 KB Output is correct
40 Correct 802 ms 115160 KB Output is correct
41 Correct 704 ms 98108 KB Output is correct
42 Correct 531 ms 93584 KB Output is correct
43 Correct 826 ms 111536 KB Output is correct
44 Correct 650 ms 99432 KB Output is correct
45 Correct 603 ms 116392 KB Output is correct
46 Correct 557 ms 117228 KB Output is correct
47 Correct 655 ms 122008 KB Output is correct
48 Correct 651 ms 121944 KB Output is correct
49 Correct 660 ms 124512 KB Output is correct
50 Correct 681 ms 122428 KB Output is correct
51 Correct 607 ms 115852 KB Output is correct
52 Correct 609 ms 117124 KB Output is correct