답안 #400911

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
400911 2021-05-08T20:00:18 Z 534351 Inside information (BOI21_servers) C++17
2.5 / 100
178 ms 49588 KB
#include <bits/stdc++.h>

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

const int MAXN = 240013;
const int INF = 1e9 + 7;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N, K, T;
int parent[MAXN], subtree[MAXN], st[MAXN], ft[MAXN], dup[MAXN];
int ancestor[20][MAXN];
bool incr[20][MAXN], decr[20][MAXN];
int mx[20][MAXN], mn[20][MAXN];
vpi edge[MAXN];
pair<int, pii> quer[MAXN];

bool insubt(int u, int v) //is v in the subtree of u?
{
    return (u == N || (st[u] <= st[v] && st[v] <= ft[u]));
}
void dfs(int u, int p)
{
    st[u] = T;
    ft[u] = T;
    T++;
    subtree[u] = 1;
    for (auto e : edge[u])
    {
        int v = e.fi, d = e.se;
        if (v == p) continue;
        parent[v] = u;
        dup[v] = d;
        dfs(v, u);
        subtree[u] += subtree[v];
        ft[u] = ft[v];
    }
}
bool check(int u, int v, int t)
{
    //return if v -> u is stirctl increasing and max is <= t
    // cerr << "Check " << v << " -> " << u << endl;
    int curmx = -1;
    int w = v;
    //v going up, so it has to keep on increasing
    FORD(i, 20, 0)
    {
        if (!insubt(ancestor[i][w], u))
        {
            if (mn[i][w] < curmx || !incr[i][w] || mx[i][w] > t) return false;
            curmx = mx[i][w];
            w = ancestor[i][w];
        }
    }
    if (!insubt(w, u))
    {
        if (mn[0][w] < curmx || mx[0][w] > t) return false;
        curmx = mx[0][w];
    }
    //u going up, so it has to keep on decreasing.
    w = u;
    int curmn = INF;
    FORD(i, 20, 0)
    {
        if (!insubt(ancestor[i][w], v))
        {
            if (mx[i][w] > curmn || !decr[i][w] || mx[i][w] > t) return false;
            curmn = mn[0][w];
            w = ancestor[i][w];
        }
    }
    if (!insubt(w, v))
    {
        if (mx[0][w] > curmn || mx[0][w] > t) return false;
        curmn = mn[0][w];
    }
    if (curmn < curmx)
    {
        return false;
    }
    return true;
}

int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N >> K;
    FOR(i, 0, N + K - 1)
    {
        char qid; cin >> qid;
        if (qid == 'S')
        {
            int u, v;
            cin >> u >> v; u--; v--;
            quer[i] = {0, {u, v}};
            edge[u].PB({v, i});
            edge[v].PB({u, i});
        }
        if (qid == 'Q')
        {
            int u, v;
            cin >> u >> v; u--; v--;
            quer[i] = {1, {u, v}};
            // cout << (get(u) == get(v) ? "yes" : "no") << '\n';
        }
        if (qid == 'C')
        {
            int u;
            cin >> u; u--;
            quer[i] = {2, {u, -1}};
            // cout << siz[get(u)] << '\n';
        }
    }
    parent[0] = N; parent[N] = N;
    dfs(0, N);
    FOR(i, 0, N + 1)
    {
        ancestor[0][i] = parent[i];
        mx[0][i] = dup[i];
        mn[0][i] = dup[i];
        incr[0][i] = true;
        decr[0][i] = true;
    }
    FOR(i, 1, 20)
    {
        FOR(j, 0, N + 1)
        {
            int k = ancestor[i - 1][j];
            ancestor[i][j] = ancestor[i - 1][k];
            mx[i][j] = max(mx[i - 1][j], mx[i - 1][k]);
            mn[i][j] = min(mn[i - 1][j], mn[i - 1][k]);
            incr[i][j] = (incr[i - 1][j] && incr[i - 1][k] && mx[i - 1][j] < mn[i - 1][k]);
            decr[i][j] = (decr[i - 1][j] && decr[i - 1][k] && mn[i - 1][j] > mx[i - 1][k]);
        }
    }
    FOR(i, 0, N + K - 1)
    {
        if (quer[i].fi == 1)
        {
            int u = quer[i].se.fi, v = quer[i].se.se;
            cout << ((u == v || check(u, v, i)) ? "yes" : "no") << '\n';
            //check if v -> u is strictly increasing.
        }
        if (quer[i].fi == 2)
        {
            cout << "69\n";
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 8280 KB Output is correct
2 Incorrect 48 ms 9604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 8280 KB Output is correct
2 Incorrect 48 ms 9604 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 8344 KB Output is correct
2 Correct 178 ms 49580 KB Output is correct
3 Correct 176 ms 49588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 46 ms 8344 KB Output is correct
2 Correct 178 ms 49580 KB Output is correct
3 Correct 176 ms 49588 KB Output is correct
4 Incorrect 42 ms 8264 KB Extra information in the output file
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 8168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 8168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 41 ms 8252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 41 ms 8252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 8176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 43 ms 8176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 8256 KB Output is correct
2 Incorrect 54 ms 9572 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 42 ms 8256 KB Output is correct
2 Incorrect 54 ms 9572 KB Output isn't correct
3 Halted 0 ms 0 KB -