답안 #528803

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
528803 2022-02-21T13:30:33 Z radal Inside information (BOI21_servers) C++14
100 / 100
437 ms 45300 KB
#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("unroll-loops")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 3e5+20,mod = 998244353,inf = 1e9+10;
inline int mkay(int a,int b){
    if (a+b >= mod) return a+b-mod;
    if (a+b < 0) return a+b+mod;
    return a+b;
}

inline int poww(int a,int k){
    if (k < 0) return 0;
    int z = 1;
    while (k){
        if (k&1) z = 1ll*z*a%mod;
        a = 1ll*a*a%mod;
        k >>= 1;
    }
    return z;
}
vector<pll> adj[N],Q1[N];
vector<int> Q2[N];
int sz[N],n,k,fen[N],ans[N],ch[N],W[N],lst[N];
bool hide[N],fl[N][2];
char c[N];
int siz(int v,int p){
    sz[v] = 1;
    for (pll u : adj[v]){
        if (hide[u.X] || u.X == p) continue;
        sz[v] += siz(u.X,v);
    }
    return sz[v];
}
inline void upd(int l,int x){
    for(; l < k; l |= (l+1))
        fen[l] += x;
}
inline int que(int r){
    int res = 0;
    for(; r >= 0; r = (r&(r+1))-1)
        res += fen[r];
    return res;
}
inline int cent(int v,int _n){
    int p = -1;
    while (true){
        bool f = 0;
        for (pll u : adj[v]){
            if (u.X == p || hide[u.X]) continue;
            if (sz[u.X]*2 > _n){
                p = v;
                v = u.X;
                f = 1;
                break;
            }
        }
        if (!f) break;
    }
    return v;
}
void dfs(int v,int w,int par){
    if (par == -1) fl[v][0] = fl[v][1] = 1;
    W[v] = w;
    for (pll p : adj[v]){
        int u = p.X;
        if (u == par || hide[u]) continue;
        if (par == -1){
            fl[u][0] = 1;
            fl[u][1] = 1;
            lst[u] = p.Y;
        }
        else{
            if (fl[v][0] && p.Y < w) fl[u][0] = 1;
            else fl[u][0] = 0;
            if (fl[v][1] && p.Y > w) fl[u][1] = 1;
            else fl[u][1] = 0;
            lst[u] = lst[v];
        }
        dfs(u,p.Y,v);
    }
}
void add(int v,int x,int p){
    if (!fl[v][1]) return;
    upd(W[v],x);
    ch[v] += x;
    for (pll u : adj[v]){
        if (u.X != p && !hide[u.X]){
            add(u.X,x,v);
        }
    }
}
void calc(int v,int p){
    if (!fl[v][0]) return;
    for(int t : Q2[v]){
        ans[t] += que(t)+(lst[v] < t);
    }
    for (pll u : Q1[v]){
        if (u.X == v || (ch[u.X] && max(W[u.X],lst[v]) <= u.Y)) ans[u.Y] = 1;
    }
    for (pll u : adj[v]){
        if (hide[u.X] || u.X == p) continue;
        calc(u.X,v);
    }
}
void decom(int v){
    v = cent(v,siz(v,-1));
    hide[v] = 1;
    ch[v] = 1;
    dfs(v,0,-1);
    for (pll u : adj[v]){
        if (hide[u.X]) continue;
        calc(u.X,v);
        add(u.X,1,v);
    }
    for (int t : Q2[v]){
        ans[t] += que(t)+1;
    }
    ch[v] = 0;
    for (pll u : Q1[v]){
        if (u.X == v || (ch[u.X] && W[u.X] <= u.Y)) ans[u.Y] = 1;
    }
    for (pll u : adj[v]){
        if (!hide[u.X])
            add(u.X,-1,v);
    }
    for (pll u : adj[v]) if (!hide[u.X]) decom(u.X);
}
int main(){
	ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    k += n;
    rep(i,1,k){
        int v;
        cin >> c[i] >> v;
        if (c[i] == 'S'){
            int u;
            cin >> u;
            adj[u].pb({v,i});
            adj[v].pb({u,i});
        }
        if (c[i] == 'Q'){
            int u;
            cin >> u;
            Q1[u].pb({v,i});
        }
        if (c[i] == 'C'){
            Q2[v].pb(i);
        }
    }
    rep(i,1,n+1) reverse(adj[i].begin(),adj[i].end());
    decom(1);
    rep(i,1,k){
        if (c[i] == 'S') continue;
        if (c[i] == 'Q')
            cout << ((ans[i]) ? "yes" : "no" ) << endl;
        else
            cout << ans[i] << endl;
    }
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 25164 KB Output is correct
2 Correct 42 ms 25924 KB Output is correct
3 Correct 41 ms 25948 KB Output is correct
4 Correct 41 ms 25956 KB Output is correct
5 Correct 48 ms 25936 KB Output is correct
6 Correct 41 ms 25924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 25164 KB Output is correct
2 Correct 42 ms 25924 KB Output is correct
3 Correct 41 ms 25948 KB Output is correct
4 Correct 41 ms 25956 KB Output is correct
5 Correct 48 ms 25936 KB Output is correct
6 Correct 41 ms 25924 KB Output is correct
7 Correct 35 ms 25240 KB Output is correct
8 Correct 44 ms 25432 KB Output is correct
9 Correct 40 ms 25348 KB Output is correct
10 Correct 47 ms 25632 KB Output is correct
11 Correct 45 ms 25312 KB Output is correct
12 Correct 40 ms 25128 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 25216 KB Output is correct
2 Correct 141 ms 36012 KB Output is correct
3 Correct 159 ms 36016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 25216 KB Output is correct
2 Correct 141 ms 36012 KB Output is correct
3 Correct 159 ms 36016 KB Output is correct
4 Correct 32 ms 25180 KB Output is correct
5 Correct 139 ms 35636 KB Output is correct
6 Correct 92 ms 33328 KB Output is correct
7 Correct 104 ms 33484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 25164 KB Output is correct
2 Correct 255 ms 45124 KB Output is correct
3 Correct 277 ms 45268 KB Output is correct
4 Correct 226 ms 44764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 25164 KB Output is correct
2 Correct 255 ms 45124 KB Output is correct
3 Correct 277 ms 45268 KB Output is correct
4 Correct 226 ms 44764 KB Output is correct
5 Correct 41 ms 25160 KB Output is correct
6 Correct 273 ms 45128 KB Output is correct
7 Correct 246 ms 45168 KB Output is correct
8 Correct 269 ms 44336 KB Output is correct
9 Correct 266 ms 44228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 25132 KB Output is correct
2 Correct 192 ms 36420 KB Output is correct
3 Correct 206 ms 36436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 25132 KB Output is correct
2 Correct 192 ms 36420 KB Output is correct
3 Correct 206 ms 36436 KB Output is correct
4 Correct 32 ms 25196 KB Output is correct
5 Correct 210 ms 36628 KB Output is correct
6 Correct 216 ms 36348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 25156 KB Output is correct
2 Correct 267 ms 45104 KB Output is correct
3 Correct 272 ms 45176 KB Output is correct
4 Correct 223 ms 44852 KB Output is correct
5 Correct 32 ms 25120 KB Output is correct
6 Correct 197 ms 36484 KB Output is correct
7 Correct 204 ms 36420 KB Output is correct
8 Correct 222 ms 36944 KB Output is correct
9 Correct 223 ms 37264 KB Output is correct
10 Correct 335 ms 40968 KB Output is correct
11 Correct 307 ms 39492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 31 ms 25156 KB Output is correct
2 Correct 267 ms 45104 KB Output is correct
3 Correct 272 ms 45176 KB Output is correct
4 Correct 223 ms 44852 KB Output is correct
5 Correct 32 ms 25120 KB Output is correct
6 Correct 197 ms 36484 KB Output is correct
7 Correct 204 ms 36420 KB Output is correct
8 Correct 222 ms 36944 KB Output is correct
9 Correct 223 ms 37264 KB Output is correct
10 Correct 335 ms 40968 KB Output is correct
11 Correct 307 ms 39492 KB Output is correct
12 Correct 31 ms 25148 KB Output is correct
13 Correct 304 ms 45300 KB Output is correct
14 Correct 241 ms 45124 KB Output is correct
15 Correct 276 ms 44592 KB Output is correct
16 Correct 274 ms 44256 KB Output is correct
17 Correct 33 ms 25176 KB Output is correct
18 Correct 229 ms 36580 KB Output is correct
19 Correct 211 ms 36396 KB Output is correct
20 Correct 235 ms 37084 KB Output is correct
21 Correct 247 ms 37448 KB Output is correct
22 Correct 382 ms 39520 KB Output is correct
23 Correct 424 ms 40456 KB Output is correct
24 Correct 402 ms 39904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 25180 KB Output is correct
2 Correct 41 ms 25944 KB Output is correct
3 Correct 39 ms 25940 KB Output is correct
4 Correct 43 ms 25980 KB Output is correct
5 Correct 45 ms 25944 KB Output is correct
6 Correct 43 ms 25816 KB Output is correct
7 Correct 31 ms 25260 KB Output is correct
8 Correct 145 ms 36020 KB Output is correct
9 Correct 139 ms 36024 KB Output is correct
10 Correct 31 ms 25136 KB Output is correct
11 Correct 268 ms 45096 KB Output is correct
12 Correct 263 ms 45108 KB Output is correct
13 Correct 233 ms 44948 KB Output is correct
14 Correct 32 ms 25160 KB Output is correct
15 Correct 195 ms 36332 KB Output is correct
16 Correct 213 ms 36424 KB Output is correct
17 Correct 209 ms 36704 KB Output is correct
18 Correct 230 ms 37292 KB Output is correct
19 Correct 327 ms 40968 KB Output is correct
20 Correct 303 ms 39496 KB Output is correct
21 Correct 178 ms 36444 KB Output is correct
22 Correct 163 ms 36480 KB Output is correct
23 Correct 193 ms 36916 KB Output is correct
24 Correct 198 ms 37052 KB Output is correct
25 Correct 310 ms 40896 KB Output is correct
26 Correct 239 ms 35352 KB Output is correct
27 Correct 225 ms 35284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 25180 KB Output is correct
2 Correct 41 ms 25944 KB Output is correct
3 Correct 39 ms 25940 KB Output is correct
4 Correct 43 ms 25980 KB Output is correct
5 Correct 45 ms 25944 KB Output is correct
6 Correct 43 ms 25816 KB Output is correct
7 Correct 31 ms 25260 KB Output is correct
8 Correct 145 ms 36020 KB Output is correct
9 Correct 139 ms 36024 KB Output is correct
10 Correct 31 ms 25136 KB Output is correct
11 Correct 268 ms 45096 KB Output is correct
12 Correct 263 ms 45108 KB Output is correct
13 Correct 233 ms 44948 KB Output is correct
14 Correct 32 ms 25160 KB Output is correct
15 Correct 195 ms 36332 KB Output is correct
16 Correct 213 ms 36424 KB Output is correct
17 Correct 209 ms 36704 KB Output is correct
18 Correct 230 ms 37292 KB Output is correct
19 Correct 327 ms 40968 KB Output is correct
20 Correct 303 ms 39496 KB Output is correct
21 Correct 178 ms 36444 KB Output is correct
22 Correct 163 ms 36480 KB Output is correct
23 Correct 193 ms 36916 KB Output is correct
24 Correct 198 ms 37052 KB Output is correct
25 Correct 310 ms 40896 KB Output is correct
26 Correct 239 ms 35352 KB Output is correct
27 Correct 225 ms 35284 KB Output is correct
28 Correct 34 ms 25120 KB Output is correct
29 Correct 46 ms 25428 KB Output is correct
30 Correct 42 ms 25368 KB Output is correct
31 Correct 45 ms 25548 KB Output is correct
32 Correct 49 ms 25372 KB Output is correct
33 Correct 42 ms 25148 KB Output is correct
34 Correct 32 ms 25180 KB Output is correct
35 Correct 142 ms 35668 KB Output is correct
36 Correct 107 ms 33492 KB Output is correct
37 Correct 107 ms 33504 KB Output is correct
38 Correct 32 ms 25220 KB Output is correct
39 Correct 276 ms 45136 KB Output is correct
40 Correct 253 ms 45188 KB Output is correct
41 Correct 265 ms 44244 KB Output is correct
42 Correct 274 ms 44328 KB Output is correct
43 Correct 33 ms 25156 KB Output is correct
44 Correct 228 ms 36524 KB Output is correct
45 Correct 216 ms 36288 KB Output is correct
46 Correct 228 ms 37076 KB Output is correct
47 Correct 254 ms 37540 KB Output is correct
48 Correct 382 ms 39364 KB Output is correct
49 Correct 437 ms 40392 KB Output is correct
50 Correct 397 ms 39916 KB Output is correct
51 Correct 123 ms 34724 KB Output is correct
52 Correct 102 ms 34364 KB Output is correct
53 Correct 104 ms 33904 KB Output is correct
54 Correct 102 ms 34492 KB Output is correct
55 Correct 110 ms 34220 KB Output is correct
56 Correct 177 ms 35880 KB Output is correct
57 Correct 248 ms 38416 KB Output is correct
58 Correct 308 ms 35696 KB Output is correct
59 Correct 230 ms 35416 KB Output is correct