Submission #495868

# Submission time Handle Problem Language Result Execution time Memory
495868 2021-12-20T06:39:36 Z ergagan Birthday gift (IZhO18_treearray) C++17
56 / 100
269 ms 262148 KB
//я так много думал, что опять попал
#include <bits/stdc++.h>
#define all(x) x.begin(),x.end()
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define f first
#define s second
#define left(v) v + v
#define right(v) v + v + 1
#define ub upper_bound
#define lb lower_bound
#define pll pair<ll, ll>

using namespace std;
typedef long long ll;

//17 SEVENTEEN
const long double Pi = acos(-1.0);
const ll dx[] = {0,0,1,-1};
const ll dy[] = {1,-1,0,0};
const ll N = (ll) 1e6 + 17;
const ll M = (ll) 5e3 + 69;
const ll inf = (ll) 1e14 + 3;
const ll mod = (ll) 1e9 + 7;
ll sq(ll x) { return x * x; }

ll zxc = 1, a[N], b[N];
ll h[N], up[N][50];
ll n, m, q, tp, pos, u, v, l, r;

vector<ll> g[N];

set<ll> st[N], ts[N];

void dfs(ll v, ll p, ll lvl) {

	up[v][0] = p, h[v] = lvl;

	for(ll to : g[v]) {
		if(to != p)
			dfs(to, v, lvl + 1);
	}

}

bool bit(ll x, ll p) {
	return x & (1 << p);
}

ll lift(ll v, ll k) {
	for(ll i = 0; i < 26; i++) {
		if(bit(k, i))
			v = up[v][i];
	}
	return v;
}

ll lca(ll a, ll b) {
	if(h[a] < h[b]) swap(a, b);

	a = lift(a, h[a] - h[b]);

	if(a == b) return a;

	for(ll i = 25; i >= 0; i--) {
		if(up[a][i] != up[b][i])
			a = up[a][i], b = up[b][i];
	}

	return up[a][0];
}

ll dis(ll a, ll b) {
    return h[a] + h[b] - h[lca(a, b)] * 2;
}

void solve() {

    cin >> n >> m >> q;

    for(ll i = 1; i < n; i++) {
        cin >> u >> v;
        g[u].pb(v), g[v].pb(u);
    }

    for(ll i = 1; i <= m; i++) {
        cin >> a[i];
        st[a[i]].insert(i);
    }

    dfs(1, -1, 0);

    for(ll i = 1; i <= 25; i++) {
    	for(ll v = 1; v <= n; v++) {
    		up[v][i] = up[up[v][i - 1]][i - 1];
    	}
    }

    for(ll i = 1; i < m; i++) {
        ll x = lca(a[i], a[i + 1]);
        ts[x].insert(i);
    }

    while(q--) {
        cin >> tp;
        if(tp == 1) {
            cin >> pos >> v;
            ll x = lca(a[pos], a[pos + 1]), y = lca(a[pos], a[pos - 1]);

            if(st[a[pos]].count(pos)) st[a[pos]].erase(pos);
            if(pos < m && ts[x].count(pos)) ts[x].erase(pos);
            if(pos > 1 && ts[y].count(pos - 1)) ts[y].erase(pos - 1);

            a[pos] = v;
            x = lca(a[pos], a[pos + 1]), y = lca(a[pos], a[pos - 1]);

            st[a[pos]].insert(pos);
            if(pos < m) ts[x].insert(pos);
            if(pos > 1) ts[y].insert(pos - 1);
        }
        else {
            ll ok = 0;
            cin >> l >> r >> v;

            ll x = *st[v].lb(l);

            if(x <= r) { cout << x << " " << x << "\n"; continue; }

            x = *ts[v].lb(l);
            if(x < r) { cout << x << " " << x + 1 << "\n"; continue; }

            cout << "-1 -1\n";
        }
    }
}

/*
5 4 4
1 2
3 1
3 4
5 3
4 5 2 3
2 1 3 1
1 3 5
2 3 4 5
2 1 3 1
*/

int main(/*Уверенно*/) {
ios_base::sync_with_stdio(0);
    cin.tie(0);
/*
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
*/
//    cin >> zxc;

    for(ll i = 0; i < N; i++)
        st[i].insert(inf), ts[i].insert(inf);

    while(zxc--) {
        solve();
    }
  	return 0;
}
// さよならさ いかなくちゃ

Compilation message

treearray.cpp: In function 'void solve()':
treearray.cpp:124:16: warning: unused variable 'ok' [-Wunused-variable]
  124 |             ll ok = 0;
      |                ^~
# Verdict Execution time Memory Grader output
1 Correct 191 ms 211612 KB n=5
2 Correct 185 ms 211784 KB n=100
3 Correct 212 ms 211680 KB n=100
4 Correct 207 ms 211716 KB n=100
5 Correct 210 ms 211720 KB n=100
6 Correct 190 ms 211624 KB n=100
7 Correct 204 ms 211640 KB n=100
8 Correct 200 ms 211628 KB n=100
9 Correct 186 ms 211648 KB n=100
10 Correct 211 ms 211724 KB n=100
11 Correct 197 ms 211684 KB n=100
12 Correct 212 ms 211684 KB n=100
13 Correct 184 ms 211608 KB n=100
14 Correct 199 ms 211648 KB n=100
15 Correct 233 ms 211712 KB n=100
16 Correct 216 ms 211696 KB n=100
17 Correct 187 ms 211660 KB n=100
18 Correct 182 ms 211692 KB n=100
19 Correct 172 ms 211740 KB n=100
20 Correct 181 ms 211604 KB n=100
21 Correct 173 ms 211652 KB n=100
22 Correct 171 ms 211668 KB n=100
23 Correct 177 ms 211700 KB n=100
24 Correct 188 ms 211716 KB n=100
25 Correct 172 ms 211624 KB n=100
26 Correct 166 ms 211672 KB n=12
27 Correct 175 ms 211700 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 191 ms 211612 KB n=5
2 Correct 185 ms 211784 KB n=100
3 Correct 212 ms 211680 KB n=100
4 Correct 207 ms 211716 KB n=100
5 Correct 210 ms 211720 KB n=100
6 Correct 190 ms 211624 KB n=100
7 Correct 204 ms 211640 KB n=100
8 Correct 200 ms 211628 KB n=100
9 Correct 186 ms 211648 KB n=100
10 Correct 211 ms 211724 KB n=100
11 Correct 197 ms 211684 KB n=100
12 Correct 212 ms 211684 KB n=100
13 Correct 184 ms 211608 KB n=100
14 Correct 199 ms 211648 KB n=100
15 Correct 233 ms 211712 KB n=100
16 Correct 216 ms 211696 KB n=100
17 Correct 187 ms 211660 KB n=100
18 Correct 182 ms 211692 KB n=100
19 Correct 172 ms 211740 KB n=100
20 Correct 181 ms 211604 KB n=100
21 Correct 173 ms 211652 KB n=100
22 Correct 171 ms 211668 KB n=100
23 Correct 177 ms 211700 KB n=100
24 Correct 188 ms 211716 KB n=100
25 Correct 172 ms 211624 KB n=100
26 Correct 166 ms 211672 KB n=12
27 Correct 175 ms 211700 KB n=100
28 Correct 184 ms 211864 KB n=500
29 Correct 198 ms 211856 KB n=500
30 Correct 175 ms 211960 KB n=500
31 Correct 210 ms 212012 KB n=500
32 Correct 193 ms 211856 KB n=500
33 Correct 188 ms 211900 KB n=500
34 Correct 178 ms 211936 KB n=500
35 Correct 176 ms 211968 KB n=500
36 Correct 167 ms 211840 KB n=500
37 Correct 181 ms 212040 KB n=500
38 Correct 165 ms 211920 KB n=500
39 Correct 167 ms 211988 KB n=500
40 Correct 168 ms 212052 KB n=500
41 Correct 168 ms 212024 KB n=500
42 Correct 167 ms 211864 KB n=500
43 Correct 168 ms 211860 KB n=500
44 Correct 163 ms 212036 KB n=500
45 Correct 166 ms 211844 KB n=500
46 Correct 171 ms 211944 KB n=500
47 Correct 163 ms 212060 KB n=500
48 Correct 164 ms 211848 KB n=500
49 Correct 172 ms 211852 KB n=500
50 Correct 167 ms 211820 KB n=500
51 Correct 168 ms 211912 KB n=500
52 Correct 166 ms 211948 KB n=500
53 Correct 176 ms 211908 KB n=500
54 Correct 164 ms 211944 KB n=500
55 Correct 180 ms 211768 KB n=278
56 Correct 177 ms 212052 KB n=500
57 Correct 173 ms 211916 KB n=500
58 Correct 211 ms 211852 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 191 ms 211612 KB n=5
2 Correct 185 ms 211784 KB n=100
3 Correct 212 ms 211680 KB n=100
4 Correct 207 ms 211716 KB n=100
5 Correct 210 ms 211720 KB n=100
6 Correct 190 ms 211624 KB n=100
7 Correct 204 ms 211640 KB n=100
8 Correct 200 ms 211628 KB n=100
9 Correct 186 ms 211648 KB n=100
10 Correct 211 ms 211724 KB n=100
11 Correct 197 ms 211684 KB n=100
12 Correct 212 ms 211684 KB n=100
13 Correct 184 ms 211608 KB n=100
14 Correct 199 ms 211648 KB n=100
15 Correct 233 ms 211712 KB n=100
16 Correct 216 ms 211696 KB n=100
17 Correct 187 ms 211660 KB n=100
18 Correct 182 ms 211692 KB n=100
19 Correct 172 ms 211740 KB n=100
20 Correct 181 ms 211604 KB n=100
21 Correct 173 ms 211652 KB n=100
22 Correct 171 ms 211668 KB n=100
23 Correct 177 ms 211700 KB n=100
24 Correct 188 ms 211716 KB n=100
25 Correct 172 ms 211624 KB n=100
26 Correct 166 ms 211672 KB n=12
27 Correct 175 ms 211700 KB n=100
28 Correct 184 ms 211864 KB n=500
29 Correct 198 ms 211856 KB n=500
30 Correct 175 ms 211960 KB n=500
31 Correct 210 ms 212012 KB n=500
32 Correct 193 ms 211856 KB n=500
33 Correct 188 ms 211900 KB n=500
34 Correct 178 ms 211936 KB n=500
35 Correct 176 ms 211968 KB n=500
36 Correct 167 ms 211840 KB n=500
37 Correct 181 ms 212040 KB n=500
38 Correct 165 ms 211920 KB n=500
39 Correct 167 ms 211988 KB n=500
40 Correct 168 ms 212052 KB n=500
41 Correct 168 ms 212024 KB n=500
42 Correct 167 ms 211864 KB n=500
43 Correct 168 ms 211860 KB n=500
44 Correct 163 ms 212036 KB n=500
45 Correct 166 ms 211844 KB n=500
46 Correct 171 ms 211944 KB n=500
47 Correct 163 ms 212060 KB n=500
48 Correct 164 ms 211848 KB n=500
49 Correct 172 ms 211852 KB n=500
50 Correct 167 ms 211820 KB n=500
51 Correct 168 ms 211912 KB n=500
52 Correct 166 ms 211948 KB n=500
53 Correct 176 ms 211908 KB n=500
54 Correct 164 ms 211944 KB n=500
55 Correct 180 ms 211768 KB n=278
56 Correct 177 ms 212052 KB n=500
57 Correct 173 ms 211916 KB n=500
58 Correct 211 ms 211852 KB n=500
59 Correct 178 ms 212736 KB n=2000
60 Correct 171 ms 212752 KB n=2000
61 Correct 170 ms 212760 KB n=2000
62 Correct 166 ms 212676 KB n=2000
63 Correct 167 ms 212696 KB n=2000
64 Correct 177 ms 212692 KB n=2000
65 Correct 167 ms 212684 KB n=2000
66 Correct 168 ms 212732 KB n=2000
67 Correct 175 ms 212676 KB n=2000
68 Correct 180 ms 212720 KB n=2000
69 Correct 184 ms 212664 KB n=2000
70 Correct 166 ms 212820 KB n=2000
71 Correct 184 ms 212644 KB n=2000
72 Correct 164 ms 212716 KB n=2000
73 Correct 171 ms 212724 KB n=2000
74 Correct 170 ms 212688 KB n=1844
75 Correct 173 ms 212688 KB n=2000
76 Correct 174 ms 212684 KB n=2000
77 Correct 186 ms 212724 KB n=2000
78 Correct 171 ms 212804 KB n=2000
79 Correct 178 ms 212656 KB n=2000
80 Correct 190 ms 212792 KB n=2000
81 Correct 198 ms 212684 KB n=2000
82 Correct 182 ms 212676 KB n=2000
83 Correct 179 ms 212716 KB n=2000
84 Correct 172 ms 212676 KB n=2000
85 Correct 165 ms 212716 KB n=2000
86 Correct 168 ms 212760 KB n=2000
87 Correct 166 ms 212756 KB n=2000
88 Correct 180 ms 212760 KB n=2000
89 Correct 168 ms 212772 KB n=2000
90 Correct 165 ms 212804 KB n=2000
91 Correct 166 ms 212696 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 191 ms 211612 KB n=5
2 Correct 185 ms 211784 KB n=100
3 Correct 212 ms 211680 KB n=100
4 Correct 207 ms 211716 KB n=100
5 Correct 210 ms 211720 KB n=100
6 Correct 190 ms 211624 KB n=100
7 Correct 204 ms 211640 KB n=100
8 Correct 200 ms 211628 KB n=100
9 Correct 186 ms 211648 KB n=100
10 Correct 211 ms 211724 KB n=100
11 Correct 197 ms 211684 KB n=100
12 Correct 212 ms 211684 KB n=100
13 Correct 184 ms 211608 KB n=100
14 Correct 199 ms 211648 KB n=100
15 Correct 233 ms 211712 KB n=100
16 Correct 216 ms 211696 KB n=100
17 Correct 187 ms 211660 KB n=100
18 Correct 182 ms 211692 KB n=100
19 Correct 172 ms 211740 KB n=100
20 Correct 181 ms 211604 KB n=100
21 Correct 173 ms 211652 KB n=100
22 Correct 171 ms 211668 KB n=100
23 Correct 177 ms 211700 KB n=100
24 Correct 188 ms 211716 KB n=100
25 Correct 172 ms 211624 KB n=100
26 Correct 166 ms 211672 KB n=12
27 Correct 175 ms 211700 KB n=100
28 Correct 184 ms 211864 KB n=500
29 Correct 198 ms 211856 KB n=500
30 Correct 175 ms 211960 KB n=500
31 Correct 210 ms 212012 KB n=500
32 Correct 193 ms 211856 KB n=500
33 Correct 188 ms 211900 KB n=500
34 Correct 178 ms 211936 KB n=500
35 Correct 176 ms 211968 KB n=500
36 Correct 167 ms 211840 KB n=500
37 Correct 181 ms 212040 KB n=500
38 Correct 165 ms 211920 KB n=500
39 Correct 167 ms 211988 KB n=500
40 Correct 168 ms 212052 KB n=500
41 Correct 168 ms 212024 KB n=500
42 Correct 167 ms 211864 KB n=500
43 Correct 168 ms 211860 KB n=500
44 Correct 163 ms 212036 KB n=500
45 Correct 166 ms 211844 KB n=500
46 Correct 171 ms 211944 KB n=500
47 Correct 163 ms 212060 KB n=500
48 Correct 164 ms 211848 KB n=500
49 Correct 172 ms 211852 KB n=500
50 Correct 167 ms 211820 KB n=500
51 Correct 168 ms 211912 KB n=500
52 Correct 166 ms 211948 KB n=500
53 Correct 176 ms 211908 KB n=500
54 Correct 164 ms 211944 KB n=500
55 Correct 180 ms 211768 KB n=278
56 Correct 177 ms 212052 KB n=500
57 Correct 173 ms 211916 KB n=500
58 Correct 211 ms 211852 KB n=500
59 Correct 178 ms 212736 KB n=2000
60 Correct 171 ms 212752 KB n=2000
61 Correct 170 ms 212760 KB n=2000
62 Correct 166 ms 212676 KB n=2000
63 Correct 167 ms 212696 KB n=2000
64 Correct 177 ms 212692 KB n=2000
65 Correct 167 ms 212684 KB n=2000
66 Correct 168 ms 212732 KB n=2000
67 Correct 175 ms 212676 KB n=2000
68 Correct 180 ms 212720 KB n=2000
69 Correct 184 ms 212664 KB n=2000
70 Correct 166 ms 212820 KB n=2000
71 Correct 184 ms 212644 KB n=2000
72 Correct 164 ms 212716 KB n=2000
73 Correct 171 ms 212724 KB n=2000
74 Correct 170 ms 212688 KB n=1844
75 Correct 173 ms 212688 KB n=2000
76 Correct 174 ms 212684 KB n=2000
77 Correct 186 ms 212724 KB n=2000
78 Correct 171 ms 212804 KB n=2000
79 Correct 178 ms 212656 KB n=2000
80 Correct 190 ms 212792 KB n=2000
81 Correct 198 ms 212684 KB n=2000
82 Correct 182 ms 212676 KB n=2000
83 Correct 179 ms 212716 KB n=2000
84 Correct 172 ms 212676 KB n=2000
85 Correct 165 ms 212716 KB n=2000
86 Correct 168 ms 212760 KB n=2000
87 Correct 166 ms 212756 KB n=2000
88 Correct 180 ms 212760 KB n=2000
89 Correct 168 ms 212772 KB n=2000
90 Correct 165 ms 212804 KB n=2000
91 Correct 166 ms 212696 KB n=2000
92 Runtime error 269 ms 262148 KB Execution killed with signal 9
93 Halted 0 ms 0 KB -