Submission #573084

# Submission time Handle Problem Language Result Execution time Memory
573084 2022-06-05T18:00:53 Z MohammadAghil Birthday gift (IZhO18_treearray) C++14
100 / 100
1453 ms 82316 KB
      #include <bits/stdc++.h>
//   #pragma GCC optimize ("Ofast,unroll-loops")
// #pragma GCC target ("avx2")
    using namespace std;
  typedef long long ll;
   typedef pair<int, int> pp;
    #define er(args ...) cerr << __LINE__ << ": ", err(new istringstream(string(#args)), args), cerr << endl
      #define per(i,r,l) for(int i = (r); i >= (l); i--)
        #define rep(i,l,r) for(int i = (l); i < (r); i++)
           #define all(x) x.begin(), x.end()
              #define sz(x) (int)(x).size()
                  #define pb push_back
                      #define ss second
                           #define ff first
                                   void err(istringstream *iss){}template<typename T,typename ...Args> void err(istringstream *iss,const T &_val, const Args&...args){string _name;*iss>>_name;if(_name.back()==',')_name.pop_back();cerr<<_name<<" = "<<_val<<", ",err(iss,args...);}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const ll mod = 1e9 + 7, maxn = 2e5 + 5, lg = 22, lng = 26, inf = ll(1e9) + 5;
ll pw(ll a,ll b,ll md=mod){if(!b)return 1;ll k=pw(a,b>>1ll);return k*k%md*(b&1ll?a:1)%md;}

vector<int> adj[maxn];
int par[maxn][lg], h[maxn];

void dfs(int r, int p){
     par[r][0] = p;
     rep(i,1,lg) par[r][i] = par[par[r][i-1]][i-1];
     for(int c: adj[r]) if(c - p) h[c] = h[r]+1, dfs(c, r); 
}

int lca(int u, int v){
     if(h[u] > h[v]) swap(u, v);
     per(i,lg-1,0) if(h[u] <= h[par[v][i]]) v = par[v][i];
     if(u == v) return u;
     per(i,lg-1,0) if(par[u][i] - par[v][i]) u = par[u][i], v = par[v][i];
     return par[u][0];
}

set<int> pos[maxn], bt[maxn];

int main(){
     cin.tie(0) -> sync_with_stdio(0);
     int n, m, q; cin >> n >> m >> q;
     rep(i,1,n){
          int u, v; cin >> u >> v; u--, v--;
          adj[u].pb(v), adj[v].pb(u);
     } dfs(0, 0);
     vector<int> a(m);
     rep(i,0,m){
          cin >> a[i]; a[i]--;
          pos[a[i]].insert(i);
          if(i) bt[lca(a[i-1], a[i])].insert(i-1);
     }
     while(q--){
          int t; cin >> t;
          if(t&1){
               int p, v; cin >> p >> v; p--, v--;
               pos[a[p]].erase(p);
               if(p) bt[lca(a[p], a[p-1])].erase(p-1);
               if(p < m-1) bt[lca(a[p], a[p+1])].erase(p);
               a[p] = v;
               pos[a[p]].insert(p);
               if(p) bt[lca(a[p], a[p-1])].insert(p-1);
               if(p < m-1) bt[lca(a[p], a[p+1])].insert(p);
          }else{
               int l, r, x; cin >> l >> r >> x; l--, r--, x--;
               auto it = pos[x].lower_bound(l);
               if(it != end(pos[x]) && *it <= r) cout << *it + 1 << ' ' << *it + 1 << '\n';
               else{
                    auto it = bt[x].lower_bound(l);
                    if(it != end(bt[x]) && *it < r) cout << *it + 1 << ' ' << *it + 2 << '\n';
                    else cout << -1 << ' ' << -1 << '\n';
               }
          }
     }
     return 0; 
}
/*

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

*/
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB n=5
2 Correct 12 ms 23892 KB n=100
3 Correct 13 ms 23764 KB n=100
4 Correct 13 ms 23796 KB n=100
5 Correct 12 ms 23820 KB n=100
6 Correct 13 ms 23804 KB n=100
7 Correct 12 ms 23764 KB n=100
8 Correct 13 ms 23916 KB n=100
9 Correct 12 ms 23820 KB n=100
10 Correct 13 ms 23824 KB n=100
11 Correct 12 ms 23816 KB n=100
12 Correct 13 ms 23812 KB n=100
13 Correct 13 ms 23892 KB n=100
14 Correct 12 ms 23764 KB n=100
15 Correct 14 ms 23800 KB n=100
16 Correct 12 ms 23728 KB n=100
17 Correct 13 ms 23840 KB n=100
18 Correct 13 ms 23892 KB n=100
19 Correct 12 ms 23752 KB n=100
20 Correct 13 ms 23764 KB n=100
21 Correct 13 ms 23764 KB n=100
22 Correct 12 ms 23764 KB n=100
23 Correct 12 ms 23752 KB n=100
24 Correct 13 ms 23824 KB n=100
25 Correct 12 ms 23840 KB n=100
26 Correct 13 ms 23812 KB n=12
27 Correct 13 ms 23892 KB n=100
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB n=5
2 Correct 12 ms 23892 KB n=100
3 Correct 13 ms 23764 KB n=100
4 Correct 13 ms 23796 KB n=100
5 Correct 12 ms 23820 KB n=100
6 Correct 13 ms 23804 KB n=100
7 Correct 12 ms 23764 KB n=100
8 Correct 13 ms 23916 KB n=100
9 Correct 12 ms 23820 KB n=100
10 Correct 13 ms 23824 KB n=100
11 Correct 12 ms 23816 KB n=100
12 Correct 13 ms 23812 KB n=100
13 Correct 13 ms 23892 KB n=100
14 Correct 12 ms 23764 KB n=100
15 Correct 14 ms 23800 KB n=100
16 Correct 12 ms 23728 KB n=100
17 Correct 13 ms 23840 KB n=100
18 Correct 13 ms 23892 KB n=100
19 Correct 12 ms 23752 KB n=100
20 Correct 13 ms 23764 KB n=100
21 Correct 13 ms 23764 KB n=100
22 Correct 12 ms 23764 KB n=100
23 Correct 12 ms 23752 KB n=100
24 Correct 13 ms 23824 KB n=100
25 Correct 12 ms 23840 KB n=100
26 Correct 13 ms 23812 KB n=12
27 Correct 13 ms 23892 KB n=100
28 Correct 13 ms 23944 KB n=500
29 Correct 13 ms 23892 KB n=500
30 Correct 14 ms 23892 KB n=500
31 Correct 13 ms 23956 KB n=500
32 Correct 15 ms 23828 KB n=500
33 Correct 15 ms 23956 KB n=500
34 Correct 13 ms 23892 KB n=500
35 Correct 13 ms 23892 KB n=500
36 Correct 13 ms 23892 KB n=500
37 Correct 12 ms 23892 KB n=500
38 Correct 13 ms 23892 KB n=500
39 Correct 14 ms 23856 KB n=500
40 Correct 13 ms 23892 KB n=500
41 Correct 13 ms 23892 KB n=500
42 Correct 13 ms 23856 KB n=500
43 Correct 14 ms 23828 KB n=500
44 Correct 13 ms 23948 KB n=500
45 Correct 15 ms 23832 KB n=500
46 Correct 15 ms 23884 KB n=500
47 Correct 15 ms 23892 KB n=500
48 Correct 15 ms 23824 KB n=500
49 Correct 14 ms 23892 KB n=500
50 Correct 15 ms 23892 KB n=500
51 Correct 14 ms 23820 KB n=500
52 Correct 13 ms 23892 KB n=500
53 Correct 13 ms 23960 KB n=500
54 Correct 14 ms 23952 KB n=500
55 Correct 12 ms 23820 KB n=278
56 Correct 14 ms 23952 KB n=500
57 Correct 14 ms 23892 KB n=500
58 Correct 13 ms 23832 KB n=500
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB n=5
2 Correct 12 ms 23892 KB n=100
3 Correct 13 ms 23764 KB n=100
4 Correct 13 ms 23796 KB n=100
5 Correct 12 ms 23820 KB n=100
6 Correct 13 ms 23804 KB n=100
7 Correct 12 ms 23764 KB n=100
8 Correct 13 ms 23916 KB n=100
9 Correct 12 ms 23820 KB n=100
10 Correct 13 ms 23824 KB n=100
11 Correct 12 ms 23816 KB n=100
12 Correct 13 ms 23812 KB n=100
13 Correct 13 ms 23892 KB n=100
14 Correct 12 ms 23764 KB n=100
15 Correct 14 ms 23800 KB n=100
16 Correct 12 ms 23728 KB n=100
17 Correct 13 ms 23840 KB n=100
18 Correct 13 ms 23892 KB n=100
19 Correct 12 ms 23752 KB n=100
20 Correct 13 ms 23764 KB n=100
21 Correct 13 ms 23764 KB n=100
22 Correct 12 ms 23764 KB n=100
23 Correct 12 ms 23752 KB n=100
24 Correct 13 ms 23824 KB n=100
25 Correct 12 ms 23840 KB n=100
26 Correct 13 ms 23812 KB n=12
27 Correct 13 ms 23892 KB n=100
28 Correct 13 ms 23944 KB n=500
29 Correct 13 ms 23892 KB n=500
30 Correct 14 ms 23892 KB n=500
31 Correct 13 ms 23956 KB n=500
32 Correct 15 ms 23828 KB n=500
33 Correct 15 ms 23956 KB n=500
34 Correct 13 ms 23892 KB n=500
35 Correct 13 ms 23892 KB n=500
36 Correct 13 ms 23892 KB n=500
37 Correct 12 ms 23892 KB n=500
38 Correct 13 ms 23892 KB n=500
39 Correct 14 ms 23856 KB n=500
40 Correct 13 ms 23892 KB n=500
41 Correct 13 ms 23892 KB n=500
42 Correct 13 ms 23856 KB n=500
43 Correct 14 ms 23828 KB n=500
44 Correct 13 ms 23948 KB n=500
45 Correct 15 ms 23832 KB n=500
46 Correct 15 ms 23884 KB n=500
47 Correct 15 ms 23892 KB n=500
48 Correct 15 ms 23824 KB n=500
49 Correct 14 ms 23892 KB n=500
50 Correct 15 ms 23892 KB n=500
51 Correct 14 ms 23820 KB n=500
52 Correct 13 ms 23892 KB n=500
53 Correct 13 ms 23960 KB n=500
54 Correct 14 ms 23952 KB n=500
55 Correct 12 ms 23820 KB n=278
56 Correct 14 ms 23952 KB n=500
57 Correct 14 ms 23892 KB n=500
58 Correct 13 ms 23832 KB n=500
59 Correct 16 ms 24276 KB n=2000
60 Correct 17 ms 24404 KB n=2000
61 Correct 17 ms 24276 KB n=2000
62 Correct 16 ms 24348 KB n=2000
63 Correct 16 ms 24228 KB n=2000
64 Correct 17 ms 24316 KB n=2000
65 Correct 16 ms 24276 KB n=2000
66 Correct 17 ms 24408 KB n=2000
67 Correct 19 ms 24276 KB n=2000
68 Correct 17 ms 24480 KB n=2000
69 Correct 14 ms 24276 KB n=2000
70 Correct 15 ms 24276 KB n=2000
71 Correct 15 ms 24276 KB n=2000
72 Correct 16 ms 24252 KB n=2000
73 Correct 15 ms 24208 KB n=2000
74 Correct 16 ms 24388 KB n=1844
75 Correct 15 ms 24276 KB n=2000
76 Correct 16 ms 24404 KB n=2000
77 Correct 17 ms 24320 KB n=2000
78 Correct 16 ms 24276 KB n=2000
79 Correct 16 ms 24260 KB n=2000
80 Correct 15 ms 24404 KB n=2000
81 Correct 16 ms 24268 KB n=2000
82 Correct 16 ms 24276 KB n=2000
83 Correct 15 ms 24300 KB n=2000
84 Correct 16 ms 24264 KB n=2000
85 Correct 18 ms 24276 KB n=2000
86 Correct 16 ms 24276 KB n=2000
87 Correct 16 ms 24212 KB n=2000
88 Correct 16 ms 24344 KB n=2000
89 Correct 15 ms 24420 KB n=2000
90 Correct 15 ms 24404 KB n=2000
91 Correct 15 ms 24212 KB n=2000
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23764 KB n=5
2 Correct 12 ms 23892 KB n=100
3 Correct 13 ms 23764 KB n=100
4 Correct 13 ms 23796 KB n=100
5 Correct 12 ms 23820 KB n=100
6 Correct 13 ms 23804 KB n=100
7 Correct 12 ms 23764 KB n=100
8 Correct 13 ms 23916 KB n=100
9 Correct 12 ms 23820 KB n=100
10 Correct 13 ms 23824 KB n=100
11 Correct 12 ms 23816 KB n=100
12 Correct 13 ms 23812 KB n=100
13 Correct 13 ms 23892 KB n=100
14 Correct 12 ms 23764 KB n=100
15 Correct 14 ms 23800 KB n=100
16 Correct 12 ms 23728 KB n=100
17 Correct 13 ms 23840 KB n=100
18 Correct 13 ms 23892 KB n=100
19 Correct 12 ms 23752 KB n=100
20 Correct 13 ms 23764 KB n=100
21 Correct 13 ms 23764 KB n=100
22 Correct 12 ms 23764 KB n=100
23 Correct 12 ms 23752 KB n=100
24 Correct 13 ms 23824 KB n=100
25 Correct 12 ms 23840 KB n=100
26 Correct 13 ms 23812 KB n=12
27 Correct 13 ms 23892 KB n=100
28 Correct 13 ms 23944 KB n=500
29 Correct 13 ms 23892 KB n=500
30 Correct 14 ms 23892 KB n=500
31 Correct 13 ms 23956 KB n=500
32 Correct 15 ms 23828 KB n=500
33 Correct 15 ms 23956 KB n=500
34 Correct 13 ms 23892 KB n=500
35 Correct 13 ms 23892 KB n=500
36 Correct 13 ms 23892 KB n=500
37 Correct 12 ms 23892 KB n=500
38 Correct 13 ms 23892 KB n=500
39 Correct 14 ms 23856 KB n=500
40 Correct 13 ms 23892 KB n=500
41 Correct 13 ms 23892 KB n=500
42 Correct 13 ms 23856 KB n=500
43 Correct 14 ms 23828 KB n=500
44 Correct 13 ms 23948 KB n=500
45 Correct 15 ms 23832 KB n=500
46 Correct 15 ms 23884 KB n=500
47 Correct 15 ms 23892 KB n=500
48 Correct 15 ms 23824 KB n=500
49 Correct 14 ms 23892 KB n=500
50 Correct 15 ms 23892 KB n=500
51 Correct 14 ms 23820 KB n=500
52 Correct 13 ms 23892 KB n=500
53 Correct 13 ms 23960 KB n=500
54 Correct 14 ms 23952 KB n=500
55 Correct 12 ms 23820 KB n=278
56 Correct 14 ms 23952 KB n=500
57 Correct 14 ms 23892 KB n=500
58 Correct 13 ms 23832 KB n=500
59 Correct 16 ms 24276 KB n=2000
60 Correct 17 ms 24404 KB n=2000
61 Correct 17 ms 24276 KB n=2000
62 Correct 16 ms 24348 KB n=2000
63 Correct 16 ms 24228 KB n=2000
64 Correct 17 ms 24316 KB n=2000
65 Correct 16 ms 24276 KB n=2000
66 Correct 17 ms 24408 KB n=2000
67 Correct 19 ms 24276 KB n=2000
68 Correct 17 ms 24480 KB n=2000
69 Correct 14 ms 24276 KB n=2000
70 Correct 15 ms 24276 KB n=2000
71 Correct 15 ms 24276 KB n=2000
72 Correct 16 ms 24252 KB n=2000
73 Correct 15 ms 24208 KB n=2000
74 Correct 16 ms 24388 KB n=1844
75 Correct 15 ms 24276 KB n=2000
76 Correct 16 ms 24404 KB n=2000
77 Correct 17 ms 24320 KB n=2000
78 Correct 16 ms 24276 KB n=2000
79 Correct 16 ms 24260 KB n=2000
80 Correct 15 ms 24404 KB n=2000
81 Correct 16 ms 24268 KB n=2000
82 Correct 16 ms 24276 KB n=2000
83 Correct 15 ms 24300 KB n=2000
84 Correct 16 ms 24264 KB n=2000
85 Correct 18 ms 24276 KB n=2000
86 Correct 16 ms 24276 KB n=2000
87 Correct 16 ms 24212 KB n=2000
88 Correct 16 ms 24344 KB n=2000
89 Correct 15 ms 24420 KB n=2000
90 Correct 15 ms 24404 KB n=2000
91 Correct 15 ms 24212 KB n=2000
92 Correct 757 ms 69832 KB n=200000
93 Correct 1093 ms 75220 KB n=200000
94 Correct 1202 ms 79800 KB n=200000
95 Correct 918 ms 70328 KB n=200000
96 Correct 930 ms 70700 KB n=200000
97 Correct 1453 ms 74780 KB n=200000
98 Correct 867 ms 70656 KB n=200000
99 Correct 1186 ms 70012 KB n=200000
100 Correct 860 ms 70732 KB n=200000
101 Correct 1301 ms 82152 KB n=200000
102 Correct 500 ms 71512 KB n=200000
103 Correct 512 ms 71600 KB n=200000
104 Correct 496 ms 71544 KB n=200000
105 Correct 489 ms 71416 KB n=200000
106 Correct 493 ms 71240 KB n=200000
107 Correct 526 ms 71340 KB n=200000
108 Correct 934 ms 70364 KB n=200000
109 Correct 944 ms 70296 KB n=200000
110 Correct 949 ms 70192 KB n=200000
111 Correct 805 ms 70528 KB n=200000
112 Correct 1161 ms 80980 KB n=200000
113 Correct 1157 ms 74760 KB n=200000
114 Correct 844 ms 70480 KB n=200000
115 Correct 1295 ms 71976 KB n=200000
116 Correct 780 ms 70372 KB n=200000
117 Correct 1152 ms 81316 KB n=200000
118 Correct 1304 ms 73284 KB n=200000
119 Correct 762 ms 70340 KB n=200000
120 Correct 1144 ms 81892 KB n=200000
121 Correct 1109 ms 82048 KB n=200000
122 Correct 1061 ms 82316 KB n=200000
123 Correct 598 ms 71052 KB n=200000
124 Correct 300 ms 38240 KB n=25264