Submission #984211

#TimeUsernameProblemLanguageResultExecution timeMemory
984211LucaIlieHorses (IOI15_horses)C++17
17 / 100
362 ms56284 KiB
#include "horses.h" #include <bits/stdc++.h> using namespace std; const int MAX_N = 5e5; const int MOD = 1e9 + 7; struct AIB1 { int aib[MAX_N + 1]; void init() { for ( int i = 0; i <= MAX_N; i++ ) aib[i] = 1; } void update( int i, int x ) { while ( i <= MAX_N ) { aib[i] = (long long)aib[i] * x % MOD; i += (i & -i); } } int query( int i ) { int p = 1; while ( i > 0 ) { p = (long long)p * aib[i] % MOD; i -= (i & -i); } return p; } } horses; struct AIB2 { double aib[MAX_N + 1]; void update( int i, double x ) { while ( i <= MAX_N ) { aib[i] += x; i += (i & -i); } } double query( int i ) { double p = 0; while ( i > 0 ) { p += aib[i]; i -= (i & -i); } return p; } } cost; int lgPut( int a, int n ) { if ( n == 0 ) return 1; int p = lgPut( a, n / 2 ); p = (long long)p * p % MOD; if ( n % 2 == 1 ) p = (long long)p * a % MOD; return p; } int inv( int x ) { return lgPut( x, MOD - 2 ); } int x[MAX_N + 1], y[MAX_N + 1]; set<pair<double, int>> s; int answer() { int i = s.rbegin()->second; return (long long)horses.query( i ) * y[i] % MOD; } int init( int n, int X[], int Y[] ) { for ( int i = n - 1; i >= 0; i-- ) x[i + 1] = X[i], y[i + 1] = Y[i]; horses.init(); for ( int i = 1; i <= n; i++ ) { horses.update( i, x[i] ); cost.update( i, log( x[i] ) ); s.insert( { cost.query( i ) + log( y[i] ), i } ); } return answer(); } int updateX( int pos, int val ) { int i = pos + 1; s.erase( { cost.query( i ) + log( y[i] ), i } ); cost.update( i, -log( x[i] ) ); horses.update( i, inv( x[i] ) ); x[i] = val; cost.update( i, log( x[i] ) ); horses.update( i, x[i] ); s.insert( { cost.query( i ) + log( y[i] ), i } ); return answer(); } int updateY( int pos, int val ) { int i = pos + 1; s.erase( { cost.query( i ) + log( y[i] ), i } ); y[i] = val; s.insert( { cost.query( i ) + log( y[i] ), i } ); return answer(); }

Compilation message (stderr)

horses.cpp: In member function 'void AIB1::update(int, int)':
horses.cpp:19:44: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   19 |             aib[i] = (long long)aib[i] * x % MOD;
      |                      ~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In member function 'int AIB1::query(int)':
horses.cpp:27:39: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   27 |             p = (long long)p * aib[i] % MOD;
      |                 ~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int lgPut(int, int)':
horses.cpp:59:26: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   59 |     p = (long long)p * p % MOD;
      |         ~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:61:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   61 |         p = (long long)p * a % MOD;
      |             ~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int answer()':
horses.cpp:75:48: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
   75 |     return (long long)horses.query( i ) * y[i] % 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...