Submission #124051

# Submission time Handle Problem Language Result Execution time Memory
124051 2019-07-02T12:26:41 Z RockyB Werewolf (IOI18_werewolf) C++17
100 / 100
828 ms 148984 KB
#include "werewolf.h"
#include <bits/stdc++.h>

#define f first
#define s second

#define pb push_back
#define pp pop_back
#define mp make_pair

#define sz(x) (int)x.size()
#define sqr(x) ((x) * 1ll * (x))
#define all(x) x.begin(), x.end()

#define rep(i, l, r) for (int i = (l); i < (r); i++)
#define per(i, l, r) for (int i = (l); i >= (r); i--)

#define Kazakhstan ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0);

#define nl '\n'
#define ioi exit(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int MAXN = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const ll linf = (ll)1e18 + 7;

const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};

using namespace std;

int n;
vector <int> X, Y, L, R, S, E;
vector <int> g[MAXN], adj[2][MAXN];

bool was[MAXN];

struct dsu {
  int p[MAXN];
  int get(int i) {
    return p[i] == i ? i : p[i] = get(p[i]);
  }
} d;

struct fenwick {
  int f[MAXN];
  void upd(int p, int x) {
    for (; p < MAXN; p |= p + 1) f[p] += x;
  }
  int get(int p) {
    int sum = 0;
    for (; p >= 0; p = (p & (p + 1)) - 1) sum += f[p];
    return sum;
  }
} f;

vector < pair <int, int> > q[2][MAXN];
vector < array <int, 4> > qu[MAXN]; /// i, f, l, r
int sum[MAXN];
int par[2][MAXN];

int tmr;
int tin[2][MAXN], tout[2][MAXN];
int a[2][MAXN];
void dfs(int v, int id) {
  tin[id][v] = ++tmr;
  a[id][tmr] = v;
  /*
  {
    / *
      TODO:
        Then Delete it (it's just for debug)
    * /
    cerr << v << " -> ";
    for (auto to : adj[id][v]) {
      {
        cerr << to << ' ';
      }
    }
    cerr << nl;
  }
  */
  for (auto to : adj[id][v]) {
    if (!tin[id][to]) {
      dfs(to, id);
    }
  }
  tout[id][v] = tmr;
}

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;
  X = _X;
  Y = _Y;
  S = _S;
  E = _E;
  L = _L;
  R = _R;
  // copy finished
  // checked 1

  rep(i, 0, sz(X)) {
    g[X[i]].pb(Y[i]);
    g[Y[i]].pb(X[i]);
  }
  // checked 1

  rep(i, 0, sz(S)) {
    q[0][L[i]].pb({S[i], i});
    q[1][R[i]].pb({E[i], i});
  }
  // checked 1
  
  per(i, n - 1, 0) {
    d.p[i] = i;
    for (auto to : g[i]) {
      if (!was[to] || d.get(to) == i) continue;
      adj[0][i].pb(d.get(to));
      d.p[d.get(to)] = i;
    }
    for (auto it : q[0][i]) {
      par[0][it.s] = d.get(it.f);
    }
    was[i] = 1;
  }
  // checked 1

  memset(was, 0, sizeof(was));
  rep(i, 0, n) {
    d.p[i] = i;
    for (auto to : g[i]) {
      if (!was[to] || d.get(to) == i) continue;
      adj[1][i].pb(d.get(to));
      d.p[d.get(to)] = i;
    }
    for (auto it : q[1][i]) {
      par[1][it.s] = d.get(it.f);
    }
    was[i] = 1;
  }
  // checked 1

  dfs(0, 0);
  tmr = 0;
  dfs(n - 1, 1);
  // checked 1

  rep(i, 0, sz(S)) {
    int v1 = par[0][i];
    int l1 = tin[0][v1], r1 = tout[0][v1];
    int v2 = par[1][i];
    int l2 = tin[1][v2], r2 = tout[1][v2];

    if (l1) qu[l1 - 1].pb({i, -1, l2, r2});
    qu[r1].pb({i, 1, l2, r2});
  }
  vector <int> ans(sz(S)), pos(n, 0);
  rep(i, 1, n + 1) pos[a[1][i]] = i;
  rep(i, 1, n + 1) {
    f.upd(pos[a[0][i]], 1);
    for (auto it : qu[i]) {
      ans[it[0]] += it[1] * (f.get(it[3]) - f.get(it[2] - 1));
    }
  }
  rep(i, 0, sz(ans)) {
    assert(ans[i] >= 0);
    if (ans[i] > 0) ans[i] = 1;
    else ans[i] = 0;
  }
  return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 67 ms 71416 KB Output is correct
2 Correct 67 ms 71504 KB Output is correct
3 Correct 66 ms 71416 KB Output is correct
4 Correct 66 ms 71416 KB Output is correct
5 Correct 66 ms 71388 KB Output is correct
6 Correct 66 ms 71416 KB Output is correct
7 Correct 67 ms 71428 KB Output is correct
8 Correct 67 ms 71416 KB Output is correct
9 Correct 66 ms 71544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 71416 KB Output is correct
2 Correct 67 ms 71504 KB Output is correct
3 Correct 66 ms 71416 KB Output is correct
4 Correct 66 ms 71416 KB Output is correct
5 Correct 66 ms 71388 KB Output is correct
6 Correct 66 ms 71416 KB Output is correct
7 Correct 67 ms 71428 KB Output is correct
8 Correct 67 ms 71416 KB Output is correct
9 Correct 66 ms 71544 KB Output is correct
10 Correct 72 ms 72412 KB Output is correct
11 Correct 71 ms 72312 KB Output is correct
12 Correct 85 ms 72312 KB Output is correct
13 Correct 86 ms 72568 KB Output is correct
14 Correct 74 ms 72568 KB Output is correct
15 Correct 74 ms 72440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 776 ms 135000 KB Output is correct
2 Correct 645 ms 139384 KB Output is correct
3 Correct 607 ms 135672 KB Output is correct
4 Correct 633 ms 133596 KB Output is correct
5 Correct 638 ms 133592 KB Output is correct
6 Correct 736 ms 134904 KB Output is correct
7 Correct 657 ms 130736 KB Output is correct
8 Correct 621 ms 139348 KB Output is correct
9 Correct 580 ms 133216 KB Output is correct
10 Correct 569 ms 132064 KB Output is correct
11 Correct 592 ms 132184 KB Output is correct
12 Correct 668 ms 132308 KB Output is correct
13 Correct 674 ms 143808 KB Output is correct
14 Correct 753 ms 143912 KB Output is correct
15 Correct 668 ms 143832 KB Output is correct
16 Correct 718 ms 144144 KB Output is correct
17 Correct 658 ms 130744 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 67 ms 71416 KB Output is correct
2 Correct 67 ms 71504 KB Output is correct
3 Correct 66 ms 71416 KB Output is correct
4 Correct 66 ms 71416 KB Output is correct
5 Correct 66 ms 71388 KB Output is correct
6 Correct 66 ms 71416 KB Output is correct
7 Correct 67 ms 71428 KB Output is correct
8 Correct 67 ms 71416 KB Output is correct
9 Correct 66 ms 71544 KB Output is correct
10 Correct 72 ms 72412 KB Output is correct
11 Correct 71 ms 72312 KB Output is correct
12 Correct 85 ms 72312 KB Output is correct
13 Correct 86 ms 72568 KB Output is correct
14 Correct 74 ms 72568 KB Output is correct
15 Correct 74 ms 72440 KB Output is correct
16 Correct 776 ms 135000 KB Output is correct
17 Correct 645 ms 139384 KB Output is correct
18 Correct 607 ms 135672 KB Output is correct
19 Correct 633 ms 133596 KB Output is correct
20 Correct 638 ms 133592 KB Output is correct
21 Correct 736 ms 134904 KB Output is correct
22 Correct 657 ms 130736 KB Output is correct
23 Correct 621 ms 139348 KB Output is correct
24 Correct 580 ms 133216 KB Output is correct
25 Correct 569 ms 132064 KB Output is correct
26 Correct 592 ms 132184 KB Output is correct
27 Correct 668 ms 132308 KB Output is correct
28 Correct 674 ms 143808 KB Output is correct
29 Correct 753 ms 143912 KB Output is correct
30 Correct 668 ms 143832 KB Output is correct
31 Correct 718 ms 144144 KB Output is correct
32 Correct 658 ms 130744 KB Output is correct
33 Correct 811 ms 135696 KB Output is correct
34 Correct 411 ms 122484 KB Output is correct
35 Correct 772 ms 139512 KB Output is correct
36 Correct 750 ms 136020 KB Output is correct
37 Correct 780 ms 138232 KB Output is correct
38 Correct 802 ms 136824 KB Output is correct
39 Correct 748 ms 148984 KB Output is correct
40 Correct 769 ms 143656 KB Output is correct
41 Correct 722 ms 136308 KB Output is correct
42 Correct 606 ms 132316 KB Output is correct
43 Correct 820 ms 145432 KB Output is correct
44 Correct 739 ms 137960 KB Output is correct
45 Correct 604 ms 146496 KB Output is correct
46 Correct 603 ms 146928 KB Output is correct
47 Correct 709 ms 144088 KB Output is correct
48 Correct 682 ms 143980 KB Output is correct
49 Correct 828 ms 144344 KB Output is correct
50 Correct 658 ms 143960 KB Output is correct
51 Correct 725 ms 142944 KB Output is correct
52 Correct 733 ms 143092 KB Output is correct