제출 #425622

#제출 시각아이디문제언어결과실행 시간메모리
425622hhhhauraDynamic Diameter (CEOI19_diameter)C++14
18 / 100
5028 ms20308 KiB
#define wiwihorz #include <bits/stdc++.h> #pragma GCC optimize("Ofast") #pragma loop-opt(on) #define rep(i, a, b) for(int i = a; i <= b; i++) #define rrep(i, a, b) for(int i = b; i >= a; i--) #define ceil(a, b) ((a + b - 1) / (b)) #define all(x) x.begin(), x.end() #define INF 1000000000000000000 #define MOD 1000000007 #define eps (1e-9) using namespace std; #define int long long int #define lld long double #define pii pair<int, int> #define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count()) #ifdef wiwihorz #define print(a...) kout("[" + string(#a) + "] = ", a) void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;} void kout() { cerr << endl; } template<class T1, class ... T2> void kout(T1 a, T2 ... e) { cerr << a << " ", kout(e...); } #else #define print(...) 0 #define vprint(...) 0 #endif namespace solver { int n; vector<int> val, dp, es, cost, x, y; vector<vector<int>> mp; multiset<int> s; void init_(int _n) { n = _n; val.assign(n + 1, 0); dp.assign(n + 1, 0); es.clear(); cost.clear(); x.clear(); y.clear(); mp.assign(n + 1, vector<int>()); s.clear(); } void add_edge(int a, int b, int c) { mp[a].push_back(es.size()); mp[b].push_back(es.size()); x.push_back(a); y.push_back(b); es.push_back(a ^ b); cost.push_back(c); } void dfs(int x, int par) { dp[x] = 0; int v1 = 0, v2 = 0; for(auto i : mp[x]) if(i != par) { int to = es[i] ^ x; dfs(to, i); int vv = dp[to] + cost[i]; dp[x] = max(dp[x], vv); if(vv > v1) swap(vv, v1); if(vv > v2) swap(vv, v2); } val[x] = v1 + v2; s.insert(val[x]); } int query(int id, int c) { int a = x[id], b = y[id]; if(a > b) swap(a, b); cost[id] = c; while(a) { dp[a] = 0; int v1 = 0, v2 = 0; for(auto i : mp[a]) if((es[i] ^ a) > a) { int to = es[i] ^ a, vv = dp[to] + cost[i]; dp[a] = max(dp[a], vv); if(vv > v1) swap(vv, v1); if(vv > v2) swap(vv, v2); } s.erase(s.find(val[a])); val[a] = v1 + v2; s.insert(val[a]); a /= 2; } return *s.rbegin(); } }; using namespace solver; signed main() { ios::sync_with_stdio(false), cin.tie(0); int n, q, w, last = 0; cin >> n >> q >> w, init_(n); rep(i, 1, n - 1) { int a, b, c; cin >> a >> b >> c; add_edge(a, b, c); } dfs(1, -1); while(q --) { int x, y; cin >> x >> y; x = (x + last) % (n - 1); y = (y + last) % w; int ans = query(x, y); last = ans; cout << ans << "\n"; } return 0; }

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

diameter.cpp:4: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    4 | #pragma loop-opt(on)
      | 
diameter.cpp:23:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   23 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |             ^~~~
diameter.cpp:23:21: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   23 | void vprint(auto L, auto R) {while(L < R) cerr << *L << " \n"[next(L) == R], ++L;}
      |                     ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...