Submission #726911

#TimeUsernameProblemLanguageResultExecution timeMemory
726911Yell0Horses (IOI15_horses)C++17
17 / 100
66 ms16872 KiB
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
ll modinv(ll a) {
  ll res=1;
  for(ll i=0;(1LL<<i)<=MOD-2;++i) {
    if((MOD-2)&(1LL<<i)) res=res*a%MOD;
    a=a*a%MOD;
  }
  return res;
}
 
int N;
vector<ll> bit,X,Y;
void upd(int i,int a) {
  for(;i<=N;i+=-i&i) bit[i]=bit[i]*a%MOD;
}
ll qry(int i) {
  ll res=1;
  for(;i>0;i-=-i&i) res=res*bit[i]%MOD;
  return res;
}
 
int init(int n,int x[],int y[]) {
  N=n;
  bit.resize(N+2,1);
  X.resize(N+2,1);
  Y.resize(N+2,1);
  for(int i=1;i<=N;++i) {
    upd(i,x[i-1]);
    X[i]=x[i-1];
    Y[i]=y[i-1];
  }
  ll pfx=1,mx=0,sfx=1;
  int mxi,sti=N;
  for(int i=N;i>0;--i) {
    sfx*=X[i];
    if(sfx>(ll)1e9) break;
    sti=i;
  }
  for(int i=sti;i<=N;++i) {
    pfx*=X[i];
    if(pfx*Y[i]>mx) {
      mxi=i;
      mx=pfx*Y[i];
    }
  }
  return qry(mxi)*Y[mxi]%MOD;
}
int updateX(int i,int a) {
  ++i;
  upd(i,modinv(X[i])*a%MOD);
  X[i]=a;
  ll pfx=1,mx=0,sfx=1;
  int mxi,sti=N;
  for(int i=N;i>0;--i) {
    sfx*=X[i];
    if(sfx>(ll)1e9) break;
    sti=i;
  }
  for(int i=sti;i<=N;++i) {
    pfx*=X[i];
    if(pfx*Y[i]>mx) {
      mxi=i;
      mx=pfx*Y[i];
    }
  }
  return qry(mxi)*Y[mxi]%MOD;
}
int updateY(int i,int a) {
  ++i;
  Y[i]=a;
  ll pfx=1,mx=0,sfx=1;
  int mxi,sti=N;
  for(int i=N;i>0;--i) {
    sfx*=X[i];
    if(sfx>(ll)1e9) break;
    sti=i;
  }
  for(int i=sti;i<=N;++i) {
    pfx*=X[i];
    if(pfx*Y[i]>mx) {
      mxi=i;
      mx=pfx*Y[i];
    }
  }
  return qry(mxi)*Y[mxi]%MOD;
}

Compilation message (stderr)

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:50:25: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   50 |   return qry(mxi)*Y[mxi]%MOD;
      |          ~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:54:23: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   54 |   upd(i,modinv(X[i])*a%MOD);
      |         ~~~~~~~~~~~~~~^~~~
horses.cpp:58:11: warning: declaration of 'int i' shadows a parameter [-Wshadow]
   58 |   for(int i=N;i>0;--i) {
      |           ^
horses.cpp:52:17: note: shadowed declaration is here
   52 | int updateX(int i,int a) {
      |             ~~~~^
horses.cpp:63:11: warning: declaration of 'int i' shadows a parameter [-Wshadow]
   63 |   for(int i=sti;i<=N;++i) {
      |           ^
horses.cpp:52:17: note: shadowed declaration is here
   52 | int updateX(int i,int a) {
      |             ~~~~^
horses.cpp:70:25: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   70 |   return qry(mxi)*Y[mxi]%MOD;
      |          ~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:77:11: warning: declaration of 'int i' shadows a parameter [-Wshadow]
   77 |   for(int i=N;i>0;--i) {
      |           ^
horses.cpp:72:17: note: shadowed declaration is here
   72 | int updateY(int i,int a) {
      |             ~~~~^
horses.cpp:82:11: warning: declaration of 'int i' shadows a parameter [-Wshadow]
   82 |   for(int i=sti;i<=N;++i) {
      |           ^
horses.cpp:72:17: note: shadowed declaration is here
   72 | int updateY(int i,int a) {
      |             ~~~~^
horses.cpp:89:25: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
   89 |   return qry(mxi)*Y[mxi]%MOD;
      |          ~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:70:24: warning: 'mxi' may be used uninitialized in this function [-Wmaybe-uninitialized]
   70 |   return qry(mxi)*Y[mxi]%MOD;
      |                        ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:89:24: warning: 'mxi' may be used uninitialized in this function [-Wmaybe-uninitialized]
   89 |   return qry(mxi)*Y[mxi]%MOD;
      |                        ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:50:24: warning: 'mxi' may be used uninitialized in this function [-Wmaybe-uninitialized]
   50 |   return qry(mxi)*Y[mxi]%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...