답안 #399158

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
399158 2021-05-05T11:13:34 Z egekabas Inside information (BOI21_servers) C++14
50 / 100
415 ms 69672 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
int n, k;
    
char t[240009];
int x[240009];
int y[240009];
    
vector<pii> g[120009];
    
int dad[120009][25];
int depth[120009];
    
int pval[120009][25];
int incr[120009][25];
int decr[120009][25];
    
void dfs(int v, int prt){
    dad[v][0] = prt;
    depth[v] = depth[prt]+1;
    
    for(int i = 1; i < 25; ++i){
        dad[v][i] = dad[dad[v][i-1]][i-1];
        pval[v][i] = pval[dad[v][i-1]][i-1];
        if(incr[v][i-1] && incr[dad[v][i-1]][i-1] && pval[v][i-1] < pval[dad[v][i-1]][0])
            incr[v][i] = 1;
        if(decr[v][i-1] && decr[dad[v][i-1]][i-1] && pval[v][i-1] > pval[dad[v][i-1]][0])
            decr[v][i] = 1;
    }
    for(auto u : g[v])
        if(u.ff != prt){
            incr[u.ff][0] = decr[u.ff][0] = 1;
            pval[u.ff][0] = u.ss;
            dfs(u.ff, v);
        }
}
int lca(int x, int y){
    if(depth[y] > depth[x])
        swap(x, y);
    for(int i = 24; i >= 0; --i)
        if(depth[dad[x][i]] >= depth[y])
            x = dad[x][i];
    if(x == y) return x;
    for(int i = 24; i >= 0; --i)
        if(dad[x][i] != dad[y][i]){
            x = dad[x][i];
            y = dad[y][i];
        }
    return dad[x][0];
}
struct retst{
    int incr = 1, decr = 1, maxi = -1, last = -1;
};
retst goup(int x, int y){
    retst ret = retst();
    for(int i = 24; i >= 0; --i)
        if(depth[dad[x][i]] >= depth[y]){
            if((ret.last != -1 && ret.last > pval[x][0]) || incr[x][i] == 0)
                ret.incr = 0;
            if((ret.last != -1 && ret.last < pval[x][0]) || decr[x][i] == 0)
                ret.decr = 0;
            ret.maxi = max({ret.maxi, pval[x][0], pval[x][i]});
            ret.last = pval[x][i];
            x = dad[x][i];
        }
    return ret;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n >> k;
    for(int i = 0; i < n+k-1; ++i){
        cin >> t[i];
        if(t[i] == 'C')
            cin >> x[i];
        else
            cin >> x[i] >> y[i];
        if(t[i] == 'S'){
            g[x[i]].pb({y[i], i});
            g[y[i]].pb({x[i], i});
        }
    }
    dfs(1, 0);
    for(int i = 0; i < n+k-1; ++i){
        if(t[i] == 'S') continue;
        else if(t[i] == 'Q'){
            int lc = lca(x[i], y[i]);
            retst a = goup(x[i], lc);
            retst b = goup(y[i], lc);
            if(a.decr && b.incr && (a.last == -1 || b.last == -1 || a.last > b.last) && max(a.maxi, b.maxi) <= i)
                cout << "yes\n";
            else
                cout << "no\n";
        }
        else{
            cout << "0\n";
            assert(0);
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 4508 KB Output is correct
2 Correct 86 ms 7616 KB Output is correct
3 Correct 75 ms 7804 KB Output is correct
4 Correct 114 ms 7952 KB Output is correct
5 Correct 92 ms 7980 KB Output is correct
6 Correct 76 ms 7764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 4508 KB Output is correct
2 Correct 86 ms 7616 KB Output is correct
3 Correct 75 ms 7804 KB Output is correct
4 Correct 114 ms 7952 KB Output is correct
5 Correct 92 ms 7980 KB Output is correct
6 Correct 76 ms 7764 KB Output is correct
7 Runtime error 28 ms 9248 KB Execution killed with signal 6
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 4520 KB Output is correct
2 Correct 236 ms 57704 KB Output is correct
3 Correct 235 ms 57700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 4520 KB Output is correct
2 Correct 236 ms 57704 KB Output is correct
3 Correct 235 ms 57700 KB Output is correct
4 Runtime error 27 ms 8424 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 4604 KB Output is correct
2 Correct 232 ms 69488 KB Output is correct
3 Correct 233 ms 69572 KB Output is correct
4 Correct 303 ms 69460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 4604 KB Output is correct
2 Correct 232 ms 69488 KB Output is correct
3 Correct 233 ms 69572 KB Output is correct
4 Correct 303 ms 69460 KB Output is correct
5 Runtime error 31 ms 9316 KB Execution killed with signal 6
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 4544 KB Output is correct
2 Correct 226 ms 61092 KB Output is correct
3 Correct 207 ms 61508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 66 ms 4544 KB Output is correct
2 Correct 226 ms 61092 KB Output is correct
3 Correct 207 ms 61508 KB Output is correct
4 Runtime error 28 ms 9296 KB Execution killed with signal 6
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 4548 KB Output is correct
2 Correct 239 ms 69672 KB Output is correct
3 Correct 228 ms 69572 KB Output is correct
4 Correct 288 ms 69476 KB Output is correct
5 Correct 70 ms 5464 KB Output is correct
6 Correct 218 ms 60976 KB Output is correct
7 Correct 205 ms 61512 KB Output is correct
8 Correct 311 ms 61920 KB Output is correct
9 Correct 243 ms 61932 KB Output is correct
10 Correct 314 ms 66600 KB Output is correct
11 Correct 396 ms 65740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 62 ms 4548 KB Output is correct
2 Correct 239 ms 69672 KB Output is correct
3 Correct 228 ms 69572 KB Output is correct
4 Correct 288 ms 69476 KB Output is correct
5 Correct 70 ms 5464 KB Output is correct
6 Correct 218 ms 60976 KB Output is correct
7 Correct 205 ms 61512 KB Output is correct
8 Correct 311 ms 61920 KB Output is correct
9 Correct 243 ms 61932 KB Output is correct
10 Correct 314 ms 66600 KB Output is correct
11 Correct 396 ms 65740 KB Output is correct
12 Runtime error 38 ms 9348 KB Execution killed with signal 6
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 4520 KB Output is correct
2 Correct 86 ms 7688 KB Output is correct
3 Correct 78 ms 7764 KB Output is correct
4 Correct 109 ms 7824 KB Output is correct
5 Correct 94 ms 8016 KB Output is correct
6 Correct 81 ms 7704 KB Output is correct
7 Correct 63 ms 5504 KB Output is correct
8 Correct 234 ms 60560 KB Output is correct
9 Correct 223 ms 60548 KB Output is correct
10 Correct 67 ms 5468 KB Output is correct
11 Correct 245 ms 69516 KB Output is correct
12 Correct 256 ms 69572 KB Output is correct
13 Correct 317 ms 69500 KB Output is correct
14 Correct 71 ms 5448 KB Output is correct
15 Correct 226 ms 61052 KB Output is correct
16 Correct 235 ms 61560 KB Output is correct
17 Correct 326 ms 61868 KB Output is correct
18 Correct 253 ms 61908 KB Output is correct
19 Correct 322 ms 66520 KB Output is correct
20 Correct 415 ms 65708 KB Output is correct
21 Correct 244 ms 61156 KB Output is correct
22 Correct 238 ms 61116 KB Output is correct
23 Correct 246 ms 61508 KB Output is correct
24 Correct 252 ms 61472 KB Output is correct
25 Correct 311 ms 63336 KB Output is correct
26 Correct 227 ms 60936 KB Output is correct
27 Correct 204 ms 61012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 4520 KB Output is correct
2 Correct 86 ms 7688 KB Output is correct
3 Correct 78 ms 7764 KB Output is correct
4 Correct 109 ms 7824 KB Output is correct
5 Correct 94 ms 8016 KB Output is correct
6 Correct 81 ms 7704 KB Output is correct
7 Correct 63 ms 5504 KB Output is correct
8 Correct 234 ms 60560 KB Output is correct
9 Correct 223 ms 60548 KB Output is correct
10 Correct 67 ms 5468 KB Output is correct
11 Correct 245 ms 69516 KB Output is correct
12 Correct 256 ms 69572 KB Output is correct
13 Correct 317 ms 69500 KB Output is correct
14 Correct 71 ms 5448 KB Output is correct
15 Correct 226 ms 61052 KB Output is correct
16 Correct 235 ms 61560 KB Output is correct
17 Correct 326 ms 61868 KB Output is correct
18 Correct 253 ms 61908 KB Output is correct
19 Correct 322 ms 66520 KB Output is correct
20 Correct 415 ms 65708 KB Output is correct
21 Correct 244 ms 61156 KB Output is correct
22 Correct 238 ms 61116 KB Output is correct
23 Correct 246 ms 61508 KB Output is correct
24 Correct 252 ms 61472 KB Output is correct
25 Correct 311 ms 63336 KB Output is correct
26 Correct 227 ms 60936 KB Output is correct
27 Correct 204 ms 61012 KB Output is correct
28 Runtime error 28 ms 9312 KB Execution killed with signal 6
29 Halted 0 ms 0 KB -