Submission #195357

# Submission time Handle Problem Language Result Execution time Memory
195357 2020-01-16T07:21:00 Z kdh9949 Werewolf (IOI18_werewolf) C++17
100 / 100
1998 ms 149496 KB
#include "werewolf.h"
#include <bits/stdc++.h>
using namespace std;

const int N = 200005, LG = 18;

int n, q, p[2 * N], tim[2][2 * N], sgs[2][2 * N], sge[2][2 * N], cnt;
int sp[2][LG][2 * N];
vector<int> e[N], t[2 * N];

struct Qry{ int i, s, e, sgn; };
vector<Qry> qv[N];
vector<int> pos[N];

int f(int x){ return p[x] = (x == p[x] ? x : f(p[x])); }

void aft(int id, int x){
  if(x < n){
    sgs[id][x] = sge[id][x] = ++cnt;
    return;
  }
  sgs[id][x] = N;
  for(int i : t[x]){
    aft(id, i);
    sgs[id][x] = min(sgs[id][x], sgs[id][i]);
    sge[id][x] = max(sge[id][x], sge[id][i]);
  }
}

struct Fen{
  int d[N];
  void u(int x){ for(; x < N; x += x & -x) d[x]++; }
  int g(int x){ int r = 0; for(; x; x &= x - 1) r += d[x]; return r; }
  int g(int s, int e){ return g(e) - g(s - 1); }
} F;

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;
  q = S.size();

  for(int i = 0; i < X.size(); i++){
    e[X[i]].push_back(Y[i]);
    e[Y[i]].push_back(X[i]);
  }

  iota(p, p + 2 * n, 0);
  cnt = n;
  for(int i = 1; i < n; i++){
    for(int j : e[i]){
      if(j > i || f(j) == f(i)) continue;
      int x = f(i), y = f(j);
      sp[0][0][x] = sp[0][0][y] = p[x] = p[y] = cnt;
      tim[0][cnt] = i;
      t[cnt].push_back(x);
      t[cnt].push_back(y);
      cnt++;
    }
  }
  cnt = 0;
  aft(0, 2 * n - 2);

  iota(p, p + 2 * n, 0);
  for(int i = 0; i < 2 * n; i++) t[i].clear();
  cnt = n;
  for(int i = n - 2; i >= 0; i--){
    for(int j : e[i]){
      if(j < i || f(j) == f(i)) continue;
      int x = f(i), y = f(j);
      sp[1][0][x] = sp[1][0][y] = p[x] = p[y] = cnt;
      tim[1][cnt] = i;
      t[cnt].push_back(x);
      t[cnt].push_back(y);
      cnt++;
    }
  }
  cnt = 0;
  aft(1, 2 * n - 2);

  for(int id = 0; id < 2; id++){
    sp[id][0][2 * n - 2] = 2 * n - 2;
    for(int j = 1; j < LG; j++){
      for(int k = 0; k < 2 * n - 1; k++){
        sp[id][j][k] = sp[id][j - 1][sp[id][j - 1][k]];
      }
    }
  }

  for(int i = 0; i < n; i++) pos[sgs[0][i]].push_back(sgs[1][i]);
  for(int i = 0; i < q; i++){
    int x = S[i];
    for(int j = LG-1; j >= 0; j--) if(tim[1][sp[1][j][x]] >= L[i]) x = sp[1][j][x];
    int y = E[i];
    for(int j = LG-1; j >= 0; j--) if(tim[0][sp[0][j][y]] <= R[i]) y = sp[0][j][y];

    qv[sgs[0][y] - 1].push_back({i, sgs[1][x], sge[1][x], -1});
    qv[sge[0][y]].push_back({i, sgs[1][x], sge[1][x], 1});
  }

  vector<int> res(q, 0);
  for(int i = 1; i <= n; i++){
    for(int j : pos[i]) F.u(j);
    for(Qry &j : qv[i]) res[j.i] += j.sgn * F.g(j.s, j.e);
  }

  for(int &i : res) i = !!i;
  return res;
}

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:42:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int i = 0; i < X.size(); i++){
                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 31 ms 24312 KB Output is correct
2 Correct 25 ms 24184 KB Output is correct
3 Correct 30 ms 24156 KB Output is correct
4 Correct 25 ms 24184 KB Output is correct
5 Correct 25 ms 24128 KB Output is correct
6 Correct 25 ms 24132 KB Output is correct
7 Correct 25 ms 24184 KB Output is correct
8 Correct 25 ms 24184 KB Output is correct
9 Correct 25 ms 24184 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 24312 KB Output is correct
2 Correct 25 ms 24184 KB Output is correct
3 Correct 30 ms 24156 KB Output is correct
4 Correct 25 ms 24184 KB Output is correct
5 Correct 25 ms 24128 KB Output is correct
6 Correct 25 ms 24132 KB Output is correct
7 Correct 25 ms 24184 KB Output is correct
8 Correct 25 ms 24184 KB Output is correct
9 Correct 25 ms 24184 KB Output is correct
10 Correct 35 ms 25888 KB Output is correct
11 Correct 33 ms 25720 KB Output is correct
12 Correct 34 ms 25848 KB Output is correct
13 Correct 33 ms 25848 KB Output is correct
14 Correct 33 ms 25848 KB Output is correct
15 Correct 39 ms 25864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1612 ms 129260 KB Output is correct
2 Correct 1517 ms 143592 KB Output is correct
3 Correct 1387 ms 139584 KB Output is correct
4 Correct 1400 ms 137272 KB Output is correct
5 Correct 1385 ms 137088 KB Output is correct
6 Correct 1454 ms 137100 KB Output is correct
7 Correct 1334 ms 135364 KB Output is correct
8 Correct 1315 ms 143596 KB Output is correct
9 Correct 951 ms 139432 KB Output is correct
10 Correct 655 ms 135852 KB Output is correct
11 Correct 791 ms 136864 KB Output is correct
12 Correct 768 ms 136672 KB Output is correct
13 Correct 1452 ms 142232 KB Output is correct
14 Correct 1439 ms 142164 KB Output is correct
15 Correct 1433 ms 142200 KB Output is correct
16 Correct 1440 ms 142280 KB Output is correct
17 Correct 1320 ms 135200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 24312 KB Output is correct
2 Correct 25 ms 24184 KB Output is correct
3 Correct 30 ms 24156 KB Output is correct
4 Correct 25 ms 24184 KB Output is correct
5 Correct 25 ms 24128 KB Output is correct
6 Correct 25 ms 24132 KB Output is correct
7 Correct 25 ms 24184 KB Output is correct
8 Correct 25 ms 24184 KB Output is correct
9 Correct 25 ms 24184 KB Output is correct
10 Correct 35 ms 25888 KB Output is correct
11 Correct 33 ms 25720 KB Output is correct
12 Correct 34 ms 25848 KB Output is correct
13 Correct 33 ms 25848 KB Output is correct
14 Correct 33 ms 25848 KB Output is correct
15 Correct 39 ms 25864 KB Output is correct
16 Correct 1612 ms 129260 KB Output is correct
17 Correct 1517 ms 143592 KB Output is correct
18 Correct 1387 ms 139584 KB Output is correct
19 Correct 1400 ms 137272 KB Output is correct
20 Correct 1385 ms 137088 KB Output is correct
21 Correct 1454 ms 137100 KB Output is correct
22 Correct 1334 ms 135364 KB Output is correct
23 Correct 1315 ms 143596 KB Output is correct
24 Correct 951 ms 139432 KB Output is correct
25 Correct 655 ms 135852 KB Output is correct
26 Correct 791 ms 136864 KB Output is correct
27 Correct 768 ms 136672 KB Output is correct
28 Correct 1452 ms 142232 KB Output is correct
29 Correct 1439 ms 142164 KB Output is correct
30 Correct 1433 ms 142200 KB Output is correct
31 Correct 1440 ms 142280 KB Output is correct
32 Correct 1320 ms 135200 KB Output is correct
33 Correct 1724 ms 139396 KB Output is correct
34 Correct 426 ms 63308 KB Output is correct
35 Correct 1826 ms 143684 KB Output is correct
36 Correct 1633 ms 138536 KB Output is correct
37 Correct 1688 ms 142656 KB Output is correct
38 Correct 1998 ms 139276 KB Output is correct
39 Correct 1469 ms 148748 KB Output is correct
40 Correct 1407 ms 145836 KB Output is correct
41 Correct 1126 ms 140276 KB Output is correct
42 Correct 775 ms 136932 KB Output is correct
43 Correct 1503 ms 147488 KB Output is correct
44 Correct 1417 ms 142080 KB Output is correct
45 Correct 1037 ms 149496 KB Output is correct
46 Correct 1088 ms 149068 KB Output is correct
47 Correct 1427 ms 142412 KB Output is correct
48 Correct 1441 ms 142400 KB Output is correct
49 Correct 1507 ms 142480 KB Output is correct
50 Correct 1448 ms 142188 KB Output is correct
51 Correct 1140 ms 147388 KB Output is correct
52 Correct 1141 ms 147348 KB Output is correct