답안 #570368

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
570368 2022-05-29T11:20:04 Z Hanksburger Birthday gift (IZhO18_treearray) C++17
100 / 100
1027 ms 84172 KB
#include <bits/stdc++.h>
using namespace std;
int par[200005][20], dep[200005], a[200005];
set<int> r[200005], s[200005];
vector<int> adj[200005];
int lca(int u, int v)
{
    if (dep[u]>dep[v])
        swap(u, v);
    int d=dep[v]-dep[u];
    for (int i=0; i<20; i++)
        if (d&(1<<i))
            v=par[v][i];
    if (u==v)
        return u;
    for (int i=19; i>=0; i--)
    {
        if (par[u][i]!=par[v][i])
        {
            u=par[u][i];
            v=par[v][i];
        }
    }
    return par[u][0];
}
void dfs(int u, int p)
{
    dep[u]=dep[p]+1;
    par[u][0]=p;
    for (int i=1; i<20; i++)
        par[u][i]=par[par[u][i-1]][i-1];
    for (int i=0; i<adj[u].size(); i++)
    {
        int v=adj[u][i];
        if (v!=p)
            dfs(v, u);
    }
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m, q;
    cin >> n >> m >> q;
    for (int i=1; i<n; i++)
    {
        int u, v;
        cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    dfs(1, 1);
    for (int i=1; i<=m; i++)
    {
        cin >> a[i];
        r[a[i]].insert(i);
        if (i>=2)
        {
            s[lca(a[i-1], a[i])].insert(i-1);
//            cout << "s " << lca(a[i-1], a[i]) << " insert " << i-1 << '\n';
        }
    }
    for (int i=0; i<q; i++)
    {
        int t;
        cin >> t;
        if (t==1)
        {
            int pos, u;
            cin >> pos >> u;
            r[a[pos]].erase(pos);
            s[lca(a[pos-1], a[pos])].erase(pos-1);
            s[lca(a[pos], a[pos+1])].erase(pos);
//            cout << "s " << lca(a[pos-1], a[pos]) << " erase " << pos-1 << '\n';
//            cout << "s " << lca(a[pos], a[pos+1]) << " erase " << pos << '\n';
            a[pos]=u;
            r[a[pos]].insert(pos);
            s[lca(a[pos-1], a[pos])].insert(pos-1);
            s[lca(a[pos], a[pos+1])].insert(pos);
//            cout << "s " << lca(a[pos-1], a[pos]) << " insert " << pos-1 << '\n';
//            cout << "s " << lca(a[pos], a[pos+1]) << " insert " << pos << '\n';
        }
        else
        {
            int x, y, u;
            cin >> x >> y >> u;
            auto itr1=r[u].lower_bound(x), itr2=s[u].lower_bound(x);
            if (itr1!=r[u].end() && (*itr1)<=y)
                cout << (*itr1) << ' ' << (*itr1) << '\n';
            else if (itr2!=s[u].end() && (*itr2)<y)
                cout << (*itr2) << ' ' << (*itr2)+1 << '\n';
            else
                cout << -1 << ' ' << -1 << '\n';
        }
    }
    return 0;
}

Compilation message

treearray.cpp: In function 'void dfs(int, int)':
treearray.cpp:32:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |     for (int i=0; i<adj[u].size(); i++)
      |                   ~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n=5
2 Correct 13 ms 23824 KB n=100
3 Correct 12 ms 23820 KB n=100
4 Correct 13 ms 23764 KB n=100
5 Correct 14 ms 23784 KB n=100
6 Correct 13 ms 23764 KB n=100
7 Correct 12 ms 23820 KB n=100
8 Correct 14 ms 23748 KB n=100
9 Correct 13 ms 23820 KB n=100
10 Correct 15 ms 23816 KB n=100
11 Correct 12 ms 23848 KB n=100
12 Correct 12 ms 23836 KB n=100
13 Correct 13 ms 23800 KB n=100
14 Correct 12 ms 23816 KB n=100
15 Correct 12 ms 23828 KB n=100
16 Correct 13 ms 23764 KB n=100
17 Correct 12 ms 23764 KB n=100
18 Correct 12 ms 23832 KB n=100
19 Correct 12 ms 23780 KB n=100
20 Correct 15 ms 23764 KB n=100
21 Correct 13 ms 23764 KB n=100
22 Correct 16 ms 23848 KB n=100
23 Correct 13 ms 23764 KB n=100
24 Correct 13 ms 23804 KB n=100
25 Correct 13 ms 23740 KB n=100
26 Correct 13 ms 23724 KB n=12
27 Correct 13 ms 23844 KB n=100
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n=5
2 Correct 13 ms 23824 KB n=100
3 Correct 12 ms 23820 KB n=100
4 Correct 13 ms 23764 KB n=100
5 Correct 14 ms 23784 KB n=100
6 Correct 13 ms 23764 KB n=100
7 Correct 12 ms 23820 KB n=100
8 Correct 14 ms 23748 KB n=100
9 Correct 13 ms 23820 KB n=100
10 Correct 15 ms 23816 KB n=100
11 Correct 12 ms 23848 KB n=100
12 Correct 12 ms 23836 KB n=100
13 Correct 13 ms 23800 KB n=100
14 Correct 12 ms 23816 KB n=100
15 Correct 12 ms 23828 KB n=100
16 Correct 13 ms 23764 KB n=100
17 Correct 12 ms 23764 KB n=100
18 Correct 12 ms 23832 KB n=100
19 Correct 12 ms 23780 KB n=100
20 Correct 15 ms 23764 KB n=100
21 Correct 13 ms 23764 KB n=100
22 Correct 16 ms 23848 KB n=100
23 Correct 13 ms 23764 KB n=100
24 Correct 13 ms 23804 KB n=100
25 Correct 13 ms 23740 KB n=100
26 Correct 13 ms 23724 KB n=12
27 Correct 13 ms 23844 KB n=100
28 Correct 15 ms 23892 KB n=500
29 Correct 14 ms 24020 KB n=500
30 Correct 14 ms 23892 KB n=500
31 Correct 17 ms 23892 KB n=500
32 Correct 14 ms 23924 KB n=500
33 Correct 13 ms 23892 KB n=500
34 Correct 13 ms 23892 KB n=500
35 Correct 13 ms 23936 KB n=500
36 Correct 13 ms 23892 KB n=500
37 Correct 14 ms 23892 KB n=500
38 Correct 13 ms 23840 KB n=500
39 Correct 14 ms 23936 KB n=500
40 Correct 13 ms 23952 KB n=500
41 Correct 12 ms 23892 KB n=500
42 Correct 14 ms 23892 KB n=500
43 Correct 14 ms 23892 KB n=500
44 Correct 16 ms 23832 KB n=500
45 Correct 13 ms 23952 KB n=500
46 Correct 15 ms 23892 KB n=500
47 Correct 13 ms 23968 KB n=500
48 Correct 15 ms 23852 KB n=500
49 Correct 13 ms 24016 KB n=500
50 Correct 15 ms 23892 KB n=500
51 Correct 13 ms 23892 KB n=500
52 Correct 13 ms 23904 KB n=500
53 Correct 13 ms 23932 KB n=500
54 Correct 13 ms 23892 KB n=500
55 Correct 13 ms 23916 KB n=278
56 Correct 13 ms 23892 KB n=500
57 Correct 13 ms 23848 KB n=500
58 Correct 13 ms 23892 KB n=500
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n=5
2 Correct 13 ms 23824 KB n=100
3 Correct 12 ms 23820 KB n=100
4 Correct 13 ms 23764 KB n=100
5 Correct 14 ms 23784 KB n=100
6 Correct 13 ms 23764 KB n=100
7 Correct 12 ms 23820 KB n=100
8 Correct 14 ms 23748 KB n=100
9 Correct 13 ms 23820 KB n=100
10 Correct 15 ms 23816 KB n=100
11 Correct 12 ms 23848 KB n=100
12 Correct 12 ms 23836 KB n=100
13 Correct 13 ms 23800 KB n=100
14 Correct 12 ms 23816 KB n=100
15 Correct 12 ms 23828 KB n=100
16 Correct 13 ms 23764 KB n=100
17 Correct 12 ms 23764 KB n=100
18 Correct 12 ms 23832 KB n=100
19 Correct 12 ms 23780 KB n=100
20 Correct 15 ms 23764 KB n=100
21 Correct 13 ms 23764 KB n=100
22 Correct 16 ms 23848 KB n=100
23 Correct 13 ms 23764 KB n=100
24 Correct 13 ms 23804 KB n=100
25 Correct 13 ms 23740 KB n=100
26 Correct 13 ms 23724 KB n=12
27 Correct 13 ms 23844 KB n=100
28 Correct 15 ms 23892 KB n=500
29 Correct 14 ms 24020 KB n=500
30 Correct 14 ms 23892 KB n=500
31 Correct 17 ms 23892 KB n=500
32 Correct 14 ms 23924 KB n=500
33 Correct 13 ms 23892 KB n=500
34 Correct 13 ms 23892 KB n=500
35 Correct 13 ms 23936 KB n=500
36 Correct 13 ms 23892 KB n=500
37 Correct 14 ms 23892 KB n=500
38 Correct 13 ms 23840 KB n=500
39 Correct 14 ms 23936 KB n=500
40 Correct 13 ms 23952 KB n=500
41 Correct 12 ms 23892 KB n=500
42 Correct 14 ms 23892 KB n=500
43 Correct 14 ms 23892 KB n=500
44 Correct 16 ms 23832 KB n=500
45 Correct 13 ms 23952 KB n=500
46 Correct 15 ms 23892 KB n=500
47 Correct 13 ms 23968 KB n=500
48 Correct 15 ms 23852 KB n=500
49 Correct 13 ms 24016 KB n=500
50 Correct 15 ms 23892 KB n=500
51 Correct 13 ms 23892 KB n=500
52 Correct 13 ms 23904 KB n=500
53 Correct 13 ms 23932 KB n=500
54 Correct 13 ms 23892 KB n=500
55 Correct 13 ms 23916 KB n=278
56 Correct 13 ms 23892 KB n=500
57 Correct 13 ms 23848 KB n=500
58 Correct 13 ms 23892 KB n=500
59 Correct 15 ms 24216 KB n=2000
60 Correct 15 ms 24404 KB n=2000
61 Correct 15 ms 24348 KB n=2000
62 Correct 16 ms 24276 KB n=2000
63 Correct 17 ms 24284 KB n=2000
64 Correct 17 ms 24328 KB n=2000
65 Correct 16 ms 24276 KB n=2000
66 Correct 15 ms 24344 KB n=2000
67 Correct 17 ms 24216 KB n=2000
68 Correct 15 ms 24320 KB n=2000
69 Correct 14 ms 24296 KB n=2000
70 Correct 14 ms 24276 KB n=2000
71 Correct 15 ms 24276 KB n=2000
72 Correct 18 ms 24220 KB n=2000
73 Correct 19 ms 24296 KB n=2000
74 Correct 17 ms 24216 KB n=1844
75 Correct 15 ms 24256 KB n=2000
76 Correct 17 ms 24288 KB n=2000
77 Correct 18 ms 24220 KB n=2000
78 Correct 17 ms 24200 KB n=2000
79 Correct 16 ms 24276 KB n=2000
80 Correct 15 ms 24268 KB n=2000
81 Correct 16 ms 24208 KB n=2000
82 Correct 16 ms 24276 KB n=2000
83 Correct 16 ms 24276 KB n=2000
84 Correct 20 ms 24276 KB n=2000
85 Correct 16 ms 24344 KB n=2000
86 Correct 16 ms 24344 KB n=2000
87 Correct 16 ms 24232 KB n=2000
88 Correct 15 ms 24404 KB n=2000
89 Correct 16 ms 24372 KB n=2000
90 Correct 16 ms 24368 KB n=2000
91 Correct 14 ms 24276 KB n=2000
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 23764 KB n=5
2 Correct 13 ms 23824 KB n=100
3 Correct 12 ms 23820 KB n=100
4 Correct 13 ms 23764 KB n=100
5 Correct 14 ms 23784 KB n=100
6 Correct 13 ms 23764 KB n=100
7 Correct 12 ms 23820 KB n=100
8 Correct 14 ms 23748 KB n=100
9 Correct 13 ms 23820 KB n=100
10 Correct 15 ms 23816 KB n=100
11 Correct 12 ms 23848 KB n=100
12 Correct 12 ms 23836 KB n=100
13 Correct 13 ms 23800 KB n=100
14 Correct 12 ms 23816 KB n=100
15 Correct 12 ms 23828 KB n=100
16 Correct 13 ms 23764 KB n=100
17 Correct 12 ms 23764 KB n=100
18 Correct 12 ms 23832 KB n=100
19 Correct 12 ms 23780 KB n=100
20 Correct 15 ms 23764 KB n=100
21 Correct 13 ms 23764 KB n=100
22 Correct 16 ms 23848 KB n=100
23 Correct 13 ms 23764 KB n=100
24 Correct 13 ms 23804 KB n=100
25 Correct 13 ms 23740 KB n=100
26 Correct 13 ms 23724 KB n=12
27 Correct 13 ms 23844 KB n=100
28 Correct 15 ms 23892 KB n=500
29 Correct 14 ms 24020 KB n=500
30 Correct 14 ms 23892 KB n=500
31 Correct 17 ms 23892 KB n=500
32 Correct 14 ms 23924 KB n=500
33 Correct 13 ms 23892 KB n=500
34 Correct 13 ms 23892 KB n=500
35 Correct 13 ms 23936 KB n=500
36 Correct 13 ms 23892 KB n=500
37 Correct 14 ms 23892 KB n=500
38 Correct 13 ms 23840 KB n=500
39 Correct 14 ms 23936 KB n=500
40 Correct 13 ms 23952 KB n=500
41 Correct 12 ms 23892 KB n=500
42 Correct 14 ms 23892 KB n=500
43 Correct 14 ms 23892 KB n=500
44 Correct 16 ms 23832 KB n=500
45 Correct 13 ms 23952 KB n=500
46 Correct 15 ms 23892 KB n=500
47 Correct 13 ms 23968 KB n=500
48 Correct 15 ms 23852 KB n=500
49 Correct 13 ms 24016 KB n=500
50 Correct 15 ms 23892 KB n=500
51 Correct 13 ms 23892 KB n=500
52 Correct 13 ms 23904 KB n=500
53 Correct 13 ms 23932 KB n=500
54 Correct 13 ms 23892 KB n=500
55 Correct 13 ms 23916 KB n=278
56 Correct 13 ms 23892 KB n=500
57 Correct 13 ms 23848 KB n=500
58 Correct 13 ms 23892 KB n=500
59 Correct 15 ms 24216 KB n=2000
60 Correct 15 ms 24404 KB n=2000
61 Correct 15 ms 24348 KB n=2000
62 Correct 16 ms 24276 KB n=2000
63 Correct 17 ms 24284 KB n=2000
64 Correct 17 ms 24328 KB n=2000
65 Correct 16 ms 24276 KB n=2000
66 Correct 15 ms 24344 KB n=2000
67 Correct 17 ms 24216 KB n=2000
68 Correct 15 ms 24320 KB n=2000
69 Correct 14 ms 24296 KB n=2000
70 Correct 14 ms 24276 KB n=2000
71 Correct 15 ms 24276 KB n=2000
72 Correct 18 ms 24220 KB n=2000
73 Correct 19 ms 24296 KB n=2000
74 Correct 17 ms 24216 KB n=1844
75 Correct 15 ms 24256 KB n=2000
76 Correct 17 ms 24288 KB n=2000
77 Correct 18 ms 24220 KB n=2000
78 Correct 17 ms 24200 KB n=2000
79 Correct 16 ms 24276 KB n=2000
80 Correct 15 ms 24268 KB n=2000
81 Correct 16 ms 24208 KB n=2000
82 Correct 16 ms 24276 KB n=2000
83 Correct 16 ms 24276 KB n=2000
84 Correct 20 ms 24276 KB n=2000
85 Correct 16 ms 24344 KB n=2000
86 Correct 16 ms 24344 KB n=2000
87 Correct 16 ms 24232 KB n=2000
88 Correct 15 ms 24404 KB n=2000
89 Correct 16 ms 24372 KB n=2000
90 Correct 16 ms 24368 KB n=2000
91 Correct 14 ms 24276 KB n=2000
92 Correct 745 ms 74592 KB n=200000
93 Correct 1012 ms 79368 KB n=200000
94 Correct 907 ms 82756 KB n=200000
95 Correct 761 ms 74436 KB n=200000
96 Correct 743 ms 74388 KB n=200000
97 Correct 966 ms 78552 KB n=200000
98 Correct 747 ms 74376 KB n=200000
99 Correct 920 ms 74740 KB n=200000
100 Correct 659 ms 74392 KB n=200000
101 Correct 874 ms 84172 KB n=200000
102 Correct 446 ms 75652 KB n=200000
103 Correct 384 ms 75468 KB n=200000
104 Correct 430 ms 75556 KB n=200000
105 Correct 456 ms 76000 KB n=200000
106 Correct 422 ms 76000 KB n=200000
107 Correct 429 ms 76176 KB n=200000
108 Correct 802 ms 74412 KB n=200000
109 Correct 770 ms 74624 KB n=200000
110 Correct 811 ms 74548 KB n=200000
111 Correct 763 ms 73920 KB n=200000
112 Correct 886 ms 83028 KB n=200000
113 Correct 936 ms 78420 KB n=200000
114 Correct 690 ms 73912 KB n=200000
115 Correct 1027 ms 76532 KB n=200000
116 Correct 628 ms 74692 KB n=200000
117 Correct 893 ms 83300 KB n=200000
118 Correct 949 ms 77372 KB n=200000
119 Correct 623 ms 74608 KB n=200000
120 Correct 873 ms 83092 KB n=200000
121 Correct 799 ms 83072 KB n=200000
122 Correct 771 ms 83312 KB n=200000
123 Correct 451 ms 75724 KB n=200000
124 Correct 215 ms 38732 KB n=25264