Submission #916552

# Submission time Handle Problem Language Result Execution time Memory
916552 2024-01-26T05:34:14 Z 12345678 Werewolf (IOI18_werewolf) C++17
100 / 100
600 ms 110100 KB
#include "werewolf.h"
#include <bits/stdc++.h>

using namespace std;

const int nx=4e5+5;
int dsu[nx], id[nx][2], idx, cnt, l[nx][2], r[nx][2], p[nx][2], res[nx];
vector<int> d[nx], a[nx], ans;
vector<pair<int, int>> c[nx];
vector<tuple<int, int, int>> eds, edt;

struct fenwick
{
    int d[nx];
    void add(int i)
    {
        while (i<nx) d[i]++, i+=(i&-i);
    }
    int find(int i)
    {
        int res=0;
        while (i>0) res+=d[i], i-=(i&-i);
        return res;
    }
} f;

int find(int x)
{
    if (dsu[x]==x) return x;
    return dsu[x]=find(dsu[x]);
}

void dfs(int u, int m)
{
    //cout<<"dfs "<<u<<'\n';
    l[u][m]=INT_MAX;
    if (d[u].empty()) return id[u][m]=l[u][m]=r[u][m]=++cnt, void();
    for (auto v:d[u]) dfs(v, m), l[u][m]=min(l[u][m], l[v][m]), r[u][m]=max(r[u][m], r[v][m]);
}

std::vector<int> check_validity(int N, std::vector<int> X, std::vector<int> Y,
                                std::vector<int> S, std::vector<int> E,
                                std::vector<int> L, std::vector<int> R) {
    for (int i=0; i<X.size(); i++) if (X[i]<Y[i]) swap(X[i], Y[i]);
    for (int i=0; i<X.size(); i++) eds.push_back({Y[i], 0, X[i]}), edt.push_back({X[i], 0, Y[i]});
    for (int i=0; i<S.size(); i++) eds.push_back({L[i], -1, i}), edt.push_back({R[i], 1, i});
    sort(eds.begin(), eds.end());
    reverse(eds.begin(), eds.end());
    sort(edt.begin(), edt.end());
    for (int i=0; i<2*N-1; i++) dsu[i]=i;
    idx=N;
    for (auto [u, t, v]:eds) 
    {
        //cout<<"update "<<u<<' '<<t<<' '<<v<<'\n';
        if (t==-1) p[v][0]=find(S[v]); //cout<<"find "<<v<<' '<<S[v]<<' '<<find(S[v])<<'\n';
        else if (find(u)!=find(v)) d[idx].push_back(find(u)), d[idx].push_back(find(v)), dsu[find(u)]=dsu[find(v)]=idx++; //cout<<"add edge "<<u<<' '<<v<<' '<<idx<<'\n';
    }
    dfs(idx-1, 0);
    idx=N;
    cnt=0;
    for (int i=0; i<2*N-1; i++) dsu[i]=i, d[i].clear();
    for (auto [u, t, v]:edt) 
    {
        //cout<<"update "<<u<<' '<<t<<' '<<v<<'\n';
        if (t==1) p[v][1]=find(E[v]); //cout<<"find "<<v<<' '<<S[v]<<' '<<find(S[v])<<'\n';
        else if (find(u)!=find(v)) d[idx].push_back(find(u)), d[idx].push_back(find(v)), dsu[find(u)]=dsu[find(v)]=idx++; //cout<<"add edge "<<u<<' '<<v<<' '<<idx<<'\n';
    }
    dfs(idx-1, 1);
    /*
    cout<<"id ";
    for (int i=0; i<N; i++) cout<<id[i][1]<<' ';
    cout<<'\n';
    for (int i=0; i<S.size(); i++) cout<<i<<' '<<p[i]<<' '<<l[p[i]][1]<<' '<<r[p[i]][1]<<'\n';*/
    //for (int i=0; i<S.size(); i++) cout<<"range "<<i<<' '<<l[p[i]][0]<<' '<<l[p[i]][1]<<' '<<r[p[]i][0]<<' '<<r[i][1]<<'\n';
    for (int i=0; i<S.size(); i++) c[l[p[i][0]][0]-1].push_back({-1, i}), c[r[p[i][0]][0]].push_back({1, i});
    for (int i=0; i<N; i++) a[id[i][0]].push_back(id[i][1]);
    for (int i=0; i<=N; i++)
    {
        for (auto y:a[i]) f.add(y);
        for (auto [mul, j]:c[i]) res[j]+=(f.find(r[p[j][1]][1])-f.find(l[p[j][1]][1]-1))*mul;
    }
    for (int i=0; i<S.size(); i++) ans.push_back(res[i]>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:44:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for (int i=0; i<X.size(); i++) if (X[i]<Y[i]) swap(X[i], Y[i]);
      |                   ~^~~~~~~~~
werewolf.cpp:45:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   45 |     for (int i=0; i<X.size(); i++) eds.push_back({Y[i], 0, X[i]}), edt.push_back({X[i], 0, Y[i]});
      |                   ~^~~~~~~~~
werewolf.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |     for (int i=0; i<S.size(); i++) eds.push_back({L[i], -1, i}), edt.push_back({R[i], 1, i});
      |                   ~^~~~~~~~~
werewolf.cpp:75:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |     for (int i=0; i<S.size(); i++) c[l[p[i][0]][0]-1].push_back({-1, i}), c[r[p[i][0]][0]].push_back({1, i});
      |                   ~^~~~~~~~~
werewolf.cpp:82:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   82 |     for (int i=0; i<S.size(); i++) ans.push_back(res[i]>0);
      |                   ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 11 ms 41308 KB Output is correct
2 Correct 11 ms 41308 KB Output is correct
3 Correct 11 ms 41308 KB Output is correct
4 Correct 11 ms 41308 KB Output is correct
5 Correct 12 ms 41308 KB Output is correct
6 Correct 11 ms 41308 KB Output is correct
7 Correct 12 ms 41308 KB Output is correct
8 Correct 11 ms 41308 KB Output is correct
9 Correct 12 ms 41540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 41308 KB Output is correct
2 Correct 11 ms 41308 KB Output is correct
3 Correct 11 ms 41308 KB Output is correct
4 Correct 11 ms 41308 KB Output is correct
5 Correct 12 ms 41308 KB Output is correct
6 Correct 11 ms 41308 KB Output is correct
7 Correct 12 ms 41308 KB Output is correct
8 Correct 11 ms 41308 KB Output is correct
9 Correct 12 ms 41540 KB Output is correct
10 Correct 16 ms 42332 KB Output is correct
11 Correct 15 ms 42304 KB Output is correct
12 Correct 15 ms 42248 KB Output is correct
13 Correct 16 ms 42332 KB Output is correct
14 Correct 16 ms 42332 KB Output is correct
15 Correct 16 ms 42376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 538 ms 94872 KB Output is correct
2 Correct 351 ms 100392 KB Output is correct
3 Correct 368 ms 96168 KB Output is correct
4 Correct 403 ms 93472 KB Output is correct
5 Correct 401 ms 94872 KB Output is correct
6 Correct 420 ms 94548 KB Output is correct
7 Correct 470 ms 91936 KB Output is correct
8 Correct 343 ms 101968 KB Output is correct
9 Correct 345 ms 93988 KB Output is correct
10 Correct 346 ms 92704 KB Output is correct
11 Correct 355 ms 91604 KB Output is correct
12 Correct 423 ms 91420 KB Output is correct
13 Correct 345 ms 100464 KB Output is correct
14 Correct 334 ms 100372 KB Output is correct
15 Correct 362 ms 100136 KB Output is correct
16 Correct 330 ms 100312 KB Output is correct
17 Correct 491 ms 95004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 41308 KB Output is correct
2 Correct 11 ms 41308 KB Output is correct
3 Correct 11 ms 41308 KB Output is correct
4 Correct 11 ms 41308 KB Output is correct
5 Correct 12 ms 41308 KB Output is correct
6 Correct 11 ms 41308 KB Output is correct
7 Correct 12 ms 41308 KB Output is correct
8 Correct 11 ms 41308 KB Output is correct
9 Correct 12 ms 41540 KB Output is correct
10 Correct 16 ms 42332 KB Output is correct
11 Correct 15 ms 42304 KB Output is correct
12 Correct 15 ms 42248 KB Output is correct
13 Correct 16 ms 42332 KB Output is correct
14 Correct 16 ms 42332 KB Output is correct
15 Correct 16 ms 42376 KB Output is correct
16 Correct 538 ms 94872 KB Output is correct
17 Correct 351 ms 100392 KB Output is correct
18 Correct 368 ms 96168 KB Output is correct
19 Correct 403 ms 93472 KB Output is correct
20 Correct 401 ms 94872 KB Output is correct
21 Correct 420 ms 94548 KB Output is correct
22 Correct 470 ms 91936 KB Output is correct
23 Correct 343 ms 101968 KB Output is correct
24 Correct 345 ms 93988 KB Output is correct
25 Correct 346 ms 92704 KB Output is correct
26 Correct 355 ms 91604 KB Output is correct
27 Correct 423 ms 91420 KB Output is correct
28 Correct 345 ms 100464 KB Output is correct
29 Correct 334 ms 100372 KB Output is correct
30 Correct 362 ms 100136 KB Output is correct
31 Correct 330 ms 100312 KB Output is correct
32 Correct 491 ms 95004 KB Output is correct
33 Correct 600 ms 97368 KB Output is correct
34 Correct 317 ms 88824 KB Output is correct
35 Correct 496 ms 102208 KB Output is correct
36 Correct 508 ms 97384 KB Output is correct
37 Correct 565 ms 99828 KB Output is correct
38 Correct 482 ms 95940 KB Output is correct
39 Correct 455 ms 109596 KB Output is correct
40 Correct 497 ms 109400 KB Output is correct
41 Correct 427 ms 99360 KB Output is correct
42 Correct 394 ms 93220 KB Output is correct
43 Correct 462 ms 106812 KB Output is correct
44 Correct 449 ms 98484 KB Output is correct
45 Correct 410 ms 107376 KB Output is correct
46 Correct 412 ms 108832 KB Output is correct
47 Correct 367 ms 100640 KB Output is correct
48 Correct 356 ms 100380 KB Output is correct
49 Correct 344 ms 100592 KB Output is correct
50 Correct 340 ms 102732 KB Output is correct
51 Correct 452 ms 108460 KB Output is correct
52 Correct 429 ms 110100 KB Output is correct