답안 #893842

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
893842 2023-12-27T14:20:14 Z kigash Birthday gift (IZhO18_treearray) C++17
100 / 100
1092 ms 112408 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 = 3e5+5;
vector<ll> g[N];
set<ll> st[N], t[N];
ll d[N], up[N][20], 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=18; i>=0; i--) {
        if(k&(1<<i)) x = up[x][i];
    }
    if(x==y) return x;
    for(ll i=18; 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);
    }
    dfs(1, 0);
    for(ll i=1; i<=m; i++) {
        cin>>a[i];
        t[a[i]].insert(i);
        if(i>1) st[lca(a[i], a[i-1])].insert(i-1);
    }
    while(q--) {
        ll type, pos, v, l, r;
        cin>>type;
        if(type==1) {
            cin>>pos>>v;
            t[a[pos]].erase(pos);
            st[lca(a[pos], a[pos-1])].erase(pos-1);
            st[lca(a[pos+1], a[pos])].erase(pos);
            a[pos] = v;
            t[a[pos]].insert(pos);
            st[lca(a[pos], a[pos-1])].insert(pos-1);
            st[lca(a[pos+1], a[pos])].insert(pos);
        }
        else {
            cin>>l>>r>>v;
            auto it = t[v].lower_bound(l);
            if(it!=t[v].end() && (*it)<=r) cout<<(*it)<<" "<<(*it)<<"\n";
            else {
                auto it = st[v].lower_bound(l);
                if(it!=st[v].end() && (*it)<r) cout<<(*it)<<" "<<(*it)+1<<"\n";
                else cout<<"-1 -1\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); }
      |                                                                  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 37724 KB n=5
2 Correct 8 ms 37724 KB n=100
3 Correct 9 ms 37724 KB n=100
4 Correct 8 ms 37724 KB n=100
5 Correct 8 ms 37724 KB n=100
6 Correct 8 ms 37724 KB n=100
7 Correct 9 ms 37952 KB n=100
8 Correct 8 ms 37720 KB n=100
9 Correct 8 ms 37724 KB n=100
10 Correct 8 ms 37724 KB n=100
11 Correct 8 ms 37960 KB n=100
12 Correct 8 ms 37724 KB n=100
13 Correct 8 ms 37724 KB n=100
14 Correct 8 ms 37720 KB n=100
15 Correct 8 ms 37724 KB n=100
16 Correct 8 ms 37724 KB n=100
17 Correct 8 ms 37724 KB n=100
18 Correct 8 ms 37976 KB n=100
19 Correct 8 ms 37724 KB n=100
20 Correct 8 ms 37724 KB n=100
21 Correct 8 ms 37720 KB n=100
22 Correct 8 ms 37884 KB n=100
23 Correct 8 ms 37724 KB n=100
24 Correct 8 ms 37724 KB n=100
25 Correct 10 ms 37720 KB n=100
26 Correct 8 ms 37724 KB n=12
27 Correct 8 ms 37724 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 37724 KB n=5
2 Correct 8 ms 37724 KB n=100
3 Correct 9 ms 37724 KB n=100
4 Correct 8 ms 37724 KB n=100
5 Correct 8 ms 37724 KB n=100
6 Correct 8 ms 37724 KB n=100
7 Correct 9 ms 37952 KB n=100
8 Correct 8 ms 37720 KB n=100
9 Correct 8 ms 37724 KB n=100
10 Correct 8 ms 37724 KB n=100
11 Correct 8 ms 37960 KB n=100
12 Correct 8 ms 37724 KB n=100
13 Correct 8 ms 37724 KB n=100
14 Correct 8 ms 37720 KB n=100
15 Correct 8 ms 37724 KB n=100
16 Correct 8 ms 37724 KB n=100
17 Correct 8 ms 37724 KB n=100
18 Correct 8 ms 37976 KB n=100
19 Correct 8 ms 37724 KB n=100
20 Correct 8 ms 37724 KB n=100
21 Correct 8 ms 37720 KB n=100
22 Correct 8 ms 37884 KB n=100
23 Correct 8 ms 37724 KB n=100
24 Correct 8 ms 37724 KB n=100
25 Correct 10 ms 37720 KB n=100
26 Correct 8 ms 37724 KB n=12
27 Correct 8 ms 37724 KB n=100
28 Correct 9 ms 37980 KB n=500
29 Correct 9 ms 37976 KB n=500
30 Correct 9 ms 37980 KB n=500
31 Correct 10 ms 37976 KB n=500
32 Correct 8 ms 37980 KB n=500
33 Correct 8 ms 37980 KB n=500
34 Correct 9 ms 37980 KB n=500
35 Correct 8 ms 37980 KB n=500
36 Correct 8 ms 37980 KB n=500
37 Correct 8 ms 37980 KB n=500
38 Correct 9 ms 37976 KB n=500
39 Correct 9 ms 37976 KB n=500
40 Correct 9 ms 37980 KB n=500
41 Correct 9 ms 37980 KB n=500
42 Correct 9 ms 37980 KB n=500
43 Correct 8 ms 37980 KB n=500
44 Correct 8 ms 37980 KB n=500
45 Correct 8 ms 37868 KB n=500
46 Correct 9 ms 37980 KB n=500
47 Correct 8 ms 37976 KB n=500
48 Correct 8 ms 37976 KB n=500
49 Correct 10 ms 37980 KB n=500
50 Correct 9 ms 37980 KB n=500
51 Correct 8 ms 37980 KB n=500
52 Correct 8 ms 37980 KB n=500
53 Correct 8 ms 37892 KB n=500
54 Correct 8 ms 37976 KB n=500
55 Correct 8 ms 37980 KB n=278
56 Correct 8 ms 37976 KB n=500
57 Correct 8 ms 37976 KB n=500
58 Correct 9 ms 37976 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 37724 KB n=5
2 Correct 8 ms 37724 KB n=100
3 Correct 9 ms 37724 KB n=100
4 Correct 8 ms 37724 KB n=100
5 Correct 8 ms 37724 KB n=100
6 Correct 8 ms 37724 KB n=100
7 Correct 9 ms 37952 KB n=100
8 Correct 8 ms 37720 KB n=100
9 Correct 8 ms 37724 KB n=100
10 Correct 8 ms 37724 KB n=100
11 Correct 8 ms 37960 KB n=100
12 Correct 8 ms 37724 KB n=100
13 Correct 8 ms 37724 KB n=100
14 Correct 8 ms 37720 KB n=100
15 Correct 8 ms 37724 KB n=100
16 Correct 8 ms 37724 KB n=100
17 Correct 8 ms 37724 KB n=100
18 Correct 8 ms 37976 KB n=100
19 Correct 8 ms 37724 KB n=100
20 Correct 8 ms 37724 KB n=100
21 Correct 8 ms 37720 KB n=100
22 Correct 8 ms 37884 KB n=100
23 Correct 8 ms 37724 KB n=100
24 Correct 8 ms 37724 KB n=100
25 Correct 10 ms 37720 KB n=100
26 Correct 8 ms 37724 KB n=12
27 Correct 8 ms 37724 KB n=100
28 Correct 9 ms 37980 KB n=500
29 Correct 9 ms 37976 KB n=500
30 Correct 9 ms 37980 KB n=500
31 Correct 10 ms 37976 KB n=500
32 Correct 8 ms 37980 KB n=500
33 Correct 8 ms 37980 KB n=500
34 Correct 9 ms 37980 KB n=500
35 Correct 8 ms 37980 KB n=500
36 Correct 8 ms 37980 KB n=500
37 Correct 8 ms 37980 KB n=500
38 Correct 9 ms 37976 KB n=500
39 Correct 9 ms 37976 KB n=500
40 Correct 9 ms 37980 KB n=500
41 Correct 9 ms 37980 KB n=500
42 Correct 9 ms 37980 KB n=500
43 Correct 8 ms 37980 KB n=500
44 Correct 8 ms 37980 KB n=500
45 Correct 8 ms 37868 KB n=500
46 Correct 9 ms 37980 KB n=500
47 Correct 8 ms 37976 KB n=500
48 Correct 8 ms 37976 KB n=500
49 Correct 10 ms 37980 KB n=500
50 Correct 9 ms 37980 KB n=500
51 Correct 8 ms 37980 KB n=500
52 Correct 8 ms 37980 KB n=500
53 Correct 8 ms 37892 KB n=500
54 Correct 8 ms 37976 KB n=500
55 Correct 8 ms 37980 KB n=278
56 Correct 8 ms 37976 KB n=500
57 Correct 8 ms 37976 KB n=500
58 Correct 9 ms 37976 KB n=500
59 Correct 10 ms 38232 KB n=2000
60 Correct 11 ms 38372 KB n=2000
61 Correct 11 ms 38236 KB n=2000
62 Correct 11 ms 38232 KB n=2000
63 Correct 12 ms 38232 KB n=2000
64 Correct 11 ms 38236 KB n=2000
65 Correct 12 ms 38236 KB n=2000
66 Correct 12 ms 38304 KB n=2000
67 Correct 11 ms 38232 KB n=2000
68 Correct 10 ms 38236 KB n=2000
69 Correct 10 ms 38236 KB n=2000
70 Correct 10 ms 38232 KB n=2000
71 Correct 10 ms 38236 KB n=2000
72 Correct 10 ms 38236 KB n=2000
73 Correct 10 ms 38132 KB n=2000
74 Correct 11 ms 38236 KB n=1844
75 Correct 10 ms 38232 KB n=2000
76 Correct 11 ms 38236 KB n=2000
77 Correct 11 ms 38236 KB n=2000
78 Correct 11 ms 38368 KB n=2000
79 Correct 11 ms 38232 KB n=2000
80 Correct 10 ms 38236 KB n=2000
81 Correct 11 ms 38232 KB n=2000
82 Correct 12 ms 38196 KB n=2000
83 Correct 11 ms 38236 KB n=2000
84 Correct 11 ms 38312 KB n=2000
85 Correct 11 ms 38316 KB n=2000
86 Correct 10 ms 38236 KB n=2000
87 Correct 10 ms 38304 KB n=2000
88 Correct 10 ms 38240 KB n=2000
89 Correct 12 ms 38240 KB n=2000
90 Correct 11 ms 38236 KB n=2000
91 Correct 10 ms 38236 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 37724 KB n=5
2 Correct 8 ms 37724 KB n=100
3 Correct 9 ms 37724 KB n=100
4 Correct 8 ms 37724 KB n=100
5 Correct 8 ms 37724 KB n=100
6 Correct 8 ms 37724 KB n=100
7 Correct 9 ms 37952 KB n=100
8 Correct 8 ms 37720 KB n=100
9 Correct 8 ms 37724 KB n=100
10 Correct 8 ms 37724 KB n=100
11 Correct 8 ms 37960 KB n=100
12 Correct 8 ms 37724 KB n=100
13 Correct 8 ms 37724 KB n=100
14 Correct 8 ms 37720 KB n=100
15 Correct 8 ms 37724 KB n=100
16 Correct 8 ms 37724 KB n=100
17 Correct 8 ms 37724 KB n=100
18 Correct 8 ms 37976 KB n=100
19 Correct 8 ms 37724 KB n=100
20 Correct 8 ms 37724 KB n=100
21 Correct 8 ms 37720 KB n=100
22 Correct 8 ms 37884 KB n=100
23 Correct 8 ms 37724 KB n=100
24 Correct 8 ms 37724 KB n=100
25 Correct 10 ms 37720 KB n=100
26 Correct 8 ms 37724 KB n=12
27 Correct 8 ms 37724 KB n=100
28 Correct 9 ms 37980 KB n=500
29 Correct 9 ms 37976 KB n=500
30 Correct 9 ms 37980 KB n=500
31 Correct 10 ms 37976 KB n=500
32 Correct 8 ms 37980 KB n=500
33 Correct 8 ms 37980 KB n=500
34 Correct 9 ms 37980 KB n=500
35 Correct 8 ms 37980 KB n=500
36 Correct 8 ms 37980 KB n=500
37 Correct 8 ms 37980 KB n=500
38 Correct 9 ms 37976 KB n=500
39 Correct 9 ms 37976 KB n=500
40 Correct 9 ms 37980 KB n=500
41 Correct 9 ms 37980 KB n=500
42 Correct 9 ms 37980 KB n=500
43 Correct 8 ms 37980 KB n=500
44 Correct 8 ms 37980 KB n=500
45 Correct 8 ms 37868 KB n=500
46 Correct 9 ms 37980 KB n=500
47 Correct 8 ms 37976 KB n=500
48 Correct 8 ms 37976 KB n=500
49 Correct 10 ms 37980 KB n=500
50 Correct 9 ms 37980 KB n=500
51 Correct 8 ms 37980 KB n=500
52 Correct 8 ms 37980 KB n=500
53 Correct 8 ms 37892 KB n=500
54 Correct 8 ms 37976 KB n=500
55 Correct 8 ms 37980 KB n=278
56 Correct 8 ms 37976 KB n=500
57 Correct 8 ms 37976 KB n=500
58 Correct 9 ms 37976 KB n=500
59 Correct 10 ms 38232 KB n=2000
60 Correct 11 ms 38372 KB n=2000
61 Correct 11 ms 38236 KB n=2000
62 Correct 11 ms 38232 KB n=2000
63 Correct 12 ms 38232 KB n=2000
64 Correct 11 ms 38236 KB n=2000
65 Correct 12 ms 38236 KB n=2000
66 Correct 12 ms 38304 KB n=2000
67 Correct 11 ms 38232 KB n=2000
68 Correct 10 ms 38236 KB n=2000
69 Correct 10 ms 38236 KB n=2000
70 Correct 10 ms 38232 KB n=2000
71 Correct 10 ms 38236 KB n=2000
72 Correct 10 ms 38236 KB n=2000
73 Correct 10 ms 38132 KB n=2000
74 Correct 11 ms 38236 KB n=1844
75 Correct 10 ms 38232 KB n=2000
76 Correct 11 ms 38236 KB n=2000
77 Correct 11 ms 38236 KB n=2000
78 Correct 11 ms 38368 KB n=2000
79 Correct 11 ms 38232 KB n=2000
80 Correct 10 ms 38236 KB n=2000
81 Correct 11 ms 38232 KB n=2000
82 Correct 12 ms 38196 KB n=2000
83 Correct 11 ms 38236 KB n=2000
84 Correct 11 ms 38312 KB n=2000
85 Correct 11 ms 38316 KB n=2000
86 Correct 10 ms 38236 KB n=2000
87 Correct 10 ms 38304 KB n=2000
88 Correct 10 ms 38240 KB n=2000
89 Correct 12 ms 38240 KB n=2000
90 Correct 11 ms 38236 KB n=2000
91 Correct 10 ms 38236 KB n=2000
92 Correct 605 ms 104840 KB n=200000
93 Correct 933 ms 108656 KB n=200000
94 Correct 883 ms 111648 KB n=200000
95 Correct 594 ms 104284 KB n=200000
96 Correct 543 ms 104412 KB n=200000
97 Correct 1083 ms 107828 KB n=200000
98 Correct 677 ms 104416 KB n=200000
99 Correct 834 ms 104184 KB n=200000
100 Correct 643 ms 104404 KB n=200000
101 Correct 971 ms 112408 KB n=200000
102 Correct 401 ms 105512 KB n=200000
103 Correct 361 ms 105732 KB n=200000
104 Correct 383 ms 105364 KB n=200000
105 Correct 337 ms 105296 KB n=200000
106 Correct 360 ms 105592 KB n=200000
107 Correct 349 ms 105300 KB n=200000
108 Correct 655 ms 104192 KB n=200000
109 Correct 707 ms 104488 KB n=200000
110 Correct 778 ms 104184 KB n=200000
111 Correct 670 ms 103960 KB n=200000
112 Correct 992 ms 111592 KB n=200000
113 Correct 1092 ms 107628 KB n=200000
114 Correct 635 ms 104048 KB n=200000
115 Correct 993 ms 105968 KB n=200000
116 Correct 638 ms 104052 KB n=200000
117 Correct 979 ms 112008 KB n=200000
118 Correct 1069 ms 106764 KB n=200000
119 Correct 544 ms 104096 KB n=200000
120 Correct 807 ms 111856 KB n=200000
121 Correct 827 ms 112008 KB n=200000
122 Correct 834 ms 111924 KB n=200000
123 Correct 355 ms 105440 KB n=200000
124 Correct 160 ms 56260 KB n=25264