Submission #944348

# Submission time Handle Problem Language Result Execution time Memory
944348 2024-03-12T15:26:43 Z dilanyan Birthday gift (IZhO18_treearray) C++17
0 / 100
1 ms 2908 KB
//-------------dilanyan------------\\ 
 
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
 
//------------------KarginDefines--------------------\\ 
 
#define ll long long
#define pb push_back
#define all(u) (u).begin(), (u).end()
#define pqueue priority_queue
#define upper upper_bound
#define lower lower_bound
#define umap unordered_map
#define uset unordered_set
#define Kargin ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Usaco freopen(".in", "r", stdin); freopen(".out", "w", stdout);
 
 
//-------------------KarginConstants------------------\\ 
 
const ll mod = 1000000007;
const ll inf = 1e9 + 15;
 
//-------------------KarginCode------------------------\\ 
 
const int N = 100005;

int a[N];
vector<int> g[N];
int tin[N], tout[N], tim = 0;
int up[N][20];

void dfs(int u, int p) {
    tin[u] = tim++;
    up[u][0] = p;
    for (int v : g[u]) {
        if (v != p) dfs(v, u);
    }
    tout[u] = tim;
}

bool anc(int u, int v) {
    return tin[u] <= tin[v] && tout[u] >= tout[v];
}

int lca(int x, int y) {
    if (anc(x, y)) return x;
    if (anc(y, x)) return y;
    for (int i = 19;i >= 0;i--) {
        if (!anc(up[x][i], y)) x = up[x][i];
    }
    return up[x][0];
}

void KarginSolve() {
    int n, m, q;
    cin >> n >> m >> q;
    for (int i = 0;i < n - 1;i++) {
        int u, v;
        cin >> u >> v;
        g[u].pb(v), g[v].pb(u);
    }
    for (int i = 1;i <= m;i++) cin >> a[i];
    dfs(1, 1);
    for (int j = 1;j < 20;j++) {
        for (int i = 1;i <= n;i++) {
            up[i][j] = up[up[i][j - 1]][j - 1];
        }
    }
    while (q--) {
        int t; cin >> t;
        if (t == 1) {
            int pos, v;
            cin >> pos >> v;
            a[pos] = v;
        }
        else {
            int l, r, u;
            cin >> l >> r >> u;
            bool flag = false;
            for (int i = l;i <= r;i++) {
                if (a[i] == u) {
                    cout << i << ' ' << i << '\n';
                    flag = true;
                    break;
                }
            }
            if(flag) continue;
            for (int i = l;i <= r;) {
                int s = i, e = i;
                for (int j = i;j <= r;j++) {
                    e = j + 1;
                    if (!anc(u, a[j])) break;
                }
                if (flag) break;
                if (e - s < 2) i = e + 1;
                else {
                    int x = -1, y = -1;
                    for (int v : g[u]) {
                        if (v == up[u][0]) continue;
                        for (int j = s; j < e;j++) {
                            if (anc(v, a[j])) {
                                if (x == -1) x = j;
                                else y = j;
                                break;
                            }
                        }
                        if (y != -1) {
                            if (x > y) swap(x, y);
                            cout << x << ' ' << y << '\n';
                            flag = true;
                            break;
                        }
                    }
                    if (flag) break;
                    i = e + 1;
                }
            }
            if(flag) continue;
            cout << -1 << ' ' << -1 << '\n';
        }
    }
}
 
int main() {
    Kargin;
    int test = 1;
    //cin >> test;
    while (test--) {
        KarginSolve();
    }
    return 0;
}

Compilation message

treearray.cpp:1:1: warning: multi-line comment [-Wcomment]
    1 | //-------------dilanyan------------\\
      | ^
treearray.cpp:8:1: warning: multi-line comment [-Wcomment]
    8 | //------------------KarginDefines--------------------\\
      | ^
treearray.cpp:22:1: warning: multi-line comment [-Wcomment]
   22 | //-------------------KarginConstants------------------\\
      | ^
treearray.cpp:27:1: warning: multi-line comment [-Wcomment]
   27 | //-------------------KarginCode------------------------\\
      | ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB n=5
2 Incorrect 1 ms 2908 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB n=5
2 Incorrect 1 ms 2908 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB n=5
2 Incorrect 1 ms 2908 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2908 KB n=5
2 Incorrect 1 ms 2908 KB Jury has the answer but participant has not
3 Halted 0 ms 0 KB -