Submission #963977

# Submission time Handle Problem Language Result Execution time Memory
963977 2024-04-16T06:36:06 Z Pring Inside information (BOI21_servers) C++17
50 / 100
181 ms 45344 KB
#include <bits/stdc++.h>
#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx2","popcnt","sse4","abm")
using namespace std;

#ifdef MIKU
string dbmc = "\033[1;38;2;57;197;187m", dbrs = "\033[0m";
#define debug(x...) cout << dbmc << "[" << #x << "]: ", dout(x)
void dout() { cout << dbrs << endl; }
template <typename T, typename ...U>
void dout(T t, U ...u) { cout << t << (sizeof...(u) ? ", " : ""); dout(u...); }
#else
#define debug(...) 39
#endif

#define fs first
#define sc second
#define mp make_pair
#define FOR(i, j, k) for (int i = j, Z = k; i < Z; i++)
using ll = long long;
typedef pair<int, int> pii;
typedef array<int, 4> p4i;

const int MXN = 120005, LG = 17;
int n, q;
vector<pii> edge[MXN];
vector<pii> qc[MXN];
vector<p4i> qq;
int ans[MXN * 2];

int d[MXN];
int p[LG][MXN], big[LG][MXN], lst[LG][MXN];
bitset<MXN> isP[LG], isN[LG];

void DFS(int id, int par, int dep) {
    p[0][id] = par;
    d[id] = dep;
    for (auto &[e, i] : edge[id]) {
        if (i == par) continue;
        big[0][i] = e;
        lst[0][i] = e;
        DFS(i, id, dep + 1);
    }
}

void MAKE_TREE() {
    DFS(1, 1, 0);
    isP[0].set();
    isN[0].set();
    FOR(w, 1, LG) {
        FOR(i, 1, n + 1) {
            int pp = p[w - 1][i];
            p[w][i] = p[w - 1][pp];
            big[w][i] = max(big[w - 1][i], big[w - 1][pp]);
            lst[w][i] = lst[w - 1][pp];
            isP[w][i] = (isP[w - 1][i]) & (isP[w - 1][pp]) & (lst[w - 1][i] < lst[0][pp]);
            isN[w][i] = (isN[w - 1][i]) & (isN[w - 1][pp]) & (lst[w - 1][i] > lst[0][pp]);
        }
    }
}

namespace NSBL {
    int JUMP(int x, int k) {
        FOR(w, 0, LG) if (k & (1 << w)) x = p[w][x];
        return x;
    }

    int LCA(int x, int y) {
        if (d[x] < d[y]) swap(x, y);
        x = JUMP(x, d[x] - d[y]);
        if (x == y) return x;
        for (int w = LG - 1; w >= 0; w--) {
            if (p[w][x] == p[w][y]) continue;
            x = p[w][x];
            y = p[w][y];
        }
        return p[0][x];
    }

    int GET_BIG(int x, int k) {
        int ans = INT_MIN;
        FOR(w, 0, LG) if (k & (1 << w)) {
            ans = max(ans, big[w][x]);
            x = p[w][x];
        }
        return ans;
    }

    bool PS(int x, int k) {
        int L = lst[0][x];
        x = p[0][x];
        k--;
        FOR(w, 0, LG) if (k & (1 << w)) {
            if (L > lst[0][x] || !isP[w][x]) return false;
            L = lst[w][x];
            x = p[w][x];
        }
        return true;
    }

    bool NG(int x, int k) {
        int L = lst[0][x];
        x = p[0][x];
        k--;
        FOR(w, 0, LG) if (k & (1 << w)) {
            if (L < lst[0][x] || !isN[w][x]) return false;
            L = lst[w][x];
            x = p[w][x];
        }
        return true;
    }

    bool calc(int u, int v, int t) {
        if (u == v) return true;
        int lca = LCA(u, v);
        int b = max(GET_BIG(u, d[u] - d[lca]), GET_BIG(v, d[v] - d[lca]));
        // debug(u, v, lca, b);
        if (b > t) return false;
        if (lca == u) {
            debug(1);
            return NG(v, d[v] - d[u]);
        } else if (lca == v) {
            debug(2);
            return PS(u, d[u] - d[v]);
        } else {
            int su = JUMP(u, d[u] - d[lca] - 1), sv = JUMP(v, d[v] - d[lca] - 1);
            return NG(v, d[v] - d[lca]) && PS(u, d[u] - d[lca]) && (lst[0][su] < lst[0][sv]);
        }
        return false;
    }

    void DO() {
        for (auto [u, v, t, aid] : qq) {
            ans[aid] = (calc(v, u, t) ? -2 : -3);
        }
    }
}

namespace NSCD {

    void DO() {
    }
}

void miku() {
    cin >> n >> q;
    int ec = 0;
    FOR(i, 0, q + n - 1) {
        char c;
        int a, b;
        cin >> c;
        if (c == 'S') {
            cin >> a >> b;
            ec++;
            edge[a].push_back(mp(ec, b));
            edge[b].push_back(mp(ec, a));
            ans[i] = -1;
        } else if (c == 'Q') {
            cin >> a >> b;
            qq.push_back({a, b, ec, i});
        } else {
            cin >> a;
            qc[a].push_back(mp(ec, i));
        }
    }
    MAKE_TREE();
    NSBL::DO();
    NSCD::DO();
    FOR(i, 0, q + n - 1) {
        if (ans[i] == -1) continue;
        else if (ans[i] < 0) cout << (ans[i] == -2 ? "yes" : "no") << '\n';
        else cout << ans[i] << '\n';
    }
}

int32_t main() {
    cin.tie(0) -> sync_with_stdio(false);
    cin.exceptions(cin.failbit);
    miku();
    return 0;
}

Compilation message

servers.cpp: In function 'bool NSBL::calc(int, int, int)':
servers.cpp:13:20: warning: statement has no effect [-Wunused-value]
   13 | #define debug(...) 39
      |                    ^~
servers.cpp:120:13: note: in expansion of macro 'debug'
  120 |             debug(1);
      |             ^~~~~
servers.cpp:13:20: warning: statement has no effect [-Wunused-value]
   13 | #define debug(...) 39
      |                    ^~
servers.cpp:123:13: note: in expansion of macro 'debug'
  123 |             debug(2);
      |             ^~~~~
# Verdict Execution time Memory Grader output
1 Correct 28 ms 10756 KB Output is correct
2 Correct 50 ms 11660 KB Output is correct
3 Correct 35 ms 11604 KB Output is correct
4 Correct 46 ms 11476 KB Output is correct
5 Correct 48 ms 11728 KB Output is correct
6 Correct 37 ms 11492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 28 ms 10756 KB Output is correct
2 Correct 50 ms 11660 KB Output is correct
3 Correct 35 ms 11604 KB Output is correct
4 Correct 46 ms 11476 KB Output is correct
5 Correct 48 ms 11728 KB Output is correct
6 Correct 37 ms 11492 KB Output is correct
7 Incorrect 36 ms 9312 KB Extra information in the output file
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 30 ms 10132 KB Output is correct
2 Correct 100 ms 41632 KB Output is correct
3 Correct 114 ms 41632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 10132 KB Output is correct
2 Correct 100 ms 41632 KB Output is correct
3 Correct 114 ms 41632 KB Output is correct
4 Incorrect 29 ms 9340 KB Extra information in the output file
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 10060 KB Output is correct
2 Correct 96 ms 44664 KB Output is correct
3 Correct 89 ms 44476 KB Output is correct
4 Correct 136 ms 44428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 10060 KB Output is correct
2 Correct 96 ms 44664 KB Output is correct
3 Correct 89 ms 44476 KB Output is correct
4 Correct 136 ms 44428 KB Output is correct
5 Incorrect 29 ms 9200 KB Extra information in the output file
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 35 ms 10216 KB Output is correct
2 Correct 104 ms 42156 KB Output is correct
3 Correct 97 ms 42568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 10216 KB Output is correct
2 Correct 104 ms 42156 KB Output is correct
3 Correct 97 ms 42568 KB Output is correct
4 Incorrect 30 ms 9184 KB Extra information in the output file
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 25 ms 10196 KB Output is correct
2 Correct 90 ms 44488 KB Output is correct
3 Correct 99 ms 44572 KB Output is correct
4 Correct 125 ms 44480 KB Output is correct
5 Correct 28 ms 10188 KB Output is correct
6 Correct 102 ms 42068 KB Output is correct
7 Correct 120 ms 42648 KB Output is correct
8 Correct 151 ms 42868 KB Output is correct
9 Correct 106 ms 42896 KB Output is correct
10 Correct 135 ms 45228 KB Output is correct
11 Correct 181 ms 44864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 10196 KB Output is correct
2 Correct 90 ms 44488 KB Output is correct
3 Correct 99 ms 44572 KB Output is correct
4 Correct 125 ms 44480 KB Output is correct
5 Correct 28 ms 10188 KB Output is correct
6 Correct 102 ms 42068 KB Output is correct
7 Correct 120 ms 42648 KB Output is correct
8 Correct 151 ms 42868 KB Output is correct
9 Correct 106 ms 42896 KB Output is correct
10 Correct 135 ms 45228 KB Output is correct
11 Correct 181 ms 44864 KB Output is correct
12 Incorrect 27 ms 9428 KB Extra information in the output file
13 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 27 ms 10192 KB Output is correct
2 Correct 36 ms 11532 KB Output is correct
3 Correct 36 ms 11720 KB Output is correct
4 Correct 48 ms 11588 KB Output is correct
5 Correct 41 ms 11708 KB Output is correct
6 Correct 44 ms 11500 KB Output is correct
7 Correct 30 ms 10192 KB Output is correct
8 Correct 116 ms 41632 KB Output is correct
9 Correct 90 ms 41612 KB Output is correct
10 Correct 24 ms 10192 KB Output is correct
11 Correct 97 ms 44516 KB Output is correct
12 Correct 85 ms 44492 KB Output is correct
13 Correct 120 ms 44440 KB Output is correct
14 Correct 31 ms 10152 KB Output is correct
15 Correct 149 ms 42096 KB Output is correct
16 Correct 107 ms 42484 KB Output is correct
17 Correct 148 ms 42980 KB Output is correct
18 Correct 121 ms 42900 KB Output is correct
19 Correct 132 ms 45344 KB Output is correct
20 Correct 152 ms 44856 KB Output is correct
21 Correct 118 ms 42164 KB Output is correct
22 Correct 96 ms 42288 KB Output is correct
23 Correct 101 ms 42432 KB Output is correct
24 Correct 128 ms 42684 KB Output is correct
25 Correct 128 ms 42728 KB Output is correct
26 Correct 89 ms 41948 KB Output is correct
27 Correct 90 ms 42100 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 10192 KB Output is correct
2 Correct 36 ms 11532 KB Output is correct
3 Correct 36 ms 11720 KB Output is correct
4 Correct 48 ms 11588 KB Output is correct
5 Correct 41 ms 11708 KB Output is correct
6 Correct 44 ms 11500 KB Output is correct
7 Correct 30 ms 10192 KB Output is correct
8 Correct 116 ms 41632 KB Output is correct
9 Correct 90 ms 41612 KB Output is correct
10 Correct 24 ms 10192 KB Output is correct
11 Correct 97 ms 44516 KB Output is correct
12 Correct 85 ms 44492 KB Output is correct
13 Correct 120 ms 44440 KB Output is correct
14 Correct 31 ms 10152 KB Output is correct
15 Correct 149 ms 42096 KB Output is correct
16 Correct 107 ms 42484 KB Output is correct
17 Correct 148 ms 42980 KB Output is correct
18 Correct 121 ms 42900 KB Output is correct
19 Correct 132 ms 45344 KB Output is correct
20 Correct 152 ms 44856 KB Output is correct
21 Correct 118 ms 42164 KB Output is correct
22 Correct 96 ms 42288 KB Output is correct
23 Correct 101 ms 42432 KB Output is correct
24 Correct 128 ms 42684 KB Output is correct
25 Correct 128 ms 42728 KB Output is correct
26 Correct 89 ms 41948 KB Output is correct
27 Correct 90 ms 42100 KB Output is correct
28 Incorrect 34 ms 9296 KB Extra information in the output file
29 Halted 0 ms 0 KB -