Submission #890808

#TimeUsernameProblemLanguageResultExecution timeMemory
890808NeroZeinHorses (IOI15_horses)C++17
Compilation error
0 ms0 KiB
#include "horses.h" #include "bits/stdc++.h" using namespace std; const int N = 5e5 + 5; const int md = (int) 1e9 + 7; struct node { int mul = 1, mullazy = 1; long double y = 0, lgsum = 0, lglazy = 0, mx = 0; }; int n; int x[N], y[N]; node seg[N * 2]; inline int mul(int a, int b) { return (int) ((long long) a * b % md); } inline int inv(int a) { a %= md; if (a < 0) a += md; int b = md, u = 0, v = 1; while (a) { int t = b / a; b -= t * a; swap(a, b); u -= t * v; swap(u, v); } assert(b == 1); if (u < 0) u += md; return u; } node merge(node& lx, node& rx) { return (lx.mx < rx.mx ? rx : lx); } void push(int nd, int l, int r) { if (!seg[nd].lglazy) return; seg[nd].mul = mul(seg[nd].mul, seg[nd].mullazy); seg[nd].mx = seg[nd].lgsum + seg[nd].y; seg[nd].lgsum += seg[nd].lglazy; if (l != r) { int mid = (l + r) >> 1; int rs = nd + ((mid - l + 1) << 1); seg[nd + 1].lglazy += seg[nd].lglazy; seg[nd + 1].mullazy = mul(seg[nd + 1].mullazy, seg[nd].mullazy); seg[rs].lglazy += seg[nd].lglazy; seg[rs].mullazy = mul(seg[rs].mullazy, seg[nd].mullazy); } seg[nd].lglazy = 0; seg[nd].mullazy = 1; } pair<int, long double> build(int nd, int l, int r, int z = 1, long double s = 0) { if (l == r) { s += log2(x[l]); z = mul(z, x[l]); seg[nd].y = log2(y[l]); seg[nd].mul = z; seg[nd].lgsum = s; seg[nd].mx = seg[nd].lgsum + seg[nd].y; //cout << s << ' ' << z << ' ' << seg[nd].y << ' ' << seg[nd].mx << '\n'; return {z, s}; } int mid = (l + r) >> 1; int rs = nd + ((mid - l + 1) << 1); pair<int, long long> lx = build(nd + 1, l, mid, z, s); z = lx.first; s = lx.second; pair<int, long long> rx = build(rs, mid + 1, r, z, s); z = rx.first; s = rx.second; seg[nd] = merge(seg[nd + 1], seg[rs]); return {z, s}; } void updX(int nd, int l, int r, int s, int e, int v) { push(nd, l, r); if (l >= s && r <= e) { if (v < 0) { seg[nd].lglazy = -log2(-v); seg[nd].mullazy = inv(-v); } else { seg[nd].lglazy = log2(v); seg[nd].mullazy = v; } push(nd, l, r); return; } int mid = (l + r) >> 1; int rs = nd + ((mid - l + 1) << 1); if (s <= mid) { updX(nd + 1, l, mid, s, e, v); } else { push(nd + 1, l, mid); } if (mid < e) { updX(rs, mid + 1, r, s, e, v); } else { push(rs, mid + 1, r); } seg[nd] = merge(seg[nd + 1], seg[rs]); } void updY(int nd, int l, int r, int p, int v) { push(nd, l, r); if (l == r) { seg[nd].y = log2(v); seg[nd].mx = seg[nd].lgsum + seg[nd].y; //cout << "L: " << l << ' ' << seg[nd].mx << '\n'; return; } int mid = (l + r) >> 1; int rs = nd + ((mid - l + 1) << 1); if (p <= mid) { push(rs, mid + 1, r); updY(nd + 1, l, mid, p, v); } else { push(nd + 1, l, mid); updY(rs, mid + 1, r, p, v); } seg[nd] = merge(seg[nd + 1], seg[rs]); } int get(int nd, int l, int r) { if (l == r) { return mul(seg[nd].mul, y[l]); } int mid = (l + r) >> 1; int rs = nd + ((mid - l + 1) << 1); push(nd + 1, l, mid); push(rs, mid + 1, r); if (seg[nd + 1].mx < seg[rs].mx) { return get(rs, mid + 1, r); } else { return get(nd + 1, l, mid); } } 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]; } build(0, 0, n - 1); return get(0, 0, n - 1); } int updateX(int pos, int val) { return 0; } int updateY(int pos, int val) { y[pos] = val; updY(0, 0, n - 1, pos, val); return get(0, 0, n - 1); }

Compilation message (stderr)

Compilation timeout while compiling horses