답안 #1110384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110384 2024-11-09T11:13:05 Z flyingkite Klasika (COCI20_klasika) C++17
33 / 110
851 ms 413352 KB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pll pair<long long, long long>
#define pb push_back
#define F first
#define S second  
#define all(x) (x).begin(), (x).end()
 
const ll N = 1e6 + 100;
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll block = 450;
ll n = 1, q, timer = 0;
vector<pll>adj[N];
struct query{ll typ,x,y;} t[N];
ll tin[N], tout[N], dep[N];
void dfs(ll u, ll par){
    tin[u] = ++timer;
    for(auto v : adj[u]){
        if(v.F == par) continue;
        dep[v.F] = dep[u] ^ v.S;
        dfs(v.F, u);
    }
    tout[u] = timer;
}
struct Trie{
    struct ccjv{
        ll c[2]; set<ll>s;
    } t[N];
    ll cur = 1e6;
    void init(){
        for(int i = 0; i <= cur;i++) t[i].c[0] = t[i].c[1] = -1, t[i].s.clear();
        cur = 0;
    }
    void add(ll x, ll val){
        ll pos = 0;
        for(int i = 30; i >= 0;i--){
            ll f = (x >> i) & 1;
            if(t[pos].c[f] == -1) t[pos].c[f] = ++cur;
            pos = t[pos].c[f];
            t[pos].s.insert(val);
        }
    }
    bool ok(ll pos, ll l, ll r){
        auto it = t[pos].s.lower_bound(l);
        if(it == t[pos].s.end() || (*it > r)) return 0;
        return 1;
    }
    ll query(ll x, ll l, ll r){
        ll pos = 0, res = 0;
        for(int i = 30; i >= 0;i--){
            ll f = (x >> i) & 1;
            if(t[pos].c[f ^ 1] != -1 && ok(t[pos].c[f ^ 1], l, r)){
                res |= (1 << i);
                pos = t[pos].c[f ^ 1];
            }
            else if(t[pos].c[f] != -1 && ok(t[pos].c[f], l, r)) pos = t[pos].c[f];
        }
        return res;
    }
} chinsu;
void to_thic_cau(){
    cin >> q;
    for(int i = 1; i <= q;i++){
        string s; ll x,y; cin >> s >> x >> y;
        if(s == "Add") adj[x].pb({++n, y}), t[i] = {1, n, x};      
        else t[i] = {2, x, y};
    }
    dfs(1, 0);
    chinsu.init();
    chinsu.add(0, 1);
    for(int i = 1; i <= q;i++){
        if(t[i].typ == 1) {
            chinsu.add(dep[t[i].x], tin[t[i].x]);
        }
        else{
            cout << chinsu.query(dep[t[i].x], tin[t[i].y], tout[t[i].y]) << '\n';
        }
    }
}    
 
signed main()   
{  
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll tc = 1;
    //cin >> tc;
    while(tc--) to_thic_cau();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 94544 KB Output is correct
2 Correct 19 ms 94504 KB Output is correct
3 Correct 19 ms 94544 KB Output is correct
4 Correct 20 ms 94756 KB Output is correct
5 Correct 21 ms 94544 KB Output is correct
6 Correct 19 ms 94544 KB Output is correct
7 Correct 19 ms 94712 KB Output is correct
8 Correct 20 ms 94544 KB Output is correct
9 Correct 20 ms 94712 KB Output is correct
10 Correct 21 ms 94544 KB Output is correct
11 Correct 20 ms 94744 KB Output is correct
12 Correct 20 ms 94544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 94544 KB Output is correct
2 Correct 19 ms 94504 KB Output is correct
3 Correct 19 ms 94544 KB Output is correct
4 Correct 20 ms 94756 KB Output is correct
5 Correct 21 ms 94544 KB Output is correct
6 Correct 19 ms 94544 KB Output is correct
7 Correct 19 ms 94712 KB Output is correct
8 Correct 20 ms 94544 KB Output is correct
9 Correct 20 ms 94712 KB Output is correct
10 Correct 21 ms 94544 KB Output is correct
11 Correct 20 ms 94744 KB Output is correct
12 Correct 20 ms 94544 KB Output is correct
13 Correct 23 ms 95056 KB Output is correct
14 Correct 22 ms 95824 KB Output is correct
15 Correct 28 ms 96348 KB Output is correct
16 Correct 26 ms 96848 KB Output is correct
17 Correct 23 ms 95056 KB Output is correct
18 Correct 24 ms 95568 KB Output is correct
19 Correct 24 ms 96336 KB Output is correct
20 Correct 28 ms 96840 KB Output is correct
21 Correct 21 ms 95224 KB Output is correct
22 Correct 27 ms 95568 KB Output is correct
23 Correct 22 ms 96336 KB Output is correct
24 Correct 25 ms 96852 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 465 ms 163400 KB Output is correct
2 Runtime error 851 ms 413352 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 94544 KB Output is correct
2 Correct 19 ms 94504 KB Output is correct
3 Correct 19 ms 94544 KB Output is correct
4 Correct 20 ms 94756 KB Output is correct
5 Correct 21 ms 94544 KB Output is correct
6 Correct 19 ms 94544 KB Output is correct
7 Correct 19 ms 94712 KB Output is correct
8 Correct 20 ms 94544 KB Output is correct
9 Correct 20 ms 94712 KB Output is correct
10 Correct 21 ms 94544 KB Output is correct
11 Correct 20 ms 94744 KB Output is correct
12 Correct 20 ms 94544 KB Output is correct
13 Correct 23 ms 95056 KB Output is correct
14 Correct 22 ms 95824 KB Output is correct
15 Correct 28 ms 96348 KB Output is correct
16 Correct 26 ms 96848 KB Output is correct
17 Correct 23 ms 95056 KB Output is correct
18 Correct 24 ms 95568 KB Output is correct
19 Correct 24 ms 96336 KB Output is correct
20 Correct 28 ms 96840 KB Output is correct
21 Correct 21 ms 95224 KB Output is correct
22 Correct 27 ms 95568 KB Output is correct
23 Correct 22 ms 96336 KB Output is correct
24 Correct 25 ms 96852 KB Output is correct
25 Correct 465 ms 163400 KB Output is correct
26 Runtime error 851 ms 413352 KB Execution killed with signal 11
27 Halted 0 ms 0 KB -