Submission #1100567

# Submission time Handle Problem Language Result Execution time Memory
1100567 2024-10-14T09:09:23 Z vjudge1 Birthday gift (IZhO18_treearray) C++17
0 / 100
9 ms 39504 KB
// Bolatulu
#include <bits/stdc++.h>

typedef long long ll;
typedef unsigned long long ull;
typedef double db;
#define kanagattandirilmagandiktarinizdan ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define pf push_front
#define eb emplace_back
#define ins insert
#define F first
#define S second
#define fx cout << fixed << setprecision(4);
#define md (tl+tr)/2
#define TL v+v, tl,md
#define TR v+v+1, md+1,tr
#define Tl t[v].l, tl,md
#define Tr t[v].r, md+1,tr
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define all(x) (x).begin(), (x).end()
#define int ll
#define cnk(n,k) mod(mod(f[(n)]*binpow(f[(n)-(k)],M-2))*binpow(f[(k)],M-2))
#define cnkf(n,k) mod(mod(f[(n)]*inv[(n)-(k)])*inv[(k)])

using namespace std;

typedef complex<double> cd;

struct mine{int l;int r;int i;};
struct edge{int u;int v;int w;};
struct tree{int l;int r;int val;};

auto cmp = [](mine a, mine b) { return a.i<b.i; };

mt19937 RR((uint32_t)chrono::steady_clock::now().time_since_epoch().count());
 
int random(int l, int r){
  return uniform_int_distribution<int>(l, r)(RR);
}

int M=998244353;

int mod1(int a,int b=M) {
    if (a<0)
        a=b+a%b;
    return a % b;
}

int binpow(int a,int n,int m=M) {
    a=mod1(a,m);
    if (!n)
        return 1;
    if (n&1)
        return (a * binpow(a,n-1))%m;
    int x = binpow(a,n>>1);
    return (x*x)%m; 
}

const ll INF=1e18+7;
const int N=3e5+7;

int n,m,q,p[N][20],tin[N],tout[N],tick,a[N];
set <int> s[N],t[N];
vector <int> g[N];

void dfs(int v) {
    tin[v]=++tick;
    for (int i=1;i<20;i++)
        p[v][i]=p[p[v][i-1]][i-1];
    for (auto to : g[v]) {
        if (to!=p[v][0]) {
            p[to][0]=v;
            dfs(to);
        }
    }
    tout[v]=tick;
}

bool isp(int u,int v) {
    return tin[u]<=tin[v] and tout[v]<=tout[u];
}

int lca(int u,int v) {
    if (isp(u,v))
        return u;
    if (isp(v,u))
        return v;
    for (int i=19;i>=0;i--) {
        if (p[v][i] and !isp(p[v][i],u))
            v=p[v][i];
    }
    return p[v][0];
}

void add(int i) {
    if (i>1)
        s[lca(a[i-1],a[i])].insert(i);
    t[a[i]].insert(i);
}

void del(int i) {
    if (i>1)
        s[lca(a[i-1],a[i])].erase(i);
    t[a[i]].erase(i);
}

void solve() {
    cin >> n >> m >> q;
    for (int i=1;i<n;i++) {
        int u,v;
        cin >> u >> v;
        g[u].pb(v);
        g[v].pb(u);
    }
    dfs(1);
    for (int i=1;i<=m;i++) {
        cin >> a[i];
        add(i);
    }
    while (q--) {
        int tp,l,r,v;
        cin >> tp;
        if (tp==1) {
            cin >> l >> v;
            del(l);
            a[l]=v;
            add(l);
        } else {
            cin >> l >> r >> v;
            auto it=t[v].lower_bound(l);
            if (it!=t[v].end() and *it<=r) {
                cout << *it << ' ' << *it << '\n';
            } else {
                it=s[v].upper_bound(l);
                if (it!=s[v].end() and *it<=r)
                    cout << *it-1 << ' ' << *it << '\n';
                else
                    cout << -1 << ' ' << -1 << '\n';
            }
        }
    }
} 

signed main() {
    // freopen("triangles.in", "r", stdin);
    // freopen("triangles.out", "w", stdout);
    // fx
    kanagattandirilmagandiktarinizdan
    int test = 1, count = 1;
    // cin >> test;
    while (test--) {
        // cout << "Case " << count << ":\n";
        solve();
        if (test) {
            cout << '\n';
            count++;
        }
    }
    return 0;
}

// ctrl + shift + p make stress isis__Good isis__Generator
// g++ -std=c++17 (path) -o run
// .\run
# Verdict Execution time Memory Grader output
1 Correct 7 ms 39504 KB n=5
2 Correct 7 ms 39504 KB n=100
3 Incorrect 9 ms 39504 KB Wrong range.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 39504 KB n=5
2 Correct 7 ms 39504 KB n=100
3 Incorrect 9 ms 39504 KB Wrong range.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 39504 KB n=5
2 Correct 7 ms 39504 KB n=100
3 Incorrect 9 ms 39504 KB Wrong range.
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 39504 KB n=5
2 Correct 7 ms 39504 KB n=100
3 Incorrect 9 ms 39504 KB Wrong range.
4 Halted 0 ms 0 KB -