Submission #793591

#TimeUsernameProblemLanguageResultExecution timeMemory
793591Jarif_RahmanHorses (IOI15_horses)C++17
100 / 100
731 ms60780 KiB
#include <bits/stdc++.h> #define pb push_back #define f first #define sc second using namespace std; typedef long long int ll; typedef string str; const ll md = 1e9+7; const ll L = 1e9+5; struct segtree_for_product{ int k = 1; vector<ll> P; segtree_for_product(int n){ while(k < n) k<<=1; P.assign(2*k, 1); } void update(int i, ll x){ i+=k; P[i] = x%md; i>>=1; while(i){ P[i] = (P[i<<1]*P[(i<<1)+1])%md; i>>=1; } } ll product(int l, int r, int nd, int a, int b){ if(a > r || b < l) return 1; if(a >= l && b <= r) return P[nd]; int mid = (a+b)>>1; return (product(l, r, nd<<1, a, mid)*product(l, r, (nd<<1)+1, mid+1, b))%md; } ll product(int l, int r){ return product(l, r, 1, 0, k-1); } }; struct segtree_for_maximum{ int k = 1; vector<ll> P; segtree_for_maximum(int n){ while(k < n) k<<=1; P.assign(2*k, 0); } void update(int i, ll x){ i+=k; P[i] = x; i>>=1; while(i){ P[i] = max(P[i<<1], P[(i<<1)+1]); i>>=1; } } ll getmax(int l, int r, int nd, int a, int b){ if(a > r || b < l) return 0; if(a >= l && b <= r) return P[nd]; int mid = (a+b)>>1; return max(getmax(l, r, nd<<1, a, mid), getmax(l, r, (nd<<1)+1, mid+1, b)); } ll getmax(int l, int r){ return getmax(l, r, 1, 0, k-1); } }; int n; vector<int> X, Y; segtree_for_product segx(0); segtree_for_maximum segy(0); set<int> candidates; int query(){ int fi = 0; ll p = 1; for(auto it = candidates.rbegin(); it != candidates.rend(); it++){ p*=X[*it]; if(p > L){ fi = *it; break; } } ll ans = 0; p = 1; int j = fi; while(j < n){ if(j != fi) p*=X[j]; auto it = candidates.upper_bound(j); int nxt = n; if(it != candidates.end()) nxt = *it; ans = max(ans, p*segy.getmax(j, nxt-1)); j = nxt; } ans%=md; ans*=segx.product(0, fi), ans%=md; return ans; } int init(int _n, int _X[], int _Y[]){ swap(n, _n); X.resize(n), Y.resize(n); segx = segtree_for_product(n); segy = segtree_for_maximum(n); for(int i = 0; i < n; i++){ X[i] = _X[i], Y[i] = _Y[i], segx.update(i, X[i]), segy.update(i, Y[i]); if(X[i] > 1) candidates.insert(i); } return query(); } int updateX(int i, int x){ if(X[i] > 1) candidates.erase(i); X[i] = x; if(X[i] > 1) candidates.insert(i); segx.update(i, x); return query(); } int updateY(int i, int y){ Y[i] = y; segy.update(i, y); return query(); }

Compilation message (stderr)

horses.cpp: In function 'int query()':
horses.cpp:97:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   97 |     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...