Submission #893138

# Submission time Handle Problem Language Result Execution time Memory
893138 2023-12-26T14:50:59 Z Andrey Birthday gift (IZhO18_treearray) C++14
0 / 100
6 ms 28760 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> haha[200001];
int bruh[200001][18];
vector<int> dep(200001);

long long lca(long long a, long long b) {
    if(dep[a] < dep[b]) {
        swap(a,b);
    }
    long long c = dep[a]-dep[b];
    for(long long i = 17; i >= 0; i--) {
        if((1 << i)&c) {
            a = bruh[a][i];
        }
    }
    for(long long i = 17; i >= 0; i--) {
        if(bruh[a][i] != -1 && bruh[a][i] != bruh[b][i]) {
            a = bruh[a][i];
            b = bruh[b][i];
        }
    }
    if(a == b) {
        return a;
    }
    else {
        return bruh[a][0];
    }
}

void dfs(long long a, long long t, long long d) {
    bruh[a][0] = t;
    dep[a] = d;
    for(long long i = 0; i < haha[a].size(); i++) {
        if(haha[a][i] != t) {
            dfs(haha[a][i],a,d+1);
        }
    }
}

multiset<int> wow[200001];
multiset<int> yay[200001];

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m,q,a,b,z,l,r;
    cin >> n >> m >> q;
    for(int i = 0; i < n-1; i++) {
        cin >> a >> b;
        haha[a].push_back(b);
        haha[b].push_back(a);
    }
    dfs(1,-1,0);
    for(long long i = 1; i < 18; i++) {
        for(long long j = 1; j <= n; j++) {
            if(bruh[j][i-1] == -1) {
                bruh[j][i] = -1;
            }
            else {
                bruh[j][i] = bruh[bruh[j][i-1]][i-1];
            }
        }
    }
    vector<int> wut(m+1);
    for(int i = 1; i <= m; i++) {
        cin >> wut[i];
        yay[wut[i]].insert(i);
    }
    for(int i = 1; i < m; i++) {
        wow[lca(wut[i],wut[i+1])].insert(i);
    }
    for(int i = 0; i < q; i++) {
        cin >> z;
        if(z == 1) {
            cin >> a >> b;
            yay[wut[a]].erase(a);
            yay[b].insert(a);
            if(a > 1) {
                wow[lca(wut[a],wut[a-1])].erase(a-1);
                wow[lca(b,wut[a-1])].erase(a-1);
            }
            if(a < m) {
                wow[lca(wut[a],wut[a+1])].erase(a);
                wow[lca(b,wut[a+1])].erase(a);
            }
            wut[a] = b;
        }
        else {
            cin >> l >> r >> a;
            auto d = yay[a].lower_bound(l);
            if(yay[a].empty() || d == yay[a].end() || (*d) > r) {
                auto e = wow[a].lower_bound(l);
                if(wow[a].empty() || e == wow[a].end() || (*e) >= r) {
                    cout << -1 << " " << -1 << "\n";
                }
                else {
                    cout << (*e) << " " << (*e)+1 << "\n";
                }
            }
            else {
                cout << (*d) << " " << (*d) << "\n";
            }
        }
    }
    return 0;
}

Compilation message

treearray.cpp: In function 'void dfs(long long int, long long int, long long int)':
treearray.cpp:35:28: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |     for(long long i = 0; i < haha[a].size(); i++) {
      |                          ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 28508 KB n=5
2 Correct 6 ms 28568 KB n=100
3 Correct 6 ms 28760 KB n=100
4 Incorrect 6 ms 28508 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 28508 KB n=5
2 Correct 6 ms 28568 KB n=100
3 Correct 6 ms 28760 KB n=100
4 Incorrect 6 ms 28508 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 28508 KB n=5
2 Correct 6 ms 28568 KB n=100
3 Correct 6 ms 28760 KB n=100
4 Incorrect 6 ms 28508 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 28508 KB n=5
2 Correct 6 ms 28568 KB n=100
3 Correct 6 ms 28760 KB n=100
4 Incorrect 6 ms 28508 KB Jury has the answer but participant has not
5 Halted 0 ms 0 KB -