Submission #793571

#TimeUsernameProblemLanguageResultExecution timeMemory
793571Jarif_RahmanHorses (IOI15_horses)C++17
17 / 100
147 ms29832 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{ int k = 1; vector<ll> P; segtree(int n){ while(k < n) k*=2; 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); } }; int n; vector<int> X, Y; segtree seg(0); int query(){ int fi = 0; for(ll i = n-1, p = 1; i >= 0; i--){ p*=X[i]; if(i == 0 || p > L){ fi = i; break; } } ll ans = 0; for(ll i = fi, p = X[fi]; i < n; i++, p*=X[i]) ans = max(ans, p*Y[i]); ans%=md; if(fi) ans*=seg.product(0, fi-1), ans%=md; return ans; } int init(int _n, int _X[], int _Y[]){ swap(n, _n); X.resize(n), Y.resize(n); seg = segtree(n); for(int i = 0; i < n; i++) X[i] = _X[i], Y[i] = _Y[i], seg.update(i, X[i]); return query(); } int updateX(int i, int x){ X[i] = x; seg.update(i, x); return query(); } int updateY(int i, int y){ Y[i] = y; return query(); }

Compilation message (stderr)

horses.cpp: In function 'int query()':
horses.cpp:48:18: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   48 |             fi = i;
      |                  ^
horses.cpp:57:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   57 |     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...