Submission #919005

# Submission time Handle Problem Language Result Execution time Memory
919005 2024-01-31T03:30:35 Z Whisper Birthday gift (IZhO18_treearray) C++17
0 / 100
7 ms 27224 KB
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using T = tuple<ll, ll, ll>;

#define int long long
#define Base 41
#define sz(a) (int)a.size()
#define FOR(i, a, b) for ( int i = a ; i <= b ; i++ )
#define FORD(i, a, b) for (int i = b; i >= a; i --)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPD(i, n) for (int i = n - 1; i >= 0; --i)
#define all(x) x.begin() , x.end()
#define pii pair<int , int>
#define fi first
#define se second
#define Lg(x) 31 - __builtin_clz(x)

#define MASK(i) (1LL << (i))
#define BIT(x, i) (((x) >> (i)) & 1)

constexpr ll LINF = (1ll << 60);
constexpr int INF = (1ll << 30);
constexpr int MAX = 2e5 + 5;
constexpr int Mod = 1e9 + 7;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void setupIO(){
    #define name "Whisper"
    //Phu Trong from Nguyen Tat Thanh High School for gifted student
    srand(time(NULL));
    cin.tie(nullptr)->sync_with_stdio(false); cout.tie(nullptr);
    //freopen(name".inp", "r", stdin);
    //freopen(name".out", "w", stdout);
    cout << fixed << setprecision(10);
}

template <class X, class Y>
    bool minimize(X &x, const Y &y){
        X eps = 1e-9;
        if (x > y + eps) {x = y; return 1;}
        return 0;
    }

template <class X, class Y>
    bool maximize(X &x, const Y &y){
        X eps = 1e-9;
        if (x + eps < y) {x = y; return 1;}
        return 0;
    }
int N, M, Q;
int a[MAX];
vector<int> adj[MAX];

int up[MAX][22], dep[MAX];
void dfs(int u, int p){
    for (auto&v : adj[u]) if(v ^ p){
        up[v][0] = u;
        dep[v] = dep[u] + 1;
        for (int i = 1; i <= 20; ++i){
            up[u][i] = up[up[u][i - 1]][i - 1];
        }
        dfs(v, u);
    }
}

int lca(int u, int v){
    if (dep[u] < dep[v]) swap(u, v); int dis = dep[u] - dep[v];
    for (int i = 0; MASK(i) <= dis; ++i){
        if (BIT(dis, i)) u = up[u][i];
    }
    if (u == v) return u;
    int k = Lg(dep[v]);
    for (int i = k; i >= 0; --i) if(up[u][i] != up[v][i]){
        u = up[u][i], v = up[v][i];
    }
    return up[u][0];
}

set<int> posLca[MAX], posVer[MAX];
void Whisper(){
    cin >> N >> M >> Q;
    for (int i = 1; i < N; ++i){
        int u, v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    for (int i = 1; i <= M; ++i) cin >> a[i];
    dfs(1, 0);
    for (int i = 1; i <= M; ++i){
        posVer[a[i]].insert(i);
        if (i > 1){
            int p = lca(a[i], a[i - 1]);
            posLca[p].insert(i);
        }
    }

    for (int i = 1; i <= Q; ++i){
        int cmd; cin >> cmd;
        if(cmd == 2){
            int l, r, p; cin >> l >> r >> p;
            if(posVer[p].size() > 0) {
				auto L = posVer[p].lower_bound(l);
				if(L != posVer[p].end() && *L <= r) {
					cout << *L << ' ' << *L << '\n';
					continue;
				}
			}
			if(posLca[p].size() > 0) {
				auto L = posLca[p].lower_bound(l + 1);
				if(L != posLca[p].end() && *L <= r) {
					cout << (*L) - 1 << ' ' << *L << '\n';
					continue;
				}
			}
			cout << "-1 -1\n";
        }
        else{
            int p, v; cin >> p >> v;
            posVer[a[p]].erase(p);
            if (p > 1) posLca[lca(a[p], a[p - 1])].erase(p);
            if (p < M) posLca[lca(a[p], a[p + 1])].erase(p + 1);
            a[p] = v;
            posVer[a[p]].insert(p);
            if (p > 1) posLca[lca(a[p], a[p - 1])].insert(p);
            if (p < M) posLca[lca(a[p], a[p + 1])].insert(p + 1);
        }
    }
}


signed main(){
    setupIO();
    int Test = 1;
//    cin >> Test;
    for ( int i = 1 ; i <= Test ; i++ ){
        Whisper();
        if (i < Test) cout << '\n';
    }
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 27224 KB n=5
2 Incorrect 7 ms 27224 KB Wrong range.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 27224 KB n=5
2 Incorrect 7 ms 27224 KB Wrong range.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 27224 KB n=5
2 Incorrect 7 ms 27224 KB Wrong range.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 27224 KB n=5
2 Incorrect 7 ms 27224 KB Wrong range.
3 Halted 0 ms 0 KB -