Submission #492389

#TimeUsernameProblemLanguageResultExecution timeMemory
492389hollwo_pelwBirthday gift (IZhO18_treearray)C++17
100 / 100
1135 ms74904 KiB
/* // is short or still long ??? hollwo_pelw's template(short) // Note : -Dhollwo_pelw_local */ #include <bits/stdc++.h> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/trie_policy.hpp> // #include <ext/rope> using namespace std; // using namespace __gnu_pbds; // using namespace __gnu_cxx; void FAST_IO(string filein = "", string fileout = "", string fileerr = ""){ if (fopen(filein.c_str(), "r")){ freopen(fileout.c_str(), "w", stdout); freopen(filein.c_str(), "r", stdin); #ifdef hollwo_pelw_local freopen(fileerr.c_str(), "w", stderr); #endif } cin.tie(0), cout.tie(0) -> sync_with_stdio(0); } void Hollwo_Pelw(); signed main(){ #ifdef hollwo_pelw_local FAST_IO("input.inp", "output.out", "error.err"); auto start = chrono::steady_clock::now(); #else FAST_IO("hollwo_pelw.inp", "hollwo_pelw.out"); #endif int testcases = 1; // cin >> testcases; for (int test = 1; test <= testcases; test++){ // cout << "Case #" << test << ": "; Hollwo_Pelw(); } #ifdef hollwo_pelw_local auto end = chrono::steady_clock::now(); cout << endl; cout << "Excution time : " << chrono::duration_cast<chrono::milliseconds> (end - start).count() << "[ms]" << endl; #endif return 0; } const int N = 2e5 + 5; int n, m, q, a[N], h[N], par[18][N]; vector<int> adj[N]; set<int> st1[N], st2[N]; void pre_dfs(int u, int p) { h[u] = h[p] + 1; par[0][u] = p; for (int i = 1; i <= 17; i++) par[i][u] = par[i - 1][par[i - 1][u]]; for (auto v : adj[u]) if (v != p) pre_dfs(v, u); } inline int lca(int u, int v) { if (h[u] > h[v]) swap(u, v); for (int i = 17; ~i; i--) if (h[v] - h[u] >> i & 1) v = par[i][v]; if (u == v) return u; for (int i = 17; ~i; i--) if (par[i][u] ^ par[i][v]) { v = par[i][v]; u = par[i][u]; } return par[0][u]; } void Hollwo_Pelw() { cin >> n >> m >> q; for (int i = 1, u, v; i < n; i++) cin >> u >> v, adj[u].push_back(v), adj[v].push_back(u); for (int i = 1; i <= m; i++) cin >> a[i]; pre_dfs(1, 0); for (int i = 1; i <= m; i++) { st1[a[i]].insert(i); if (i < m) st2[lca(a[i], a[i + 1])].insert(i); } for (int t, p, l, r, v; q --; ) { cin >> t; if (t == 1) { cin >> p >> v; st1[a[p]].erase(p); if (p < m) st2[lca(a[p], a[p + 1])].erase(p); if (p > 1) st2[lca(a[p], a[p - 1])].erase(p - 1); a[p] = v; st1[a[p]].insert(p); if (p < m) st2[lca(a[p], a[p + 1])].insert(p); if (p > 1) st2[lca(a[p], a[p - 1])].insert(p - 1); } else { cin >> l >> r >> v; { auto it = st1[v].lower_bound(l); if (it != st1[v].end() && *it <= r) { cout << *it << ' ' << *it << '\n'; continue ; } } { auto it = st2[v].lower_bound(l); if (it != st2[v].end() && *it < r) { cout << *it << ' ' << (*it) + 1 << '\n'; continue ; } } cout << "-1 -1\n"; } } }

Compilation message (stderr)

treearray.cpp: In function 'int lca(int, int)':
treearray.cpp:69:12: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   69 |   if (h[v] - h[u] >> i & 1)
      |       ~~~~~^~~~~~
treearray.cpp: In function 'void FAST_IO(std::string, std::string, std::string)':
treearray.cpp:18:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   18 |   freopen(fileout.c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:19:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |   freopen(filein.c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...