#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 {
long double aib[MAX_N + 1];
void init() {
for ( int i = 0; i <= MAX_N; i++ )
aib[i] = 0;
}
void update( int i, long double x ) {
while ( i <= MAX_N ) {
aib[i] += x;
i += (i & -i);
}
}
long double query( int i ) {
long 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 n;
int x[MAX_N + 1], y[MAX_N + 1];
double val[MAX_N + 1];
set<pair<long double, int>> s;
void calc() {
s.clear();
horses.init();
cost.init();
for ( int i = 1; i <= n; i++ ) {
horses.update( i, x[i] );
cost.update( i, log( x[i] ) );
val[i] = cost.query( i ) + log( y[i] );
s.insert( { val[i], i } );
}
}
void calc2() {
s.clear();
for ( int i = 1; i <= n; i++ ) {
s.insert( { cost.query( i ) + log( y[i] ), i } );
}
}
int answer() {
int i = s.rbegin()->second;
return (long long)horses.query( i ) * y[i] % MOD;
}
int init( int N, int X[], int Y[] ) {
n = N;
for ( int i = n - 1; i >= 0; i-- )
x[i + 1] = X[i], y[i + 1] = Y[i];
calc();
return answer();
}
int updateX( int pos, int a ) {
int i = pos + 1;
s.erase( { val[i], i } );
cost.update( i, -log( x[i] ) );
horses.update( i, inv( x[i] ) );
x[i] = a;
val[i] = cost.query( i ) + log( y[i] );
cost.update( i, log( x[i] ) );
horses.update( i, x[i] );
s.insert( { val[i], i } );
calc2();
return answer();
}
int updateY( int pos, int a ) {
int i = pos + 1;
s.erase( { val[i], i } );
y[i] = a;
val[i] = cost.query( i ) + log( y[i] );
s.insert( { val[i], i } );
return answer();
}
Compilation message
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:64:26: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
64 | p = (long long)p * p % MOD;
| ~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:66:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
66 | p = (long long)p * a % MOD;
| ~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void calc()':
horses.cpp:88:34: warning: conversion from 'long double' to 'double' may change value [-Wfloat-conversion]
88 | val[i] = cost.query( i ) + log( y[i] );
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
horses.cpp: In function 'int answer()':
horses.cpp:101:48: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
101 | return (long long)horses.query( i ) * y[i] % MOD;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:123:30: warning: conversion from 'long double' to 'double' may change value [-Wfloat-conversion]
123 | val[i] = cost.query( i ) + log( y[i] );
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:138:30: warning: conversion from 'long double' to 'double' may change value [-Wfloat-conversion]
138 | val[i] = cost.query( i ) + log( y[i] );
| ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
15708 KB |
Output is correct |
2 |
Correct |
3 ms |
15708 KB |
Output is correct |
3 |
Correct |
4 ms |
15812 KB |
Output is correct |
4 |
Correct |
2 ms |
15960 KB |
Output is correct |
5 |
Correct |
3 ms |
15812 KB |
Output is correct |
6 |
Correct |
3 ms |
15704 KB |
Output is correct |
7 |
Correct |
4 ms |
15876 KB |
Output is correct |
8 |
Correct |
3 ms |
15708 KB |
Output is correct |
9 |
Correct |
2 ms |
15708 KB |
Output is correct |
10 |
Correct |
2 ms |
15708 KB |
Output is correct |
11 |
Correct |
3 ms |
15708 KB |
Output is correct |
12 |
Correct |
3 ms |
15708 KB |
Output is correct |
13 |
Correct |
4 ms |
15708 KB |
Output is correct |
14 |
Correct |
3 ms |
15708 KB |
Output is correct |
15 |
Correct |
2 ms |
15708 KB |
Output is correct |
16 |
Correct |
3 ms |
15708 KB |
Output is correct |
17 |
Correct |
2 ms |
15708 KB |
Output is correct |
18 |
Correct |
2 ms |
15708 KB |
Output is correct |
19 |
Correct |
3 ms |
15816 KB |
Output is correct |
20 |
Correct |
3 ms |
15708 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
15708 KB |
Output is correct |
2 |
Correct |
3 ms |
15972 KB |
Output is correct |
3 |
Correct |
3 ms |
15708 KB |
Output is correct |
4 |
Correct |
2 ms |
15708 KB |
Output is correct |
5 |
Correct |
3 ms |
15808 KB |
Output is correct |
6 |
Correct |
3 ms |
15708 KB |
Output is correct |
7 |
Correct |
3 ms |
15708 KB |
Output is correct |
8 |
Correct |
3 ms |
15708 KB |
Output is correct |
9 |
Correct |
2 ms |
15708 KB |
Output is correct |
10 |
Correct |
3 ms |
15708 KB |
Output is correct |
11 |
Correct |
3 ms |
15812 KB |
Output is correct |
12 |
Correct |
3 ms |
15708 KB |
Output is correct |
13 |
Correct |
3 ms |
15704 KB |
Output is correct |
14 |
Correct |
2 ms |
15708 KB |
Output is correct |
15 |
Correct |
3 ms |
15708 KB |
Output is correct |
16 |
Correct |
3 ms |
15708 KB |
Output is correct |
17 |
Correct |
3 ms |
15708 KB |
Output is correct |
18 |
Correct |
3 ms |
15708 KB |
Output is correct |
19 |
Correct |
3 ms |
15692 KB |
Output is correct |
20 |
Correct |
3 ms |
15708 KB |
Output is correct |
21 |
Correct |
3 ms |
15708 KB |
Output is correct |
22 |
Correct |
3 ms |
15708 KB |
Output is correct |
23 |
Correct |
63 ms |
15708 KB |
Output is correct |
24 |
Incorrect |
59 ms |
15704 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
206 ms |
62096 KB |
Output is correct |
2 |
Execution timed out |
1539 ms |
61008 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
15704 KB |
Output is correct |
2 |
Correct |
3 ms |
15708 KB |
Output is correct |
3 |
Correct |
2 ms |
15708 KB |
Output is correct |
4 |
Correct |
3 ms |
15708 KB |
Output is correct |
5 |
Correct |
3 ms |
15708 KB |
Output is correct |
6 |
Correct |
2 ms |
15708 KB |
Output is correct |
7 |
Correct |
3 ms |
15808 KB |
Output is correct |
8 |
Correct |
2 ms |
15708 KB |
Output is correct |
9 |
Correct |
3 ms |
15704 KB |
Output is correct |
10 |
Correct |
3 ms |
15704 KB |
Output is correct |
11 |
Correct |
2 ms |
15832 KB |
Output is correct |
12 |
Correct |
3 ms |
15704 KB |
Output is correct |
13 |
Correct |
3 ms |
15708 KB |
Output is correct |
14 |
Correct |
3 ms |
15708 KB |
Output is correct |
15 |
Correct |
3 ms |
15708 KB |
Output is correct |
16 |
Correct |
3 ms |
15704 KB |
Output is correct |
17 |
Correct |
3 ms |
15708 KB |
Output is correct |
18 |
Correct |
3 ms |
15704 KB |
Output is correct |
19 |
Correct |
3 ms |
15708 KB |
Output is correct |
20 |
Correct |
2 ms |
15708 KB |
Output is correct |
21 |
Correct |
3 ms |
15708 KB |
Output is correct |
22 |
Correct |
3 ms |
15668 KB |
Output is correct |
23 |
Correct |
62 ms |
15708 KB |
Output is correct |
24 |
Incorrect |
68 ms |
15924 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
15708 KB |
Output is correct |
2 |
Correct |
3 ms |
15708 KB |
Output is correct |
3 |
Correct |
3 ms |
15704 KB |
Output is correct |
4 |
Correct |
3 ms |
15708 KB |
Output is correct |
5 |
Correct |
3 ms |
15704 KB |
Output is correct |
6 |
Correct |
3 ms |
15708 KB |
Output is correct |
7 |
Correct |
4 ms |
15812 KB |
Output is correct |
8 |
Correct |
3 ms |
15704 KB |
Output is correct |
9 |
Correct |
2 ms |
15708 KB |
Output is correct |
10 |
Correct |
3 ms |
15708 KB |
Output is correct |
11 |
Correct |
3 ms |
15708 KB |
Output is correct |
12 |
Correct |
3 ms |
15708 KB |
Output is correct |
13 |
Correct |
3 ms |
15708 KB |
Output is correct |
14 |
Correct |
3 ms |
15708 KB |
Output is correct |
15 |
Correct |
3 ms |
15708 KB |
Output is correct |
16 |
Correct |
2 ms |
15708 KB |
Output is correct |
17 |
Correct |
3 ms |
15720 KB |
Output is correct |
18 |
Correct |
2 ms |
15704 KB |
Output is correct |
19 |
Correct |
3 ms |
15708 KB |
Output is correct |
20 |
Correct |
3 ms |
15708 KB |
Output is correct |
21 |
Correct |
3 ms |
15708 KB |
Output is correct |
22 |
Correct |
2 ms |
15708 KB |
Output is correct |
23 |
Correct |
62 ms |
15916 KB |
Output is correct |
24 |
Incorrect |
60 ms |
15708 KB |
Output isn't correct |
25 |
Halted |
0 ms |
0 KB |
- |