Submission #312642

#TimeUsernameProblemLanguageResultExecution timeMemory
312642joseacazHorses (IOI15_horses)C++17
17 / 100
1586 ms36856 KiB
#include "horses.h" #include <bits/stdc++.h> #define pb push_back #define all(x) x.begin(), x.end() using namespace std; using ll = long long; using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>; using vpi = vector<pii>; using vpl = vector<pll>; struct Node { double pre, tot; int x; }; const int MOD = 1e9 + 7, MAXN = 5e5 + 5; int N, X[MAXN], Y[MAXN]; double a[MAXN]; Node ST[4*MAXN]; Node operator +(const Node& _x, const Node& _y) { Node tmp; tmp.pre = _x.pre; tmp.x = _x.x; tmp.tot = _x.tot + _y.tot; if(_x.tot + _y.pre > _x.pre) { tmp.pre = _x.tot + _y.pre; tmp.x = _y.x; } return tmp; } void build(int node = 0, int l = 0, int r = N - 1) { if(l == r) { ST[node] = Node{a[l], a[l], l}; //cerr << l << ", " << r << " : " << a[l] << " " << a[l] << " " << l << "\n"; return; } int mid = (l+r)/2, lchild = 2*node + 1, rchild = 2*node + 2; build(lchild, l, mid); build(rchild, mid + 1, r); ST[node] = ST[lchild] + ST[rchild]; //cerr << l << ", " << r << " : " << ST[node].pre << " " << ST[node].tot << " " << ST[node].x << "\n"; } void upd(int pos, double x, int node = 0, int l = 0, int r = N - 1) { if(r < pos || pos < l) return; if(l == r) { a[l] = x; ST[node] = Node{x, x, l}; //cerr << l << ", " << r << " : " << ST[node].pre << " " << ST[node].tot << " " << ST[node].x << "\n"; return; } int mid = (l+r)/2, lchild = 2*node + 1, rchild = 2*node + 2; upd(pos, x, lchild, l, mid); upd(pos, x, rchild, mid + 1, r); ST[node] = ST[lchild] + ST[rchild]; //cerr << l << ", " << r << " : " << ST[node].pre << " " << ST[node].tot << " " << ST[node].x << "\n"; } int init(int _N, int _X[], int _Y[]) { N = _N; for(int i = 0; i < N; i++) { X[i] = _X[i]; Y[i] = _Y[i]; } a[0] = log(X[0]) + log(Y[0]); for(int i = 1; i < N; i++) a[i] = log(X[i]) + log(Y[i]) - log(Y[i - 1]); build(); int idx = ST[0].x, ans = 1; //cerr << "\n" << idx << "\n"; for(int i = 0; i <= idx; i++) { ans *= X[i]; ans %= MOD; } ans *= Y[idx]; ans %= MOD; return ans; } int updateX(int pos, int val) { upd(pos, log(val) - log(X[pos])); X[pos] = val; int idx = ST[0].x, ans = 1; //cerr << ST[0].x << "\n"; for(int i = 0; i <= idx; i++) { ans *= X[i]; ans %= MOD; } ans *= Y[idx]; ans %= MOD; return ans; } int updateY(int pos, int val) { upd(pos, log(val) - log(Y[pos])); upd(pos + 1, log(Y[pos]) - log(val)); Y[pos] = val; int idx = ST[0].x, ans = 1; //cerr << ST[0].x << "\n"; for(int i = 0; i <= idx; i++) { ans *= X[i]; ans %= MOD; } ans *= Y[idx]; ans %= MOD; return ans; }
#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...