답안 #157057

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
157057 2019-10-09T10:52:49 Z dandrozavr Birthday gift (IZhO18_treearray) C++14
100 / 100
1243 ms 77788 KB
/*
Uruchamiamy samolot zwiadowczy ( + 500% do wzlamaniej )

/▄/  /█/  /◐/   /▐/   /▌/ /▀/ /░/ /🔥/   choose  own style!

***IT'S OUR LONG WAY TO THE OIILLLL***

░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░███░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░█▌░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▀██████████████████████████████████████████████████
░░░░░░░░░░░░░░░░░░░░░░░░░░▄▄▄████▄████████ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ █████
░░░░░░░░░░░░░░░░░░░░░░░░░░░▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀█████████▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░◐◐◐█████████▀▀▀▀▀▀🔥░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████████░░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░████████░░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░███████░░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░██████░░░░░░░░░░░░░░░░
░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░█████░░░░░░░░░░░░░░░
*/


//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
//#pragma comment(linker, "/stack:200000000")

#include <bits/stdc++.h>
using namespace std;



#define pb push_back
#define ll long long
#define ld long double
#define fi first
#define se second
#define eb emplace_back
#define pii pair < int , int >
#define pipii pair< int, pair < int , int > >
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());

//#include <ext/pb_ds/detail/standard_policies.hpp>'
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;template <typename T> using ordered_set = tree <T, null_type, less< T >, rb_tree_tag,tree_order_statistics_node_update>;
namespace fastio {template <class T> ostream &operator<<(ostream &os, const vector<T> &container){for (auto &u : container)os << u << " ";return os;}template<class T1, class T2> ostream& operator << (ostream& os, const pair<T1, T2>& p) { return os << p.first << " " << p.second; }template <class T> ostream &operator<<(ostream &os, set<T> const& con) { for (auto &u : con) os << u << " "; return os; }void pr() {}template <typename T, typename... args> void pr(T x, args... tail) { cout << x << " "; pr(tail...);}}using namespace fastio;

const int N = 3e5 + 5;
const int MA = 1e6 + 1;

const int X[4] = {0, 0, 1, -1};
const int Y[4] = {-1, 1, 0, 0};

vector < int > g[N];
int up[N][18], tin[N], tout[N], timer;

void dfs(int v, int pr = 0)
{
    tin[v] = ++timer;
    up[v][0] = pr;
    for (int i = 1; i < 18; ++i)
        up[v][i] = up[up[v][i - 1]][i - 1];
    for (int to : g[v])
    if (to != pr)
    {
        dfs(to, v);
    }
    tout[v] = ++timer;
}

bool upper(int x, int y)
{
    return (tin[x] <= tin[y] && tout[x] >= tout[y]);
}

int LCA(int x, int y)
{
    if (upper(x, y))
        return x;
    if (upper(y, x))
        return y;

    for (int i = 17; i >= 0; --i)
        if (!upper(up[x][i], y))
          x = up[x][i];
    return up[x][0];
}

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    #ifdef Estb_probitie
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif

    int n, m, q;
    cin >> n >> m >> q;

    for (int i = 1; i < n; ++i)
    {
        int x, y;
        cin >> x >> y;
        --x, --y;
        g[x].pb(y);
        g[y].pb(x);
    }

    dfs(0);
    int a[m];

    for (int i = 0; i < m; ++i)
        cin >> a[i], a[i]--;

    set < int > ver[n], pai[n];
    for (int i = 0; i < m; ++i)
    {
        ver[a[i]].insert(i);
        if (i)
            pai[LCA(a[i], a[i - 1])].insert(i - 1);
    }


    while(q--)
    {
        int ty;
        cin >> ty;
        if (ty == 1)
        {
            int pos, v;
            cin >> pos >> v;
            --pos;--v;
            ver[a[pos]].erase(pos);
            if (pos)
                pai[LCA(a[pos], a[pos - 1])].erase(pos - 1);
            if (pos + 1 < m)
                pai[LCA(a[pos], a[pos + 1])].erase(pos);

            a[pos] = v;
            ver[v].insert(pos);
            if (pos)
                pai[LCA(v, a[pos - 1])].insert(pos - 1);
            if (pos + 1 < m)
                pai[LCA(v, a[pos + 1])].insert(pos);
            continue;
        }

        int l, r, v;
        cin >> l >> r >> v;
        --l;--r;--v;
        int f = -2, s = -2;
        auto pp = ver[v].lower_bound(l);
        if (pp != ver[v].end() && (*pp) <= r)
        {
            f = s = (*pp);
        } else
        {
            auto poz = pai[v].lower_bound(l);
            if (poz != pai[v].end() && (*poz) < r)
                f = (*poz), s = (*poz) + 1;
        }
        cout << f + 1 << " " << s + 1 << '\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB n=5
2 Correct 8 ms 7420 KB n=100
3 Correct 8 ms 7424 KB n=100
4 Correct 8 ms 7416 KB n=100
5 Correct 10 ms 7416 KB n=100
6 Correct 10 ms 7416 KB n=100
7 Correct 10 ms 7416 KB n=100
8 Correct 9 ms 7416 KB n=100
9 Correct 9 ms 7416 KB n=100
10 Correct 8 ms 7416 KB n=100
11 Correct 9 ms 7416 KB n=100
12 Correct 9 ms 7416 KB n=100
13 Correct 9 ms 7416 KB n=100
14 Correct 8 ms 7416 KB n=100
15 Correct 9 ms 7416 KB n=100
16 Correct 8 ms 7420 KB n=100
17 Correct 8 ms 7416 KB n=100
18 Correct 8 ms 7416 KB n=100
19 Correct 8 ms 7416 KB n=100
20 Correct 8 ms 7416 KB n=100
21 Correct 9 ms 7416 KB n=100
22 Correct 8 ms 7420 KB n=100
23 Correct 8 ms 7416 KB n=100
24 Correct 9 ms 7416 KB n=100
25 Correct 9 ms 7416 KB n=100
26 Correct 9 ms 7416 KB n=12
27 Correct 8 ms 7416 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB n=5
2 Correct 8 ms 7420 KB n=100
3 Correct 8 ms 7424 KB n=100
4 Correct 8 ms 7416 KB n=100
5 Correct 10 ms 7416 KB n=100
6 Correct 10 ms 7416 KB n=100
7 Correct 10 ms 7416 KB n=100
8 Correct 9 ms 7416 KB n=100
9 Correct 9 ms 7416 KB n=100
10 Correct 8 ms 7416 KB n=100
11 Correct 9 ms 7416 KB n=100
12 Correct 9 ms 7416 KB n=100
13 Correct 9 ms 7416 KB n=100
14 Correct 8 ms 7416 KB n=100
15 Correct 9 ms 7416 KB n=100
16 Correct 8 ms 7420 KB n=100
17 Correct 8 ms 7416 KB n=100
18 Correct 8 ms 7416 KB n=100
19 Correct 8 ms 7416 KB n=100
20 Correct 8 ms 7416 KB n=100
21 Correct 9 ms 7416 KB n=100
22 Correct 8 ms 7420 KB n=100
23 Correct 8 ms 7416 KB n=100
24 Correct 9 ms 7416 KB n=100
25 Correct 9 ms 7416 KB n=100
26 Correct 9 ms 7416 KB n=12
27 Correct 8 ms 7416 KB n=100
28 Correct 9 ms 7544 KB n=500
29 Correct 9 ms 7544 KB n=500
30 Correct 10 ms 7672 KB n=500
31 Correct 9 ms 7544 KB n=500
32 Correct 9 ms 7544 KB n=500
33 Correct 9 ms 7544 KB n=500
34 Correct 9 ms 7544 KB n=500
35 Correct 9 ms 7544 KB n=500
36 Correct 9 ms 7544 KB n=500
37 Correct 9 ms 7544 KB n=500
38 Correct 9 ms 7544 KB n=500
39 Correct 9 ms 7544 KB n=500
40 Correct 9 ms 7544 KB n=500
41 Correct 9 ms 7544 KB n=500
42 Correct 9 ms 7544 KB n=500
43 Correct 9 ms 7544 KB n=500
44 Correct 9 ms 7544 KB n=500
45 Correct 9 ms 7544 KB n=500
46 Correct 11 ms 7544 KB n=500
47 Correct 11 ms 7544 KB n=500
48 Correct 11 ms 7544 KB n=500
49 Correct 10 ms 7544 KB n=500
50 Correct 12 ms 7544 KB n=500
51 Correct 9 ms 7544 KB n=500
52 Correct 20 ms 7544 KB n=500
53 Correct 11 ms 7544 KB n=500
54 Correct 9 ms 7544 KB n=500
55 Correct 11 ms 7544 KB n=278
56 Correct 9 ms 7544 KB n=500
57 Correct 11 ms 7544 KB n=500
58 Correct 9 ms 7544 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB n=5
2 Correct 8 ms 7420 KB n=100
3 Correct 8 ms 7424 KB n=100
4 Correct 8 ms 7416 KB n=100
5 Correct 10 ms 7416 KB n=100
6 Correct 10 ms 7416 KB n=100
7 Correct 10 ms 7416 KB n=100
8 Correct 9 ms 7416 KB n=100
9 Correct 9 ms 7416 KB n=100
10 Correct 8 ms 7416 KB n=100
11 Correct 9 ms 7416 KB n=100
12 Correct 9 ms 7416 KB n=100
13 Correct 9 ms 7416 KB n=100
14 Correct 8 ms 7416 KB n=100
15 Correct 9 ms 7416 KB n=100
16 Correct 8 ms 7420 KB n=100
17 Correct 8 ms 7416 KB n=100
18 Correct 8 ms 7416 KB n=100
19 Correct 8 ms 7416 KB n=100
20 Correct 8 ms 7416 KB n=100
21 Correct 9 ms 7416 KB n=100
22 Correct 8 ms 7420 KB n=100
23 Correct 8 ms 7416 KB n=100
24 Correct 9 ms 7416 KB n=100
25 Correct 9 ms 7416 KB n=100
26 Correct 9 ms 7416 KB n=12
27 Correct 8 ms 7416 KB n=100
28 Correct 9 ms 7544 KB n=500
29 Correct 9 ms 7544 KB n=500
30 Correct 10 ms 7672 KB n=500
31 Correct 9 ms 7544 KB n=500
32 Correct 9 ms 7544 KB n=500
33 Correct 9 ms 7544 KB n=500
34 Correct 9 ms 7544 KB n=500
35 Correct 9 ms 7544 KB n=500
36 Correct 9 ms 7544 KB n=500
37 Correct 9 ms 7544 KB n=500
38 Correct 9 ms 7544 KB n=500
39 Correct 9 ms 7544 KB n=500
40 Correct 9 ms 7544 KB n=500
41 Correct 9 ms 7544 KB n=500
42 Correct 9 ms 7544 KB n=500
43 Correct 9 ms 7544 KB n=500
44 Correct 9 ms 7544 KB n=500
45 Correct 9 ms 7544 KB n=500
46 Correct 11 ms 7544 KB n=500
47 Correct 11 ms 7544 KB n=500
48 Correct 11 ms 7544 KB n=500
49 Correct 10 ms 7544 KB n=500
50 Correct 12 ms 7544 KB n=500
51 Correct 9 ms 7544 KB n=500
52 Correct 20 ms 7544 KB n=500
53 Correct 11 ms 7544 KB n=500
54 Correct 9 ms 7544 KB n=500
55 Correct 11 ms 7544 KB n=278
56 Correct 9 ms 7544 KB n=500
57 Correct 11 ms 7544 KB n=500
58 Correct 9 ms 7544 KB n=500
59 Correct 13 ms 8056 KB n=2000
60 Correct 12 ms 8088 KB n=2000
61 Correct 12 ms 8100 KB n=2000
62 Correct 12 ms 8056 KB n=2000
63 Correct 13 ms 8056 KB n=2000
64 Correct 13 ms 8056 KB n=2000
65 Correct 13 ms 8056 KB n=2000
66 Correct 12 ms 8056 KB n=2000
67 Correct 13 ms 8068 KB n=2000
68 Correct 12 ms 8056 KB n=2000
69 Correct 12 ms 8056 KB n=2000
70 Correct 11 ms 8056 KB n=2000
71 Correct 11 ms 8056 KB n=2000
72 Correct 11 ms 8056 KB n=2000
73 Correct 11 ms 8056 KB n=2000
74 Correct 12 ms 8056 KB n=1844
75 Correct 13 ms 8056 KB n=2000
76 Correct 14 ms 8056 KB n=2000
77 Correct 13 ms 8056 KB n=2000
78 Correct 13 ms 8056 KB n=2000
79 Correct 13 ms 8056 KB n=2000
80 Correct 12 ms 8056 KB n=2000
81 Correct 14 ms 8056 KB n=2000
82 Correct 13 ms 8056 KB n=2000
83 Correct 12 ms 8056 KB n=2000
84 Correct 13 ms 8056 KB n=2000
85 Correct 13 ms 8056 KB n=2000
86 Correct 15 ms 8088 KB n=2000
87 Correct 13 ms 8056 KB n=2000
88 Correct 24 ms 8056 KB n=2000
89 Correct 12 ms 8056 KB n=2000
90 Correct 12 ms 8056 KB n=2000
91 Correct 12 ms 8060 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 7416 KB n=5
2 Correct 8 ms 7420 KB n=100
3 Correct 8 ms 7424 KB n=100
4 Correct 8 ms 7416 KB n=100
5 Correct 10 ms 7416 KB n=100
6 Correct 10 ms 7416 KB n=100
7 Correct 10 ms 7416 KB n=100
8 Correct 9 ms 7416 KB n=100
9 Correct 9 ms 7416 KB n=100
10 Correct 8 ms 7416 KB n=100
11 Correct 9 ms 7416 KB n=100
12 Correct 9 ms 7416 KB n=100
13 Correct 9 ms 7416 KB n=100
14 Correct 8 ms 7416 KB n=100
15 Correct 9 ms 7416 KB n=100
16 Correct 8 ms 7420 KB n=100
17 Correct 8 ms 7416 KB n=100
18 Correct 8 ms 7416 KB n=100
19 Correct 8 ms 7416 KB n=100
20 Correct 8 ms 7416 KB n=100
21 Correct 9 ms 7416 KB n=100
22 Correct 8 ms 7420 KB n=100
23 Correct 8 ms 7416 KB n=100
24 Correct 9 ms 7416 KB n=100
25 Correct 9 ms 7416 KB n=100
26 Correct 9 ms 7416 KB n=12
27 Correct 8 ms 7416 KB n=100
28 Correct 9 ms 7544 KB n=500
29 Correct 9 ms 7544 KB n=500
30 Correct 10 ms 7672 KB n=500
31 Correct 9 ms 7544 KB n=500
32 Correct 9 ms 7544 KB n=500
33 Correct 9 ms 7544 KB n=500
34 Correct 9 ms 7544 KB n=500
35 Correct 9 ms 7544 KB n=500
36 Correct 9 ms 7544 KB n=500
37 Correct 9 ms 7544 KB n=500
38 Correct 9 ms 7544 KB n=500
39 Correct 9 ms 7544 KB n=500
40 Correct 9 ms 7544 KB n=500
41 Correct 9 ms 7544 KB n=500
42 Correct 9 ms 7544 KB n=500
43 Correct 9 ms 7544 KB n=500
44 Correct 9 ms 7544 KB n=500
45 Correct 9 ms 7544 KB n=500
46 Correct 11 ms 7544 KB n=500
47 Correct 11 ms 7544 KB n=500
48 Correct 11 ms 7544 KB n=500
49 Correct 10 ms 7544 KB n=500
50 Correct 12 ms 7544 KB n=500
51 Correct 9 ms 7544 KB n=500
52 Correct 20 ms 7544 KB n=500
53 Correct 11 ms 7544 KB n=500
54 Correct 9 ms 7544 KB n=500
55 Correct 11 ms 7544 KB n=278
56 Correct 9 ms 7544 KB n=500
57 Correct 11 ms 7544 KB n=500
58 Correct 9 ms 7544 KB n=500
59 Correct 13 ms 8056 KB n=2000
60 Correct 12 ms 8088 KB n=2000
61 Correct 12 ms 8100 KB n=2000
62 Correct 12 ms 8056 KB n=2000
63 Correct 13 ms 8056 KB n=2000
64 Correct 13 ms 8056 KB n=2000
65 Correct 13 ms 8056 KB n=2000
66 Correct 12 ms 8056 KB n=2000
67 Correct 13 ms 8068 KB n=2000
68 Correct 12 ms 8056 KB n=2000
69 Correct 12 ms 8056 KB n=2000
70 Correct 11 ms 8056 KB n=2000
71 Correct 11 ms 8056 KB n=2000
72 Correct 11 ms 8056 KB n=2000
73 Correct 11 ms 8056 KB n=2000
74 Correct 12 ms 8056 KB n=1844
75 Correct 13 ms 8056 KB n=2000
76 Correct 14 ms 8056 KB n=2000
77 Correct 13 ms 8056 KB n=2000
78 Correct 13 ms 8056 KB n=2000
79 Correct 13 ms 8056 KB n=2000
80 Correct 12 ms 8056 KB n=2000
81 Correct 14 ms 8056 KB n=2000
82 Correct 13 ms 8056 KB n=2000
83 Correct 12 ms 8056 KB n=2000
84 Correct 13 ms 8056 KB n=2000
85 Correct 13 ms 8056 KB n=2000
86 Correct 15 ms 8088 KB n=2000
87 Correct 13 ms 8056 KB n=2000
88 Correct 24 ms 8056 KB n=2000
89 Correct 12 ms 8056 KB n=2000
90 Correct 12 ms 8056 KB n=2000
91 Correct 12 ms 8060 KB n=2000
92 Correct 1027 ms 76276 KB n=200000
93 Correct 1062 ms 76664 KB n=200000
94 Correct 905 ms 76568 KB n=200000
95 Correct 945 ms 75928 KB n=200000
96 Correct 906 ms 76140 KB n=200000
97 Correct 1042 ms 76612 KB n=200000
98 Correct 1041 ms 76028 KB n=200000
99 Correct 1065 ms 76260 KB n=200000
100 Correct 890 ms 76036 KB n=200000
101 Correct 691 ms 76372 KB n=200000
102 Correct 541 ms 77176 KB n=200000
103 Correct 583 ms 77160 KB n=200000
104 Correct 566 ms 77340 KB n=200000
105 Correct 542 ms 77660 KB n=200000
106 Correct 539 ms 77696 KB n=200000
107 Correct 564 ms 77788 KB n=200000
108 Correct 953 ms 76280 KB n=200000
109 Correct 909 ms 76264 KB n=200000
110 Correct 996 ms 76132 KB n=200000
111 Correct 881 ms 75536 KB n=200000
112 Correct 740 ms 76364 KB n=200000
113 Correct 1161 ms 76576 KB n=200000
114 Correct 1018 ms 75572 KB n=200000
115 Correct 1243 ms 76480 KB n=200000
116 Correct 863 ms 76432 KB n=200000
117 Correct 693 ms 76316 KB n=200000
118 Correct 1155 ms 76340 KB n=200000
119 Correct 859 ms 76108 KB n=200000
120 Correct 659 ms 75484 KB n=200000
121 Correct 636 ms 75172 KB n=200000
122 Correct 625 ms 75576 KB n=200000
123 Correct 566 ms 77484 KB n=200000
124 Correct 190 ms 23672 KB n=25264