Submission #865110

# Submission time Handle Problem Language Result Execution time Memory
865110 2023-10-24T05:37:07 Z vjudge1 Birthday gift (IZhO18_treearray) C++17
0 / 100
1 ms 348 KB
/// tree bends in youth
/// 24  .10.2023
/// success is doing same thing in every single day!!!
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
using namespace std;
const ll N =100+ 5;
const ll NN =2e6 + 5;
const ll INF = -1e1;
const ll MOD = 1e9 + 7;
const ll LG = 18;
const ll k = 316;
vector <int> g[101];
int tin[N],tout[N],a[N];
int p[N][16];
void dfs(int v){
    tout[v] = tin[v];
    for(int to : g[v]){
        if(tin[to] ==0){
            tin[to] = tout[v] + 1;
            p[to][0] = v;
            dfs(to);
            tout[v] = tout[to];
        }
    }
}
bool upper(int x,int y){
    if(tin[x] <= tin[y] && tout[x] >= tout[y])return 1;
    else return 0;
}
int lca(int x,int y){
    for(int j = 6;j >= 0;j--){
        int h = p[x][j];
        if(upper(h,y) == 0)x = h;
    }
    return p[x][0];
}
void solve(){
    int n,m,q;
    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);
    }
    p[1][0] = 1;
    tin[1]= 1;
    dfs(1);
    for(int i = 1;i <= 6;i++){
        for(int j = 1;j <= n;j++){
            p[j][i] = p[p[j][i - 1]][i - 1];
        }
    }
    for(int i = 1;i <= m;i++){
        cin >> a[i];
    }
    while(q--){
        int tp,l,r,x;
        cin >> tp >> l >> r;
        if(tp == 1){
            a[l] = r;
        }
        else{
            cin >> x;
            bool ok = 0;
            for(int j = l;j <= r;j++){
                int lc = a[j];
                if(lc == x){
                    cout << j << ' ' << j << '\n';
                    ok = 1;
                    break;
                }
                int i = l + 1;
                while(lc != x && i <= r){
                    int lcc= lca(lc,a[i]);
                    if(lcc == x){
                        cout << j << ' ' << i << '\n';
                        ok = 1;
                        break;
                    }
                    i++;
                }

                if(ok)break;
            }
            if(!ok)cout << "-1 -1\n";
        }
    }

}
main (){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    ll abd= 1;
//    cin >> abd;
    for(ll i = 1;i <= abd;i++){
//        cout << "Case " << i << ":\n";
        solve();
    }
}


Compilation message

treearray.cpp:96:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   96 | main (){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB n=5
2 Incorrect 1 ms 348 KB Wrong range.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB n=5
2 Incorrect 1 ms 348 KB Wrong range.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB n=5
2 Incorrect 1 ms 348 KB Wrong range.
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB n=5
2 Incorrect 1 ms 348 KB Wrong range.
3 Halted 0 ms 0 KB -