답안 #1018808

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1018808 2024-07-10T09:57:06 Z otarius 늑대인간 (IOI18_werewolf) C++17
100 / 100
511 ms 111988 KB
#include "werewolf.h"
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cstring>
#include <queue>
#include <map>
#include <cmath>
#include <iomanip>
using namespace std;
 
#define ff first
#define sc second
#define pb push_back
#define ll long long
#define pll pair<ll, ll>
#define pii pair <int, int>
#define ull unsigned long long
 
// #define int long long
// #define int unsigned long long
 
const ll inf = 1e9 + 7;
const ll weirdMod = 998244353;
const int maxN = 2e5 + 15;
const int lg = 21;

vector<int> g[maxN], adj[maxN][2], vc; vector<pair<pii, pii>> qs[maxN];
int n, par[maxN][2], p[maxN][lg][2], in[maxN][2], out[maxN][2], tim, t[4 * maxN];
void update(int v, int tl, int tr, int pos, int val) {
    if (tl == tr) {
        t[v] = val;
        return;
    } int tm = (tl + tr) / 2;
    if (pos <= tm) update(2 * v, tl, tm, pos, val);
    else update(2 * v + 1, tm + 1, tr, pos, val);
    t[v] = max(t[2 * v], t[2 * v + 1]);
}
int getmax(int v, int tl, int tr, int l, int r) {
    if (l > r) return -inf;
    if (tl == l && tr == r) return t[v];
    int tm = (tl + tr) / 2;
    return max(getmax(2 * v, tl, tm, l, min(r, tm)),
               getmax(2 * v + 1, tm + 1, tr, max(l, tm + 1), r));
}
void make_set() {
    for (int i = 1; i <= n; i++) {
        par[i][0] = par[i][1] = i;
        p[i][0][0] = p[i][0][1] = i;
    }
}
int find_set(int v, int f) {
    if (par[v][f] == v)
        return v;
    return par[v][f] = find_set(par[v][f], f);
}
void union_set(int x, int y, int f) {
    int rx = find_set(x, f), ry = find_set(y, f);
    if (rx != ry) {
        par[ry][f] = rx;
        p[ry][0][f] = x;
    }
}
void dfs(int v, int f) {
    if (f) vc.pb(v);
    in[v][f] = ++tim;
    for (int u : adj[v][f]) dfs(u, f);
    out[v][f] = tim;
}
int left_lift(int val, int x) {
    for (int i = lg - 1; i >= 0; i--)
        if (p[x][i][1] >= val) x = p[x][i][1];
    return x;
}
int right_lift(int val, int x) {
    for (int i = lg - 1; i >= 0; i--)
        if (p[x][i][0] <= val) x = p[x][i][0];
    return x;
}
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;
    for (int i = 0; i < x.size(); i++) {
        x[i]++; y[i]++;
        g[x[i]].pb(y[i]);
        g[y[i]].pb(x[i]);
    } make_set();
    for (int i = 1; i <= n; i++)
        for (int j : g[i]) if (j < i) union_set(i, j, 0);
    for (int i = n; i >= 1; i--)
        for (int j : g[i]) if (j > i) union_set(i, j, 1);
    for (int i = 1; i <= n; i++) {
        if (p[i][0][0] != i) adj[p[i][0][0]][0].pb(i);
        if (p[i][0][1] != i) adj[p[i][0][1]][1].pb(i);
    } for (int i = 1; i < lg; i++) {
        for (int j = 1; j <= n; j++) {
            p[j][i][0] = p[p[j][i - 1][0]][i - 1][0];
            p[j][i][1] = p[p[j][i - 1][1]][i - 1][1];
        }
    } dfs(n, 0); tim = 0; dfs(1, 1);
    vector<int> ans; ans.resize(s.size());
    for (int i = 0; i < s.size(); i++) {
        s[i]++; e[i]++; l[i]++; r[i]++;
        int rl = left_lift(l[i], s[i]);
        int rr = right_lift(r[i], e[i]);
        qs[out[rl][1]].pb({{i, in[rl][1]}, {in[rr][0], out[rr][0]}});
    } for (int i = 1; i <= n; i++) {
        update(1, 1, n, in[vc[i - 1]][0], i);
        for (auto v : qs[i]) ans[v.ff.ff] = (getmax(1, 1, n, v.sc.ff, v.sc.sc) >= v.ff.sc);
    } 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:83:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   83 |     for (int i = 0; i < x.size(); i++) {
      |                     ~~^~~~~~~~~~
werewolf.cpp:102:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |     for (int i = 0; i < s.size(); i++) {
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 19292 KB Output is correct
2 Correct 7 ms 19152 KB Output is correct
3 Correct 7 ms 19032 KB Output is correct
4 Correct 6 ms 19036 KB Output is correct
5 Correct 7 ms 19288 KB Output is correct
6 Correct 7 ms 19232 KB Output is correct
7 Correct 7 ms 19292 KB Output is correct
8 Correct 6 ms 19288 KB Output is correct
9 Correct 7 ms 19292 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 19292 KB Output is correct
2 Correct 7 ms 19152 KB Output is correct
3 Correct 7 ms 19032 KB Output is correct
4 Correct 6 ms 19036 KB Output is correct
5 Correct 7 ms 19288 KB Output is correct
6 Correct 7 ms 19232 KB Output is correct
7 Correct 7 ms 19292 KB Output is correct
8 Correct 6 ms 19288 KB Output is correct
9 Correct 7 ms 19292 KB Output is correct
10 Correct 10 ms 20316 KB Output is correct
11 Correct 10 ms 20428 KB Output is correct
12 Correct 12 ms 20316 KB Output is correct
13 Correct 10 ms 20528 KB Output is correct
14 Correct 11 ms 20568 KB Output is correct
15 Correct 10 ms 20572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 399 ms 96004 KB Output is correct
2 Correct 407 ms 102096 KB Output is correct
3 Correct 469 ms 98560 KB Output is correct
4 Correct 409 ms 97120 KB Output is correct
5 Correct 424 ms 96984 KB Output is correct
6 Correct 411 ms 97628 KB Output is correct
7 Correct 377 ms 97532 KB Output is correct
8 Correct 375 ms 102060 KB Output is correct
9 Correct 360 ms 97992 KB Output is correct
10 Correct 324 ms 97504 KB Output is correct
11 Correct 322 ms 97376 KB Output is correct
12 Correct 341 ms 96712 KB Output is correct
13 Correct 409 ms 106404 KB Output is correct
14 Correct 422 ms 108120 KB Output is correct
15 Correct 396 ms 106484 KB Output is correct
16 Correct 417 ms 106476 KB Output is correct
17 Correct 384 ms 97476 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 19292 KB Output is correct
2 Correct 7 ms 19152 KB Output is correct
3 Correct 7 ms 19032 KB Output is correct
4 Correct 6 ms 19036 KB Output is correct
5 Correct 7 ms 19288 KB Output is correct
6 Correct 7 ms 19232 KB Output is correct
7 Correct 7 ms 19292 KB Output is correct
8 Correct 6 ms 19288 KB Output is correct
9 Correct 7 ms 19292 KB Output is correct
10 Correct 10 ms 20316 KB Output is correct
11 Correct 10 ms 20428 KB Output is correct
12 Correct 12 ms 20316 KB Output is correct
13 Correct 10 ms 20528 KB Output is correct
14 Correct 11 ms 20568 KB Output is correct
15 Correct 10 ms 20572 KB Output is correct
16 Correct 399 ms 96004 KB Output is correct
17 Correct 407 ms 102096 KB Output is correct
18 Correct 469 ms 98560 KB Output is correct
19 Correct 409 ms 97120 KB Output is correct
20 Correct 424 ms 96984 KB Output is correct
21 Correct 411 ms 97628 KB Output is correct
22 Correct 377 ms 97532 KB Output is correct
23 Correct 375 ms 102060 KB Output is correct
24 Correct 360 ms 97992 KB Output is correct
25 Correct 324 ms 97504 KB Output is correct
26 Correct 322 ms 97376 KB Output is correct
27 Correct 341 ms 96712 KB Output is correct
28 Correct 409 ms 106404 KB Output is correct
29 Correct 422 ms 108120 KB Output is correct
30 Correct 396 ms 106484 KB Output is correct
31 Correct 417 ms 106476 KB Output is correct
32 Correct 384 ms 97476 KB Output is correct
33 Correct 470 ms 98416 KB Output is correct
34 Correct 208 ms 54992 KB Output is correct
35 Correct 485 ms 101888 KB Output is correct
36 Correct 444 ms 98556 KB Output is correct
37 Correct 467 ms 100804 KB Output is correct
38 Correct 441 ms 99140 KB Output is correct
39 Correct 484 ms 111740 KB Output is correct
40 Correct 511 ms 108744 KB Output is correct
41 Correct 382 ms 99268 KB Output is correct
42 Correct 347 ms 96872 KB Output is correct
43 Correct 445 ms 107204 KB Output is correct
44 Correct 409 ms 100548 KB Output is correct
45 Correct 403 ms 111988 KB Output is correct
46 Correct 437 ms 111300 KB Output is correct
47 Correct 472 ms 106504 KB Output is correct
48 Correct 473 ms 106924 KB Output is correct
49 Correct 476 ms 106724 KB Output is correct
50 Correct 445 ms 106452 KB Output is correct
51 Correct 459 ms 108240 KB Output is correct
52 Correct 469 ms 108496 KB Output is correct