Submission #495862

# Submission time Handle Problem Language Result Execution time Memory
495862 2021-12-20T06:36:20 Z ergagan Birthday gift (IZhO18_treearray) C++17
56 / 100
271 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 < 25; 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 = 24; 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 184 ms 211652 KB n=5
2 Correct 164 ms 211772 KB n=100
3 Correct 165 ms 211652 KB n=100
4 Correct 167 ms 211700 KB n=100
5 Correct 161 ms 211652 KB n=100
6 Correct 169 ms 211620 KB n=100
7 Correct 169 ms 211716 KB n=100
8 Correct 170 ms 211724 KB n=100
9 Correct 163 ms 211668 KB n=100
10 Correct 164 ms 211908 KB n=100
11 Correct 166 ms 211932 KB n=100
12 Correct 167 ms 211780 KB n=100
13 Correct 161 ms 211716 KB n=100
14 Correct 181 ms 211660 KB n=100
15 Correct 164 ms 211644 KB n=100
16 Correct 165 ms 211736 KB n=100
17 Correct 174 ms 211656 KB n=100
18 Correct 169 ms 211624 KB n=100
19 Correct 162 ms 211668 KB n=100
20 Correct 162 ms 211640 KB n=100
21 Correct 166 ms 211836 KB n=100
22 Correct 174 ms 211668 KB n=100
23 Correct 176 ms 211660 KB n=100
24 Correct 167 ms 211644 KB n=100
25 Correct 168 ms 211716 KB n=100
26 Correct 173 ms 211652 KB n=12
27 Correct 167 ms 211624 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 184 ms 211652 KB n=5
2 Correct 164 ms 211772 KB n=100
3 Correct 165 ms 211652 KB n=100
4 Correct 167 ms 211700 KB n=100
5 Correct 161 ms 211652 KB n=100
6 Correct 169 ms 211620 KB n=100
7 Correct 169 ms 211716 KB n=100
8 Correct 170 ms 211724 KB n=100
9 Correct 163 ms 211668 KB n=100
10 Correct 164 ms 211908 KB n=100
11 Correct 166 ms 211932 KB n=100
12 Correct 167 ms 211780 KB n=100
13 Correct 161 ms 211716 KB n=100
14 Correct 181 ms 211660 KB n=100
15 Correct 164 ms 211644 KB n=100
16 Correct 165 ms 211736 KB n=100
17 Correct 174 ms 211656 KB n=100
18 Correct 169 ms 211624 KB n=100
19 Correct 162 ms 211668 KB n=100
20 Correct 162 ms 211640 KB n=100
21 Correct 166 ms 211836 KB n=100
22 Correct 174 ms 211668 KB n=100
23 Correct 176 ms 211660 KB n=100
24 Correct 167 ms 211644 KB n=100
25 Correct 168 ms 211716 KB n=100
26 Correct 173 ms 211652 KB n=12
27 Correct 167 ms 211624 KB n=100
28 Correct 171 ms 211908 KB n=500
29 Correct 176 ms 211948 KB n=500
30 Correct 165 ms 211912 KB n=500
31 Correct 171 ms 211940 KB n=500
32 Correct 175 ms 211892 KB n=500
33 Correct 166 ms 211908 KB n=500
34 Correct 172 ms 211936 KB n=500
35 Correct 166 ms 211908 KB n=500
36 Correct 164 ms 211836 KB n=500
37 Correct 175 ms 211940 KB n=500
38 Correct 163 ms 211908 KB n=500
39 Correct 169 ms 211908 KB n=500
40 Correct 161 ms 211832 KB n=500
41 Correct 165 ms 211860 KB n=500
42 Correct 168 ms 211856 KB n=500
43 Correct 169 ms 212048 KB n=500
44 Correct 163 ms 211872 KB n=500
45 Correct 163 ms 211904 KB n=500
46 Correct 176 ms 211888 KB n=500
47 Correct 161 ms 211860 KB n=500
48 Correct 174 ms 211820 KB n=500
49 Correct 175 ms 211912 KB n=500
50 Correct 163 ms 211940 KB n=500
51 Correct 176 ms 211900 KB n=500
52 Correct 167 ms 211840 KB n=500
53 Correct 165 ms 212240 KB n=500
54 Correct 159 ms 211864 KB n=500
55 Correct 162 ms 211780 KB n=278
56 Correct 161 ms 211976 KB n=500
57 Correct 161 ms 211904 KB n=500
58 Correct 170 ms 211868 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 184 ms 211652 KB n=5
2 Correct 164 ms 211772 KB n=100
3 Correct 165 ms 211652 KB n=100
4 Correct 167 ms 211700 KB n=100
5 Correct 161 ms 211652 KB n=100
6 Correct 169 ms 211620 KB n=100
7 Correct 169 ms 211716 KB n=100
8 Correct 170 ms 211724 KB n=100
9 Correct 163 ms 211668 KB n=100
10 Correct 164 ms 211908 KB n=100
11 Correct 166 ms 211932 KB n=100
12 Correct 167 ms 211780 KB n=100
13 Correct 161 ms 211716 KB n=100
14 Correct 181 ms 211660 KB n=100
15 Correct 164 ms 211644 KB n=100
16 Correct 165 ms 211736 KB n=100
17 Correct 174 ms 211656 KB n=100
18 Correct 169 ms 211624 KB n=100
19 Correct 162 ms 211668 KB n=100
20 Correct 162 ms 211640 KB n=100
21 Correct 166 ms 211836 KB n=100
22 Correct 174 ms 211668 KB n=100
23 Correct 176 ms 211660 KB n=100
24 Correct 167 ms 211644 KB n=100
25 Correct 168 ms 211716 KB n=100
26 Correct 173 ms 211652 KB n=12
27 Correct 167 ms 211624 KB n=100
28 Correct 171 ms 211908 KB n=500
29 Correct 176 ms 211948 KB n=500
30 Correct 165 ms 211912 KB n=500
31 Correct 171 ms 211940 KB n=500
32 Correct 175 ms 211892 KB n=500
33 Correct 166 ms 211908 KB n=500
34 Correct 172 ms 211936 KB n=500
35 Correct 166 ms 211908 KB n=500
36 Correct 164 ms 211836 KB n=500
37 Correct 175 ms 211940 KB n=500
38 Correct 163 ms 211908 KB n=500
39 Correct 169 ms 211908 KB n=500
40 Correct 161 ms 211832 KB n=500
41 Correct 165 ms 211860 KB n=500
42 Correct 168 ms 211856 KB n=500
43 Correct 169 ms 212048 KB n=500
44 Correct 163 ms 211872 KB n=500
45 Correct 163 ms 211904 KB n=500
46 Correct 176 ms 211888 KB n=500
47 Correct 161 ms 211860 KB n=500
48 Correct 174 ms 211820 KB n=500
49 Correct 175 ms 211912 KB n=500
50 Correct 163 ms 211940 KB n=500
51 Correct 176 ms 211900 KB n=500
52 Correct 167 ms 211840 KB n=500
53 Correct 165 ms 212240 KB n=500
54 Correct 159 ms 211864 KB n=500
55 Correct 162 ms 211780 KB n=278
56 Correct 161 ms 211976 KB n=500
57 Correct 161 ms 211904 KB n=500
58 Correct 170 ms 211868 KB n=500
59 Correct 170 ms 212856 KB n=2000
60 Correct 170 ms 212892 KB n=2000
61 Correct 164 ms 212676 KB n=2000
62 Correct 181 ms 212652 KB n=2000
63 Correct 177 ms 212676 KB n=2000
64 Correct 176 ms 212776 KB n=2000
65 Correct 168 ms 212760 KB n=2000
66 Correct 229 ms 212712 KB n=2000
67 Correct 170 ms 212640 KB n=2000
68 Correct 178 ms 212760 KB n=2000
69 Correct 178 ms 212676 KB n=2000
70 Correct 179 ms 212660 KB n=2000
71 Correct 176 ms 212676 KB n=2000
72 Correct 195 ms 212732 KB n=2000
73 Correct 175 ms 212744 KB n=2000
74 Correct 185 ms 212600 KB n=1844
75 Correct 172 ms 212716 KB n=2000
76 Correct 173 ms 212676 KB n=2000
77 Correct 184 ms 212720 KB n=2000
78 Correct 171 ms 212676 KB n=2000
79 Correct 171 ms 212816 KB n=2000
80 Correct 169 ms 212736 KB n=2000
81 Correct 169 ms 212708 KB n=2000
82 Correct 168 ms 212732 KB n=2000
83 Correct 165 ms 212764 KB n=2000
84 Correct 169 ms 212676 KB n=2000
85 Correct 175 ms 212756 KB n=2000
86 Correct 167 ms 212720 KB n=2000
87 Correct 169 ms 212636 KB n=2000
88 Correct 173 ms 212784 KB n=2000
89 Correct 170 ms 212676 KB n=2000
90 Correct 164 ms 212780 KB n=2000
91 Correct 163 ms 212760 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 184 ms 211652 KB n=5
2 Correct 164 ms 211772 KB n=100
3 Correct 165 ms 211652 KB n=100
4 Correct 167 ms 211700 KB n=100
5 Correct 161 ms 211652 KB n=100
6 Correct 169 ms 211620 KB n=100
7 Correct 169 ms 211716 KB n=100
8 Correct 170 ms 211724 KB n=100
9 Correct 163 ms 211668 KB n=100
10 Correct 164 ms 211908 KB n=100
11 Correct 166 ms 211932 KB n=100
12 Correct 167 ms 211780 KB n=100
13 Correct 161 ms 211716 KB n=100
14 Correct 181 ms 211660 KB n=100
15 Correct 164 ms 211644 KB n=100
16 Correct 165 ms 211736 KB n=100
17 Correct 174 ms 211656 KB n=100
18 Correct 169 ms 211624 KB n=100
19 Correct 162 ms 211668 KB n=100
20 Correct 162 ms 211640 KB n=100
21 Correct 166 ms 211836 KB n=100
22 Correct 174 ms 211668 KB n=100
23 Correct 176 ms 211660 KB n=100
24 Correct 167 ms 211644 KB n=100
25 Correct 168 ms 211716 KB n=100
26 Correct 173 ms 211652 KB n=12
27 Correct 167 ms 211624 KB n=100
28 Correct 171 ms 211908 KB n=500
29 Correct 176 ms 211948 KB n=500
30 Correct 165 ms 211912 KB n=500
31 Correct 171 ms 211940 KB n=500
32 Correct 175 ms 211892 KB n=500
33 Correct 166 ms 211908 KB n=500
34 Correct 172 ms 211936 KB n=500
35 Correct 166 ms 211908 KB n=500
36 Correct 164 ms 211836 KB n=500
37 Correct 175 ms 211940 KB n=500
38 Correct 163 ms 211908 KB n=500
39 Correct 169 ms 211908 KB n=500
40 Correct 161 ms 211832 KB n=500
41 Correct 165 ms 211860 KB n=500
42 Correct 168 ms 211856 KB n=500
43 Correct 169 ms 212048 KB n=500
44 Correct 163 ms 211872 KB n=500
45 Correct 163 ms 211904 KB n=500
46 Correct 176 ms 211888 KB n=500
47 Correct 161 ms 211860 KB n=500
48 Correct 174 ms 211820 KB n=500
49 Correct 175 ms 211912 KB n=500
50 Correct 163 ms 211940 KB n=500
51 Correct 176 ms 211900 KB n=500
52 Correct 167 ms 211840 KB n=500
53 Correct 165 ms 212240 KB n=500
54 Correct 159 ms 211864 KB n=500
55 Correct 162 ms 211780 KB n=278
56 Correct 161 ms 211976 KB n=500
57 Correct 161 ms 211904 KB n=500
58 Correct 170 ms 211868 KB n=500
59 Correct 170 ms 212856 KB n=2000
60 Correct 170 ms 212892 KB n=2000
61 Correct 164 ms 212676 KB n=2000
62 Correct 181 ms 212652 KB n=2000
63 Correct 177 ms 212676 KB n=2000
64 Correct 176 ms 212776 KB n=2000
65 Correct 168 ms 212760 KB n=2000
66 Correct 229 ms 212712 KB n=2000
67 Correct 170 ms 212640 KB n=2000
68 Correct 178 ms 212760 KB n=2000
69 Correct 178 ms 212676 KB n=2000
70 Correct 179 ms 212660 KB n=2000
71 Correct 176 ms 212676 KB n=2000
72 Correct 195 ms 212732 KB n=2000
73 Correct 175 ms 212744 KB n=2000
74 Correct 185 ms 212600 KB n=1844
75 Correct 172 ms 212716 KB n=2000
76 Correct 173 ms 212676 KB n=2000
77 Correct 184 ms 212720 KB n=2000
78 Correct 171 ms 212676 KB n=2000
79 Correct 171 ms 212816 KB n=2000
80 Correct 169 ms 212736 KB n=2000
81 Correct 169 ms 212708 KB n=2000
82 Correct 168 ms 212732 KB n=2000
83 Correct 165 ms 212764 KB n=2000
84 Correct 169 ms 212676 KB n=2000
85 Correct 175 ms 212756 KB n=2000
86 Correct 167 ms 212720 KB n=2000
87 Correct 169 ms 212636 KB n=2000
88 Correct 173 ms 212784 KB n=2000
89 Correct 170 ms 212676 KB n=2000
90 Correct 164 ms 212780 KB n=2000
91 Correct 163 ms 212760 KB n=2000
92 Runtime error 271 ms 262148 KB Execution killed with signal 9
93 Halted 0 ms 0 KB -