제출 #943991

#제출 시각아이디문제언어결과실행 시간메모리
943991MinbaevDynamic Diameter (CEOI19_diameter)C++17
0 / 100
197 ms20856 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define pii pair<int,int> using namespace __gnu_pbds; using namespace std; #define pb push_back #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define f first #define int long long #define s second #define pii pair<int,int> template<class T>bool umax(T &a,T b){if(a<b){a=b;return true;}return false;} template<class T>bool umin(T &a,T b){if(b<a){a=b;return true;}return false;} typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set; const int N=3e5 + 5 ; const int inf = 1e17 + 7; const int mod = 998244353; int n,m,k; vector<pii>g[N]; pii t[N*4]; void update(int tl, int tr, int v, int pos, int val){ if(tl == tr){ t[v] = {val,-1}; return; } int tm = (tl + tr)/2; if(pos<=tm) update(tl,tm,v*2,pos,val); else update(tm+1,tr,v*2+1,pos,val); vector<int>a = {t[v*2].f, t[v*2].s, t[v*2+1].f, t[v*2+1].s}; sort(rall(a)); t[v] = {a[0],a[1]}; } void solve(){ cin >> n >> m >> k; for(int i = 0;i<n - 1;i++){ int a,b,c; cin >> a >> b >> c; g[a].pb({b,c}); g[b].pb({a,c}); update(0,n-2,1,i,c); } int last = 0; while(m--){ int a,b; cin >> a >> b; int pos = (a + last) % (n - 1); int val = (b + last) % k; update(0,n-2,1,pos,val); cout<<t[1].f + t[1].s<<"\n"; last = t[1].f + t[1].s; } } signed main() { // freopen("seq.in", "r", stdin); // freopen("seq.out", "w", stdout); ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL); int tt=1;//cin>>tt>>n; while(tt--)solve(); }
#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...