Submission #387428

#TimeUsernameProblemLanguageResultExecution timeMemory
387428mehrdad_sohrabiHorses (IOI15_horses)C++14
17 / 100
671 ms45420 KiB
/// Black lives matter #include <bits/stdc++.h> #include "horses.h" /// 500 485 462 A4 using namespace std; typedef long long int ll; typedef complex<double> point; typedef long double ld; #define pb push_back #define pii pair < ll , ll > #define F first #define S second //#define endl '\n' #define int long long #define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0) #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math") #define kill(x) return cout<<x<<'\n', 0; const int N=5e5+10; ll seg[N*4]; set <int> s; ll x[N],y[N]; ll n; ll mod=1e9+7; ll ans=1; ll power(ll n,ll k){ if (k==0) return 1; if (k%2==1){ ll x=power(n,k/2); return x*x%mod*n%mod; } ll x=power(n,k/2); return x*x%mod; } void upd(ll nod,ll l,ll r,ll id,ll val){ if (r-l==1){ seg[nod]=val; return ; } ll mid=(r+l)/2; if (mid>id) upd(nod*2,l,mid,id,val); else upd(nod*2+1,mid,r,id,val); seg[nod]=max(seg[nod*2],seg[nod*2+1]); } ll get(ll nod,ll l,ll r,ll L,ll R){ if (l>=R || L>=r) return 0; if (l>=L && r<=R) return seg[nod]; ll mid=(r+l)/2; return max( get(nod*2,l,mid,L,R), get(nod*2+1,mid,r,L,R)); } ll solve(){ /* ll f=ans; ll e=1; ll q=0; for (int i=n-1;i>-1;i--){ q=max(q,y[i]); // cout << q << " " << e << " " << best.F << " " << best.S << endl; if (q*best.S>e*best.F){ best={q,e}; f=ans*power(e,mod-2)%mod*q%mod; // cout << f << endl; } e*=x[i]; if (e>(ll)1e9) break; } return f; */ ll jav=ans; ll cnt=1; pii best={1,1}; auto t=s.end(); ll p1=0; for (int i=0;i<min((ll)s.size(),(ll)30);i++){ t--; ll z=get(1,0,n,*t,n); if (z*best.S>cnt*best.F){ best={z,cnt}; jav=ans*power(cnt,mod-2)%mod*z%mod; } cnt*=x[*t]; if (cnt>(ll)1e9){ p1=1; break; } } if (p1==0){ ll z=get(1,0,n,0,n); // cout << z << endl; if (z*best.S>cnt*best.F) jav=z; } return jav; } int32_t init(int32_t N, int32_t X[], int32_t Y[]) { n=N; for (int i=0;i<n;i++) { x[i]=X[i]; y[i]=Y[i]; upd(1,0,n,i,y[i]); if (x[i]>1) s.insert(i); // cout << x[i] << endl; ans*=x[i]; ans%=mod; } // cout << ans << " ans " << endl; return solve(); } int32_t updateX(int32_t pos, int32_t val) { ans=ans*power(x[pos],mod-2)%mod; ans*=val; ans%=mod; x[pos]=val; cout << ans << endl; if (x[pos]==1) s.erase(pos); else s.insert(pos); return solve(); } int32_t updateY(int32_t pos, int32_t val) { y[pos]=val; upd(1,0,n,pos,val); return solve(); } /* int32_t X[N],Y[N]; int32_t main(){ ll n; cin >> n; for (int i=0;i<n;i++){ cin >> X[i]; } for (int i=0;i<n;i++){ cin >> Y[i]; } cout << init(n,X,Y) << endl;; // cout << solve() << " solve " << endl; ll q; cin >> q; while(q--){ ll ty; cin >> ty; ll pos,val; cin >> pos >> val; if (ty==1){ cout << updateX(pos,val) << endl; } else cout << updateY(pos,val) << endl;; } } */ /* */

Compilation message (stderr)

horses.cpp: In function 'll power(ll, ll)':
horses.cpp:25:19: warning: declaration of 'n' shadows a global declaration [-Wshadow]
   25 | ll power(ll n,ll k){
      |                   ^
horses.cpp:22:4: note: shadowed declaration is here
   22 | ll n;
      |    ^
horses.cpp:28:12: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   28 |         ll x=power(n,k/2);
      |            ^
horses.cpp:21:4: note: shadowed declaration is here
   21 | ll x[N],y[N];
      |    ^
horses.cpp:31:8: warning: declaration of 'x' shadows a global declaration [-Wshadow]
   31 |     ll x=power(n,k/2);
      |        ^
horses.cpp:21:4: note: shadowed declaration is here
   21 | ll x[N],y[N];
      |    ^
horses.cpp: In function 'int32_t init(int32_t, int32_t*, int32_t*)':
horses.cpp:93:49: warning: declaration of 'N' shadows a global declaration [-Wshadow]
   93 | int32_t init(int32_t N, int32_t X[], int32_t Y[]) {
      |                                                 ^
horses.cpp:18:11: note: shadowed declaration is here
   18 | const int N=5e5+10;
      |           ^
horses.cpp:105:14: warning: conversion from 'll' {aka 'long long int'} to 'int32_t' {aka 'int'} may change value [-Wconversion]
  105 |  return solve();
      |         ~~~~~^~
horses.cpp: In function 'int32_t updateX(int32_t, int32_t)':
horses.cpp:115:14: warning: conversion from 'll' {aka 'long long int'} to 'int32_t' {aka 'int'} may change value [-Wconversion]
  115 |  return solve();
      |         ~~~~~^~
horses.cpp: In function 'int32_t updateY(int32_t, int32_t)':
horses.cpp:121:14: warning: conversion from 'll' {aka 'long long int'} to 'int32_t' {aka 'int'} may change value [-Wconversion]
  121 |  return 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...