제출 #384316

#제출 시각아이디문제언어결과실행 시간메모리
384316acmBirthday gift (IZhO18_treearray)C++14
56 / 100
1249 ms81388 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][25]; set<pair<int, int>> acl[200005]; set<int> s[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 <= __lg(n) + 1; 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 = __lg(n) + 1; 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(mp(i - 1, i)); } 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(mp(l - 1, l)); if (l < n) acl[lca(a[l], a[l + 1])].erase(mp(l, l + 1)); a[l] = r; s[a[l]].insert(l); if (l > 1) acl[lca(a[l - 1], a[l])].insert(mp(l - 1, l)); if (l < n) acl[lca(a[l], a[l + 1])].insert(mp(l, l + 1)); } 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(mp(l, l + 1)); if (ti != acl[v].end() && ti->S <= r) { cout << ti->F << " " << ti->S << "\n"; continue; } cout << -1 << " " << -1 << "\n"; } } // endl #ifndef ONLINE_JUDGE cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }

컴파일 시 표준 에러 (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...