답안 #349128

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
349128 2021-01-16T18:01:41 Z two_sides 늑대인간 (IOI18_werewolf) C++17
100 / 100
565 ms 63948 KB
#include <werewolf.h>
#include <bits/stdc++.h>

using namespace std;

#define fi first
#define se second

using pii = pair <int, int>;

struct query {int l, r, t, id;};

const int N = 200005;

int par[2][N], val[2][N], siz[2][N];
vector <int> adj[2][N]; int ver[2][N];
int tin[2][N], tout[2][N], timer;
int ans[N], BIT[N]; vector <query> que[N];

void updateBIT(int i) {
    for (; i < N; i += i & -i) BIT[i]++;
}

int queryBIT(int i) {
    int res = 0;
    for (; i > 0; i -= i & -i) res += BIT[i];
    return res;
}

int getRoot(int id, int u) {
    if (!par[id][u]) return u ;
    return getRoot(id, par[id][u]);
}

void uniteSet(int id, int u, int v, int w) {
    u = getRoot(id, u); v = getRoot(id, v);
    if (u == v) return;
    if (siz[id][u] < siz[id][v]) swap(u, v);
    par[id][v] = u; val[id][v] = w;
    siz[id][u] += siz[id][v];
    adj[id][u].push_back(v);
}

void DFS(int id, int u) {
    ver[id][tin[id][u] = ++timer] = u;
    for (int v : adj[id][u]) DFS(id, v);
    tout[id][u] = timer;
}

vector <int> check_validity(int n, vector <int> x,
vector <int> y, vector <int> s, vector <int> e,
vector <int> ll, vector <int> rr) {
    int m = x.size(), q = s.size();
    vector <pii> edge(m);
    for (int i = 0; i < m; i++)
        edge[i] = {++x[i], ++y[i]};
    for (int i = 1; i <= n; i++)
        siz[0][i] = siz[1][i] = 1;
    sort(edge.begin(), edge.end(),
    [](const pii &x, const pii &y) {
        return max(x.fi, x.se) < max(y.fi, y.se);
    });
    for (auto e : edge)
        uniteSet(0, e.fi, e.se, max(e.fi, e.se));
    for (int i = 1; i <= n; i++)
        if (!par[0][i]) DFS(0, i);
    sort(edge.begin(), edge.end(),
    [](const pii &x, const pii &y) {
        return min(x.fi, x.se) > min(y.fi, y.se);
    });
    for (auto e : edge)
        uniteSet(1, e.fi, e.se, min(e.fi, e.se));
    timer = 0;
    for (int i = 1; i <= n; i++)
        if (!par[1][i]) DFS(1, i);
    for (int i = 0; i < q; i++) {
        int u, v, l, r;
        u = s[i]; v = e[i]; l = ll[i]; r = rr[i];
        u++; v++; l++; r++; swap(u, v);
        if (u > r || v < l) continue;
        while (par[0][u] && val[0][u] <= r)
            u = par[0][u];
        int lo = 0, hi = adj[0][u].size() - 1;
        while (lo < hi) {
            int mi = (lo + hi + 1) / 2;
            if (val[0][adj[0][u][mi]] <= r)
                lo = mi;
            else hi = mi - 1;
        }
        int x1 = tin[0][u], x2;
        if (adj[0][u].empty() ||
        val[0][adj[0][u][lo]] > r)
            x2 = tin[0][u];
        else x2 = tout[0][adj[0][u][lo]];
        while (par[1][v] && val[1][v] >= l)
            v = par[1][v];
        lo = 0, hi = adj[1][v].size() - 1;
        while (lo < hi) {
            int mi = (lo + hi + 1) / 2;
            if (val[1][adj[1][v][mi]] >= l)
                lo = mi;
            else hi = mi - 1;
        }
        int y1 = tin[1][v], y2;
        if (adj[1][v].empty() ||
        val[1][adj[1][v][lo]] < l)
            y2 = tin[1][v];
        else y2 = tout[1][adj[1][v][lo]];
        que[x1 - 1].push_back({y1, y2, -1, i});
        que[x2].push_back({y1, y2, 1, i});
    }
    vector <int> res(q);
    for (int i = 1; i <= n; i++) {
        updateBIT(tin[1][ver[0][i]]);
        for (auto ev : que[i])
            ans[ev.id] += (queryBIT(ev.r)
            - queryBIT(ev.l - 1)) * ev.t;
    }
    for (int i = 0; i < q; i++)
        res[i] = ans[i] > 0;
    return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14572 KB Output is correct
2 Correct 12 ms 14572 KB Output is correct
3 Correct 10 ms 14572 KB Output is correct
4 Correct 10 ms 14572 KB Output is correct
5 Correct 10 ms 14572 KB Output is correct
6 Correct 11 ms 14572 KB Output is correct
7 Correct 10 ms 14572 KB Output is correct
8 Correct 10 ms 14592 KB Output is correct
9 Correct 10 ms 14572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14572 KB Output is correct
2 Correct 12 ms 14572 KB Output is correct
3 Correct 10 ms 14572 KB Output is correct
4 Correct 10 ms 14572 KB Output is correct
5 Correct 10 ms 14572 KB Output is correct
6 Correct 11 ms 14572 KB Output is correct
7 Correct 10 ms 14572 KB Output is correct
8 Correct 10 ms 14592 KB Output is correct
9 Correct 10 ms 14572 KB Output is correct
10 Correct 15 ms 15212 KB Output is correct
11 Correct 15 ms 15212 KB Output is correct
12 Correct 15 ms 15212 KB Output is correct
13 Correct 15 ms 15212 KB Output is correct
14 Correct 15 ms 15212 KB Output is correct
15 Correct 16 ms 15340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 540 ms 59244 KB Output is correct
2 Correct 445 ms 57432 KB Output is correct
3 Correct 444 ms 57428 KB Output is correct
4 Correct 428 ms 57684 KB Output is correct
5 Correct 445 ms 57684 KB Output is correct
6 Correct 520 ms 58204 KB Output is correct
7 Correct 467 ms 57272 KB Output is correct
8 Correct 434 ms 57560 KB Output is correct
9 Correct 380 ms 57664 KB Output is correct
10 Correct 327 ms 57280 KB Output is correct
11 Correct 355 ms 58336 KB Output is correct
12 Correct 362 ms 57812 KB Output is correct
13 Correct 469 ms 55836 KB Output is correct
14 Correct 456 ms 55332 KB Output is correct
15 Correct 459 ms 55388 KB Output is correct
16 Correct 469 ms 55504 KB Output is correct
17 Correct 454 ms 57004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 10 ms 14572 KB Output is correct
2 Correct 12 ms 14572 KB Output is correct
3 Correct 10 ms 14572 KB Output is correct
4 Correct 10 ms 14572 KB Output is correct
5 Correct 10 ms 14572 KB Output is correct
6 Correct 11 ms 14572 KB Output is correct
7 Correct 10 ms 14572 KB Output is correct
8 Correct 10 ms 14592 KB Output is correct
9 Correct 10 ms 14572 KB Output is correct
10 Correct 15 ms 15212 KB Output is correct
11 Correct 15 ms 15212 KB Output is correct
12 Correct 15 ms 15212 KB Output is correct
13 Correct 15 ms 15212 KB Output is correct
14 Correct 15 ms 15212 KB Output is correct
15 Correct 16 ms 15340 KB Output is correct
16 Correct 540 ms 59244 KB Output is correct
17 Correct 445 ms 57432 KB Output is correct
18 Correct 444 ms 57428 KB Output is correct
19 Correct 428 ms 57684 KB Output is correct
20 Correct 445 ms 57684 KB Output is correct
21 Correct 520 ms 58204 KB Output is correct
22 Correct 467 ms 57272 KB Output is correct
23 Correct 434 ms 57560 KB Output is correct
24 Correct 380 ms 57664 KB Output is correct
25 Correct 327 ms 57280 KB Output is correct
26 Correct 355 ms 58336 KB Output is correct
27 Correct 362 ms 57812 KB Output is correct
28 Correct 469 ms 55836 KB Output is correct
29 Correct 456 ms 55332 KB Output is correct
30 Correct 459 ms 55388 KB Output is correct
31 Correct 469 ms 55504 KB Output is correct
32 Correct 454 ms 57004 KB Output is correct
33 Correct 547 ms 58844 KB Output is correct
34 Correct 375 ms 51288 KB Output is correct
35 Correct 552 ms 58844 KB Output is correct
36 Correct 559 ms 59224 KB Output is correct
37 Correct 545 ms 58716 KB Output is correct
38 Correct 565 ms 59100 KB Output is correct
39 Correct 502 ms 57196 KB Output is correct
40 Correct 514 ms 63940 KB Output is correct
41 Correct 425 ms 57564 KB Output is correct
42 Correct 380 ms 58088 KB Output is correct
43 Correct 552 ms 61160 KB Output is correct
44 Correct 483 ms 58460 KB Output is correct
45 Correct 462 ms 57548 KB Output is correct
46 Correct 464 ms 57172 KB Output is correct
47 Correct 476 ms 55760 KB Output is correct
48 Correct 491 ms 55504 KB Output is correct
49 Correct 475 ms 55672 KB Output is correct
50 Correct 486 ms 55504 KB Output is correct
51 Correct 502 ms 63932 KB Output is correct
52 Correct 500 ms 63948 KB Output is correct