제출 #344967

#제출 시각아이디문제언어결과실행 시간메모리
344967Valera_GrinenkoBirthday gift (IZhO18_treearray)C++17
12 / 100
18 ms24044 KiB
#pragma GCC optimize("Ofast") #pragma GCC target("avx,avx2,fma") #pragma GCC optimization ("unroll-loops") #include <iostream> #include <fstream> #include <algorithm> #include <vector> #include <set> #include <stack> #include <map> #include <unordered_map> #include <iomanip> #include <cmath> #include <queue> #include <bitset> #include <numeric> #include <array> #include <cstring> #include <random> #include <chrono> #define fi first #define se second #define pb push_back #define mp make_pair #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin()) typedef long long ll; typedef long double ld; using namespace std; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/tree_policy.hpp> // using namespace __gnu_pbds; // template<class T> // using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; const int N = 2e5 + 42, L = 20; vector<int> g[N]; int a[N], tin[N], tout[N], up[N][L]; set<int> haveone[N], havelca[N]; int timer = 0; bool anc(int u, int v) { return tin[u] <= tin[v] && tin[v] < tout[u]; } void dfs(int v, int p) { for(int l = 1; l < L; l++) up[v][l] = up[up[v][l - 1]][l - 1]; tin[v] = timer++; for(auto& x : g[v]) { if(x == p) continue; up[x][0] = v; dfs(x, v); } tout[v] = timer; } int lca(int v, int u) { if(anc(v, u)) return v; if(anc(u, v)) return v; for(int l = L - 1; l >= 0; l--) if(!anc(up[v][l], u)) v = up[v][l]; return up[v][0]; } int main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n = 0, m = 0, q = 0; cin >> n >> m >> q; for(int i = 1; i < n; i++) { int u, v; cin >> u >> v; g[--u].pb(--v); g[v].pb(u); } dfs(0, -1); vector<int> a(m); for(int i = 0; i < m; i++) { cin >> a[i]; a[i]--; haveone[a[i]].insert(i); if(i) { havelca[lca(a[i], a[i - 1])].insert(i - 1); } } while(q--) { int type; cin >> type; if(type == 1) { int pos, v; cin >> pos >> v; pos--; v--; haveone[a[pos]].erase(pos); if(pos > 0) havelca[lca(a[pos], a[pos - 1])].erase(pos - 1); if(pos + 1 < m) havelca[lca(a[pos], a[pos + 1])].erase(pos); a[pos] = v; haveone[a[pos]].insert(pos); if(pos > 0) havelca[lca(a[pos], a[pos - 1])].insert(pos - 1); if(pos + 1 < m) havelca[lca(a[pos], a[pos + 1])].insert(pos); } else { int l, r, v; cin >> l >> r >> v; l--; r--; v--; auto it = haveone[v].lower_bound(l); if(it != haveone[v].end()) { int cur = *it; if(cur <= r) { cout << cur + 1 << ' ' << cur + 1 << '\n'; continue; } } it = havelca[v].lower_bound(l); if(it != havelca[v].end()) { int cur = *it; if(cur + 1 <= r) { cout << cur + 1 << ' ' << cur + 2 << '\n'; continue; } } cout << "-1 -1\n"; } } return 0; } /* */

컴파일 시 표준 에러 (stderr) 메시지

treearray.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...