# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
738980 |
2023-05-09T18:02:23 Z |
shoryu386 |
Horses (IOI15_horses) |
C++17 |
|
1500 ms |
26076 KB |
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007LL
#include "horses.h"
//hypothesis 1: There is no point in keeping a partial amount of horses. Sell all, or don't bother.
//Let's test this.
//Ok, should be confirmed (passed subtask 1)
//now, running product of X can be really big
//we need to determine the largest value in meow, where meow[i] = Y[i] * prefixProdX[i];
//honestly even Y[i] can be really big (10^9 for both X and Y)
//I also don't really want to touch floating point
//let our two comparison indices be A and B
//without loss of generality, let A < B
//then meow[A] = Y[A] * prefixProdX[A], meow[B] = Y[B] * prefixProdX[B]
//meow[A] < meow[B] iff
//Y[A] * prefixProdX[A] < Y[B] * prefixProdX[B]
//Y[A] < Y[B] * prefixProdX[B] / prefixProdX[A]
//Y[A] < Y[B] * rangeProdX(A+1, B)
//hmm both Y[A] and Y[B] are bounded by 10^9
//meaning if rangeProdX(A+1, B) ever exceeds 10^9, we can safely say meow[B] is greater
//Y is also bounded by 1
#define int long long
#define actlint int32_t
actlint *X, *Y;
int N;
bool st3 = true;
#define MAXN 500001
#define makeMid int mid = (s+e)/2
#define lc(x) (2*x)
#define rc(x) (2*x+1)
#define parent(x) (x/2)
typedef int stdata;
stdata ST[4*MAXN+1] = {0};
inline stdata combine(stdata x, stdata y){
return (x*y)%MOD;
}
void pointSet(int x, stdata y, int index=1, int s=0, int e=N-1){
makeMid;
if (s==e){ ST[index] = y; return; }
if (x <= mid) pointSet(x, y, lc(index), s, mid);
else pointSet(x, y, rc(index), mid+1, e);
ST[index] = combine(ST[lc(index)], ST[rc(index)]);
}
void pointAdd(int x, stdata y, int index=1, int s=0, int e=N-1){
makeMid;
if (s==e){ ST[index] += y; return; }
if (x <= mid) pointAdd(x, y, lc(index), s, mid);
else pointAdd(x, y, rc(index), mid+1, e);
ST[index] = combine(ST[lc(index)], ST[rc(index)]);
}
stdata query(int x, int y, int index=1, int s=0, int e=N-1){
makeMid;
if (s==x && e==y) return ST[index];
if (x <= mid && y > mid) return combine(query(x, mid, lc(index), s, mid), query(mid+1, y, rc(index), mid+1, e));
else if (x <= mid) return query(x, y, lc(index), s, mid);
else return query(x, y, rc(index), mid+1, e);
}
int calc(){
//this is bottleneck of code
//this takes O(N) time, which is too long since we cannot afford O(NM)
//problem that this is meant to solve:
//find max of Y[i] * prefixProdX[i] (in log n time?)
long long best = 0;
long long run = 1;
long long init = 0;
if (st3) init = max(N-33LL, 0LL), best = max(N-33LL, 0LL);
for (int i = init; i < N; i++){
run *= X[i];
if ((int)Y[best] < (int)Y[i] * run){
best = i;
run = 1;
}
}
run = query(0, best);
run *= Y[best]; run %= MOD;
return run;
}
actlint init(actlint hmN, actlint hmX[], actlint hmY[]) {
N = hmN;
X = hmX; Y = hmY;
for (int i = 0; i < N; i++){
if (X[i] < 2) st3 = false;
pointSet(i, X[i]);
}
return calc();
}
actlint updateX(actlint pos, actlint val) {
X[pos] = val;
if (val < 2) st3 = false;
pointSet(pos, val);
return calc();
}
actlint updateY(actlint pos, actlint val) {
Y[pos] = val;
return calc();
}
Compilation message
horses.cpp: In function 'int32_t init(int32_t, int32_t*, int32_t*)':
horses.cpp:104:13: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
104 | return calc();
| ~~~~^~
horses.cpp: In function 'int32_t updateX(int32_t, int32_t)':
horses.cpp:111:13: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
111 | return calc();
| ~~~~^~
horses.cpp: In function 'int32_t updateY(int32_t, int32_t)':
horses.cpp:116:13: warning: conversion from 'long long int' to 'int32_t' {aka 'int'} may change value [-Wconversion]
116 | return calc();
| ~~~~^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
312 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
312 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
316 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
312 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
292 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
5 ms |
340 KB |
Output is correct |
24 |
Correct |
5 ms |
320 KB |
Output is correct |
25 |
Correct |
5 ms |
340 KB |
Output is correct |
26 |
Correct |
5 ms |
340 KB |
Output is correct |
27 |
Correct |
5 ms |
340 KB |
Output is correct |
28 |
Correct |
5 ms |
340 KB |
Output is correct |
29 |
Correct |
5 ms |
340 KB |
Output is correct |
30 |
Correct |
5 ms |
428 KB |
Output is correct |
31 |
Correct |
5 ms |
340 KB |
Output is correct |
32 |
Correct |
5 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
158 ms |
17188 KB |
Output is correct |
2 |
Correct |
192 ms |
26076 KB |
Output is correct |
3 |
Correct |
153 ms |
17120 KB |
Output is correct |
4 |
Correct |
198 ms |
20932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
6 ms |
340 KB |
Output is correct |
24 |
Correct |
5 ms |
324 KB |
Output is correct |
25 |
Correct |
6 ms |
340 KB |
Output is correct |
26 |
Correct |
6 ms |
340 KB |
Output is correct |
27 |
Correct |
6 ms |
340 KB |
Output is correct |
28 |
Correct |
6 ms |
340 KB |
Output is correct |
29 |
Correct |
5 ms |
468 KB |
Output is correct |
30 |
Correct |
5 ms |
340 KB |
Output is correct |
31 |
Correct |
4 ms |
340 KB |
Output is correct |
32 |
Correct |
5 ms |
340 KB |
Output is correct |
33 |
Execution timed out |
1560 ms |
16356 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
312 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
5 ms |
340 KB |
Output is correct |
24 |
Correct |
5 ms |
340 KB |
Output is correct |
25 |
Correct |
5 ms |
340 KB |
Output is correct |
26 |
Correct |
6 ms |
348 KB |
Output is correct |
27 |
Correct |
5 ms |
340 KB |
Output is correct |
28 |
Correct |
5 ms |
324 KB |
Output is correct |
29 |
Correct |
5 ms |
340 KB |
Output is correct |
30 |
Correct |
5 ms |
340 KB |
Output is correct |
31 |
Correct |
5 ms |
340 KB |
Output is correct |
32 |
Correct |
5 ms |
340 KB |
Output is correct |
33 |
Correct |
147 ms |
17112 KB |
Output is correct |
34 |
Correct |
196 ms |
25980 KB |
Output is correct |
35 |
Correct |
157 ms |
17164 KB |
Output is correct |
36 |
Correct |
203 ms |
21000 KB |
Output is correct |
37 |
Execution timed out |
1555 ms |
16356 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |