Submission #590014

#TimeUsernameProblemLanguageResultExecution timeMemory
590014alirezasamimi100Horses (IOI15_horses)C++17
37 / 100
572 ms44804 KiB
#include "horses.h" #include <bits/stdc++.h> #define lc v<<1 #define rc v<<1|1 using ll = long long int; using namespace std; const int MOD = 1000000007, MN = 5e5 + 10; ll pow(ll x, ll y, ll mod){ ll ans=1; while (y != 0) { if (y & 1) ans = ans * x % mod; y >>= 1; x = x * x % mod; } return ans; } ll f[MN*4],g[MN],RX[MN]; int n; set<int> st; void update(int v, int l, int r, int p, ll x){ if(r-l==1){ f[v]=x; return; } int m=(l+r)>>1; if(p<m) update(lc,l,m,p,x); else update(rc,m,r,p,x); f[v]=max(f[lc],f[rc]); } ll get(int v, int l, int r, int tl, int tr){ if(l>=tr || tl>=r || tl>=tr) return 0; if(l>=tl && r<=tr) return f[v]; int m=(l+r)>>1; return max(get(lc,l,m,tl,tr),get(rc,m,r,tl,tr)); } void upd(int t, ll x){ for(t+=5; t<MN; t+=t&-t) g[t]=g[t]*x%MOD; } ll gt(int t, ll x=1){ for(t+=5; t; t-=t&-t) x=x*g[t]%MOD; return x; } int init(int N, int X[], int Y[]) { n=N; for(ll i=0; i<MN; i++) g[i]=1; for(int i=0; i<N; i++){ update(1,0,n,i,Y[i]); upd(i,X[i]); RX[i]=X[i]; if(X[i]>1) st.insert(-i); } ll ans=0,k=-1; for(int t : st){ if(ans>(ll)1e9) break; t=-t; k=t; ans=max(ans,get(1,0,n,t,n)); ans*=RX[t]; } if(k==-1) return f[1]; return ans%MOD*gt(k-1)%MOD; } int updateX(int pos, int val) { ll x=pow(RX[pos],MOD-2,MOD)*val%MOD; upd(pos,x); RX[pos]=val; if(val>1) st.insert(-pos); else st.erase(-pos); ll ans=0,k=-1; for(int t : st){ if(ans>(ll)1e9) break; t=-t; k=t; ans=max(ans,get(1,0,n,t,n)); ans*=RX[t]; } if(k==-1) return f[1]; return ans%MOD*gt(k-1)%MOD; } int updateY(int pos, int val) { update(1,0,n,pos,val); ll ans=0,k=-1; for(int t : st){ if(ans>(ll)1e9) break; t=-t; k=t; ans=max(ans,get(1,0,n,t,n)); ans*=RX[t]; } if(k==-1) return f[1]; return ans%MOD*gt(k-1)%MOD; }

Compilation message (stderr)

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:67:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   67 |  if(k==-1) return f[1];
      |                   ~~~^
horses.cpp:68:24: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   68 |     return ans%MOD*gt(k-1)%MOD;
      |                       ~^~
horses.cpp:68:27: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   68 |     return ans%MOD*gt(k-1)%MOD;
      |            ~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:85:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   85 |  if(k==-1) return f[1];
      |                   ~~~^
horses.cpp:86:24: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   86 |     return ans%MOD*gt(k-1)%MOD;
      |                       ~^~
horses.cpp:86:27: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   86 |     return ans%MOD*gt(k-1)%MOD;
      |            ~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:99:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   99 |  if(k==-1) return f[1];
      |                   ~~~^
horses.cpp:100:24: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  100 |     return ans%MOD*gt(k-1)%MOD;
      |                       ~^~
horses.cpp:100:27: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  100 |     return ans%MOD*gt(k-1)%MOD;
      |            ~~~~~~~~~~~~~~~^~~~
#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...