답안 #865761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
865761 2023-10-24T15:21:00 Z vjudge1 Birthday gift (IZhO18_treearray) C++
0 / 100
32 ms 66136 KB
// Bolatulu
#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define int long long
#define kanagattandirilmagandiktarinizdan ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define F first
#define S second
#define md (tl+tr)/2
#define TL v+v,tl,md
#define TR v+v+1,md+1,tr

#pragma GCC target( "sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast,unroll-loops,fast-math,O3")

using namespace std;

int binpow(int a,int n,int M) {
    if (n==0)
        return 1;
    if (n%2!=0)
        return (a * binpow(a,n-1,M))%M;
    int z=binpow(a,n/2,M);
    return (z*z)%M;
}

const ll INF = 1e18;
const int N =  1e6+7;
const int M = 1e9+7;
const ll HZ = 1e5;
const int MAX = INT_MAX;
const int MIN = INT_MIN;
const db pi = 3.141592653;
const int P=31;

int n,m,q,tin[N],tout[N],t,up[20][N],a[N];
vector <int> g[N];

void dfs(int v,int p) {
    tin[v]=++t;
    up[0][v]=p;
    for (auto now : g[v]) {
        if (now==p)
            continue;
        dfs(now,v);
    }
    tout[v]=++t;
}

bool parent(int a,int b) {
    return tin[a]<=tin[b] and tout[b]<=tout[a];
}

void prepare(int pw) {
    if (pw==20)
        return;
    for (int i=1;i<=n;i++)
        up[pw][i]=up[up[pw-1][i]][i];
    prepare(pw+1);
}

int lca(int a,int b) {
    if (parent(a,b))
        return a;
    if (parent(b,a))
        return b;
    for (int i=19;i>=0;i--)
        if (up[i][a] and !parent(up[i][a],b))
            a=up[i][a];
    return up[0][a];
}

void solve() {
    cin >> n >> m >> q;
    for (int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        g[u].push_back(v), g[v].push_back(u);
    }
    dfs(1, 0), prepare(1);
    vector<set<int>> d(n + 1),s(n+1);
    for (int i = 1; i <= m; i++) {
        cin >> a[i];
        if (i > 1)
            d[lca(a[i - 1], a[i])].insert(i-1);
        s[a[i]].insert(i);
    }
    while (q--) {
        int tp, l, r, v;
        cin >> tp;
        if (tp == 1) {
            cin >> l >> v;
            if (l > 1)
                d[lca(a[l - 1], a[l])].erase(l - 1), d[lca(a[l - 1], v)].insert(l - 1);
            if (l < m)
                d[lca(a[l], a[l + 1])].erase(l), d[lca(v, a[l + 1])].insert(l);
            s[a[l]].erase(l), s[v].insert(l);
            a[l] = v;
        } else {
            cin >> l >> r >> v;
            if (s[v].lower_bound(l)!=s[v].end() and *s[v].lower_bound(l) <= r)
                cout << *s[v].lower_bound(l) << ' ' << *s[v].lower_bound(l) << '\n';
            else if (d[v].lower_bound(l)!=d[v].end() and *d[v].lower_bound(l) <= r - 1)
                cout << *d[v].lower_bound(l) << ' ' << *d[v].lower_bound(l) + 1 << '\n';
            else
                cout << -1 << ' ' << -1 << '\n';
        }
    }
}

signed main() {
    // freopen("lca.in", "r", stdin);
    // freopen("lca.out", "w", stdout);
    kanagattandirilmagandiktarinizdan
    int test = 1, count = 1;
    // cin >> test;
    while (test--) {
        // cout << "Case " << count << ":\n";
        solve();
        if (test)
            // cout << '\n';
            count++;
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 66136 KB n=5
2 Runtime error 32 ms 63404 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 66136 KB n=5
2 Runtime error 32 ms 63404 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 66136 KB n=5
2 Runtime error 32 ms 63404 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 66136 KB n=5
2 Runtime error 32 ms 63404 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -