Submission #892815

# Submission time Handle Problem Language Result Execution time Memory
892815 2023-12-26T03:15:48 Z vjudge1 Birthday gift (IZhO18_treearray) C++17
30 / 100
4000 ms 7848 KB
#include "bits/stdc++.h"
using namespace std;       

// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")

using ll = long long;
using ld = long double;
#define pb push_back
#define ff first
#define ss second
#define sz(x) (ll)(x).size()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
void IOIGold2024_InshAllah() { ios_base::sync_with_stdio(false); cin.tie(NULL); }
ll binmul(ll a, ll b, ll c) { ll res = 0; while(b) { if(b&1) (res += a) %= c; (a += a) %= c; b >>= 1; } return res; }
ll binpow(ll a, ll b, ll c) { ll res = 1; while(b) { if(b&1) (res *= a) %= c; (a *= a) %= c; b >>= 1; } return res; }
template<typename T> T gcd(T a, T b) { if(b==0) return a; return gcd(b, a%b); }
template<typename T> T lcm(T a, T b) { return a/gcd(a, b)*b; }
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ld rnd() { return rng()%INT_MAX*1.0/INT_MAX; }

const ll inf = 1e18+7, MX = LLONG_MAX, MN = LLONG_MIN;
const ll mod = 1e9+7, N = 2e5+5;
vector<ll> g[N];
ll up[N][18], d[N], a[N];

void dfs(ll v, ll p) {
    d[v] = d[p]+1, up[v][0] = p;
    for(ll i=1; i<18; i++) up[v][i] = up[up[v][i-1]][i-1];
    for(auto to: g[v]) {
        if(to==p) continue;
        dfs(to, v);
    }
}

ll lca(ll x, ll y) {
    if(d[x]<d[y]) swap(x, y);
    ll k = d[x]-d[y];
    for(ll i=17; i>=0; i--) {
        if(k&(1<<i)) x = up[x][i];
    }
    if(x==y) return x;
    for(ll i=17; i>=0; i--) {
        if(up[x][i]!=up[y][i]) {
            x = up[x][i];
            y = up[y][i];
        }
    }
    return up[x][0];
}

void kigash() {
    ll n, m, q;
    cin>>n>>m>>q;
    for(ll i=1; i<n; i++) {
        ll u, v;
        cin>>u>>v;
        g[u].pb(v), g[v].pb(u);
    }
    for(ll i=1; i<=m; i++) cin>>a[i];
    dfs(1, 0);
    while(q--) {
        ll type, v, pos, l, r;
        cin>>type;
        if(type==1) {
            cin>>pos>>v;
            a[pos] = v;
        }
        else {
            cin>>l>>r>>v;
            ll L = -1, R = -1;
            for(ll i=l; i<=r; i++) {
                ll x = a[i];
                for(ll j=i; j<=r; j++) {
                    x = lca(x, a[j]);
                    if(x==v) {
                        L = i, R = j;
                        break;
                    }
                }
                if(L>-1) break;
            }
            cout<<L<<" "<<R<<"\n";
        }
    }
    return;
}

signed main(/*Kigash Amir*/) {
    // freopen("");
    IOIGold2024_InshAllah();
    ll tt = 1;
    // cin>>tt;
    for(ll i=1; i<=tt; i++) {
        kigash();
    }
}

Compilation message

treearray.cpp: In function 'void freopen(std::string)':
treearray.cpp:17:33: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
      |                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:17:73: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 | void freopen(string s) { freopen((s+".in").c_str(), "r", stdin); freopen((s+".out").c_str(), "w", stdout); }
      |                                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7512 KB n=5
2 Correct 3 ms 7512 KB n=100
3 Correct 3 ms 7512 KB n=100
4 Correct 2 ms 7512 KB n=100
5 Correct 2 ms 7512 KB n=100
6 Correct 9 ms 7516 KB n=100
7 Correct 9 ms 7560 KB n=100
8 Correct 3 ms 7512 KB n=100
9 Correct 3 ms 7512 KB n=100
10 Correct 6 ms 7516 KB n=100
11 Correct 6 ms 7512 KB n=100
12 Correct 2 ms 7516 KB n=100
13 Correct 2 ms 7516 KB n=100
14 Correct 2 ms 7516 KB n=100
15 Correct 2 ms 7516 KB n=100
16 Correct 2 ms 7516 KB n=100
17 Correct 3 ms 7516 KB n=100
18 Correct 2 ms 7516 KB n=100
19 Correct 2 ms 7516 KB n=100
20 Correct 2 ms 7516 KB n=100
21 Correct 3 ms 7516 KB n=100
22 Correct 2 ms 7516 KB n=100
23 Correct 4 ms 7516 KB n=100
24 Correct 4 ms 7516 KB n=100
25 Correct 2 ms 7564 KB n=100
26 Correct 2 ms 7516 KB n=12
27 Correct 5 ms 7516 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7512 KB n=5
2 Correct 3 ms 7512 KB n=100
3 Correct 3 ms 7512 KB n=100
4 Correct 2 ms 7512 KB n=100
5 Correct 2 ms 7512 KB n=100
6 Correct 9 ms 7516 KB n=100
7 Correct 9 ms 7560 KB n=100
8 Correct 3 ms 7512 KB n=100
9 Correct 3 ms 7512 KB n=100
10 Correct 6 ms 7516 KB n=100
11 Correct 6 ms 7512 KB n=100
12 Correct 2 ms 7516 KB n=100
13 Correct 2 ms 7516 KB n=100
14 Correct 2 ms 7516 KB n=100
15 Correct 2 ms 7516 KB n=100
16 Correct 2 ms 7516 KB n=100
17 Correct 3 ms 7516 KB n=100
18 Correct 2 ms 7516 KB n=100
19 Correct 2 ms 7516 KB n=100
20 Correct 2 ms 7516 KB n=100
21 Correct 3 ms 7516 KB n=100
22 Correct 2 ms 7516 KB n=100
23 Correct 4 ms 7516 KB n=100
24 Correct 4 ms 7516 KB n=100
25 Correct 2 ms 7564 KB n=100
26 Correct 2 ms 7516 KB n=12
27 Correct 5 ms 7516 KB n=100
28 Correct 4 ms 7572 KB n=500
29 Correct 114 ms 7612 KB n=500
30 Correct 76 ms 7592 KB n=500
31 Correct 88 ms 7512 KB n=500
32 Correct 5 ms 7512 KB n=500
33 Correct 67 ms 7516 KB n=500
34 Correct 2 ms 7516 KB n=500
35 Correct 94 ms 7672 KB n=500
36 Correct 1040 ms 7840 KB n=500
37 Correct 1073 ms 7580 KB n=500
38 Correct 1042 ms 7764 KB n=500
39 Correct 123 ms 7596 KB n=500
40 Correct 107 ms 7596 KB n=500
41 Correct 105 ms 7512 KB n=500
42 Correct 509 ms 7588 KB n=500
43 Correct 516 ms 7512 KB n=500
44 Correct 495 ms 7512 KB n=500
45 Correct 3 ms 7512 KB n=500
46 Correct 100 ms 7612 KB n=500
47 Correct 81 ms 7516 KB n=500
48 Correct 2 ms 7516 KB n=500
49 Correct 77 ms 7516 KB n=500
50 Correct 79 ms 7516 KB n=500
51 Correct 150 ms 7600 KB n=500
52 Correct 173 ms 7608 KB n=500
53 Correct 125 ms 7516 KB n=500
54 Correct 71 ms 7516 KB n=500
55 Correct 22 ms 7768 KB n=278
56 Correct 620 ms 7512 KB n=500
57 Correct 696 ms 7672 KB n=500
58 Correct 400 ms 7848 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7512 KB n=5
2 Correct 3 ms 7512 KB n=100
3 Correct 3 ms 7512 KB n=100
4 Correct 2 ms 7512 KB n=100
5 Correct 2 ms 7512 KB n=100
6 Correct 9 ms 7516 KB n=100
7 Correct 9 ms 7560 KB n=100
8 Correct 3 ms 7512 KB n=100
9 Correct 3 ms 7512 KB n=100
10 Correct 6 ms 7516 KB n=100
11 Correct 6 ms 7512 KB n=100
12 Correct 2 ms 7516 KB n=100
13 Correct 2 ms 7516 KB n=100
14 Correct 2 ms 7516 KB n=100
15 Correct 2 ms 7516 KB n=100
16 Correct 2 ms 7516 KB n=100
17 Correct 3 ms 7516 KB n=100
18 Correct 2 ms 7516 KB n=100
19 Correct 2 ms 7516 KB n=100
20 Correct 2 ms 7516 KB n=100
21 Correct 3 ms 7516 KB n=100
22 Correct 2 ms 7516 KB n=100
23 Correct 4 ms 7516 KB n=100
24 Correct 4 ms 7516 KB n=100
25 Correct 2 ms 7564 KB n=100
26 Correct 2 ms 7516 KB n=12
27 Correct 5 ms 7516 KB n=100
28 Correct 4 ms 7572 KB n=500
29 Correct 114 ms 7612 KB n=500
30 Correct 76 ms 7592 KB n=500
31 Correct 88 ms 7512 KB n=500
32 Correct 5 ms 7512 KB n=500
33 Correct 67 ms 7516 KB n=500
34 Correct 2 ms 7516 KB n=500
35 Correct 94 ms 7672 KB n=500
36 Correct 1040 ms 7840 KB n=500
37 Correct 1073 ms 7580 KB n=500
38 Correct 1042 ms 7764 KB n=500
39 Correct 123 ms 7596 KB n=500
40 Correct 107 ms 7596 KB n=500
41 Correct 105 ms 7512 KB n=500
42 Correct 509 ms 7588 KB n=500
43 Correct 516 ms 7512 KB n=500
44 Correct 495 ms 7512 KB n=500
45 Correct 3 ms 7512 KB n=500
46 Correct 100 ms 7612 KB n=500
47 Correct 81 ms 7516 KB n=500
48 Correct 2 ms 7516 KB n=500
49 Correct 77 ms 7516 KB n=500
50 Correct 79 ms 7516 KB n=500
51 Correct 150 ms 7600 KB n=500
52 Correct 173 ms 7608 KB n=500
53 Correct 125 ms 7516 KB n=500
54 Correct 71 ms 7516 KB n=500
55 Correct 22 ms 7768 KB n=278
56 Correct 620 ms 7512 KB n=500
57 Correct 696 ms 7672 KB n=500
58 Correct 400 ms 7848 KB n=500
59 Correct 54 ms 7512 KB n=2000
60 Execution timed out 4093 ms 7788 KB Time limit exceeded
61 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 7512 KB n=5
2 Correct 3 ms 7512 KB n=100
3 Correct 3 ms 7512 KB n=100
4 Correct 2 ms 7512 KB n=100
5 Correct 2 ms 7512 KB n=100
6 Correct 9 ms 7516 KB n=100
7 Correct 9 ms 7560 KB n=100
8 Correct 3 ms 7512 KB n=100
9 Correct 3 ms 7512 KB n=100
10 Correct 6 ms 7516 KB n=100
11 Correct 6 ms 7512 KB n=100
12 Correct 2 ms 7516 KB n=100
13 Correct 2 ms 7516 KB n=100
14 Correct 2 ms 7516 KB n=100
15 Correct 2 ms 7516 KB n=100
16 Correct 2 ms 7516 KB n=100
17 Correct 3 ms 7516 KB n=100
18 Correct 2 ms 7516 KB n=100
19 Correct 2 ms 7516 KB n=100
20 Correct 2 ms 7516 KB n=100
21 Correct 3 ms 7516 KB n=100
22 Correct 2 ms 7516 KB n=100
23 Correct 4 ms 7516 KB n=100
24 Correct 4 ms 7516 KB n=100
25 Correct 2 ms 7564 KB n=100
26 Correct 2 ms 7516 KB n=12
27 Correct 5 ms 7516 KB n=100
28 Correct 4 ms 7572 KB n=500
29 Correct 114 ms 7612 KB n=500
30 Correct 76 ms 7592 KB n=500
31 Correct 88 ms 7512 KB n=500
32 Correct 5 ms 7512 KB n=500
33 Correct 67 ms 7516 KB n=500
34 Correct 2 ms 7516 KB n=500
35 Correct 94 ms 7672 KB n=500
36 Correct 1040 ms 7840 KB n=500
37 Correct 1073 ms 7580 KB n=500
38 Correct 1042 ms 7764 KB n=500
39 Correct 123 ms 7596 KB n=500
40 Correct 107 ms 7596 KB n=500
41 Correct 105 ms 7512 KB n=500
42 Correct 509 ms 7588 KB n=500
43 Correct 516 ms 7512 KB n=500
44 Correct 495 ms 7512 KB n=500
45 Correct 3 ms 7512 KB n=500
46 Correct 100 ms 7612 KB n=500
47 Correct 81 ms 7516 KB n=500
48 Correct 2 ms 7516 KB n=500
49 Correct 77 ms 7516 KB n=500
50 Correct 79 ms 7516 KB n=500
51 Correct 150 ms 7600 KB n=500
52 Correct 173 ms 7608 KB n=500
53 Correct 125 ms 7516 KB n=500
54 Correct 71 ms 7516 KB n=500
55 Correct 22 ms 7768 KB n=278
56 Correct 620 ms 7512 KB n=500
57 Correct 696 ms 7672 KB n=500
58 Correct 400 ms 7848 KB n=500
59 Correct 54 ms 7512 KB n=2000
60 Execution timed out 4093 ms 7788 KB Time limit exceeded
61 Halted 0 ms 0 KB -