Submission #384322

#TimeUsernameProblemLanguageResultExecution timeMemory
384322acmBirthday gift (IZhO18_treearray)C++14
56 / 100
1285 ms77784 KiB
#include <bits/stdc++.h> #define speed \ ios_base::sync_with_stdio(0); \ cin.tie(0); \ cout.tie(0); #define precision \ cout.precision(30); \ cerr.precision(10); #define ll long long #define ld long double #define pll pair<ll, ll> #define pii pair<int, int> #define forn(n) for (int i = 1; i <= n; i++) #define forlr(l, r) for (int i = l; i != r; (l > r ? i-- : i++)) #define pb(x) push_back(x) #define sz(x) (int)x.size() #define mp(x, y) make_pair(x, y) #define all(x) x.begin(), x.end() #define pc(x) __builtin_popcount(x) #define pcll(x) __builtin_popcountll(x) #define F first #define S second using namespace std; void ioi(string name) { freopen((name + ".in").c_str(), "r", stdin); freopen((name + ".out").c_str(), "w", stdout); } int n, m, q, T, a[200005], tin[200005], tout[200005], up[200005][20]; set<int> s[200005], acl[200005]; vector<int> g[200005]; void calc(int v = 1, int p = 1) { tin[v] = ++T; up[v][0] = p; for (int i = 1; i <= 19; i++) up[v][i] = up[up[v][i - 1]][i - 1]; for (auto to : g[v]) if (to != p) calc(to, v); tout[v] = ++T; } bool pred(int u, int v) { return (tin[u] <= tin[v] && tout[v] <= tout[u]); } int lca(int u, int v) { if (pred(u, v)) return u; if (pred(v, u)) return v; for (int i = 19; i >= 0; i--) if (!pred(up[u][i], v)) u = up[u][i]; return (pred(u, v) ? u : up[u][0]); } int main() { speed; precision; // code cin >> n >> m >> q; for (int i = 1; i <= n - 1; i++) { int u, v; cin >> u >> v; g[u].pb(v); g[v].pb(u); } calc(); for (int i = 1; i <= m; i++) { cin >> a[i]; s[a[i]].insert(i); if (i > 1) acl[lca(a[i - 1], a[i])].insert(i - 1); } while (q--) { int type, l, r, v; cin >> type; if (type == 1) { cin >> l >> r; s[a[l]].erase(l); if (l > 1) acl[lca(a[l - 1], a[l])].erase(l - 1); if (l < n) acl[lca(a[l], a[l + 1])].erase(l); a[l] = r; s[a[l]].insert(l); if (l > 1) acl[lca(a[l - 1], a[l])].insert(l - 1); if (l < n) acl[lca(a[l], a[l + 1])].insert(l); } if (type == 2) { cin >> l >> r >> v; auto it = s[v].lower_bound(l); if (it != s[v].end() && *it <= r) { cout << *it << " " << *it << "\n"; continue; } auto ti = acl[v].lower_bound(l); if (ti != acl[v].end() && *ti + 1 <= r) { cout << *ti << " " << *ti + 1 << "\n"; continue; } cout << -1 << " " << -1 << "\n"; } } // endl #ifndef ONLINE_JUDGE cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }

Compilation message (stderr)

treearray.cpp: In function 'void ioi(std::string)':
treearray.cpp:25:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   25 |   freopen((name + ".in").c_str(), "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
treearray.cpp:26:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   26 |   freopen((name + ".out").c_str(), "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...