#include "horses.h"
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pli = pair<ll, int>;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define forsn(i, s, n) for(int i=s; i<(int)n; ++i)
#define PB push_back
#define F first
#define S second
const int MAXN = 500010, MOD = 1000000007;
int n, arr[MAXN], brr[MAXN];
set<int> ones;
pii query(int l, int r){
//cerr << l << ' ' << r << endl;
pii mx={0, -1};
forsn(i, l, r) mx=max(mx, {brr[i], i});
return mx;
}
int pro(int r){
ll ret=1;
forn(i, r+1) ret=(ret*arr[i])%MOD;
return (ret*brr[r])%MOD;
}
int solve(){
ll prod=1;
vector<int> lis;
int sz = ones.size(), pos = n-1;
auto itr = ones.end();
forn(i, sz){
itr = prev(itr);
prod*=arr[*itr];
lis.PB(*itr);
if(prod>1000000010) break;
}
reverse(lis.begin(), lis.end());
pli basic = query(0, n);
if(lis.empty()) return basic.F;
ll p=1;
pli mx={-1, -1};
for(int el:lis){
if(el!=lis.front()) p*=arr[el];
pli opt = query(el, n);
opt.F*=p;
mx = max(mx, opt);
}
if(mx.F > (basic.F / arr[lis.front()])) return pro(mx.S);
else return basic.F;
}
int init(int N, int X[], int Y[]) {
n=N;
forn(i, n){
arr[i]=X[i];
if(arr[i]!=1) ones.insert(i);
}
forn(i, n) brr[i]=Y[i];
return solve();
}
int updateX(int pos, int val) {
if(arr[pos]==1 && val!=1) ones.insert(pos);
if(arr[pos]!=1 && val==1) ones.erase(pos);
arr[pos]=val;
return solve();
}
int updateY(int pos, int val) {
brr[pos]=val;
return solve();
}
Compilation message
horses.cpp: In function 'int pro(int)':
horses.cpp:30:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
30 | return (ret*brr[r])%MOD;
| ~~~~~~~~~~~~^~~~
horses.cpp: In function 'int solve()':
horses.cpp:37:20: warning: conversion from 'std::set<int>::size_type' {aka 'long unsigned int'} to 'int' may change value [-Wconversion]
37 | int sz = ones.size(), pos = n-1;
| ~~~~~~~~~^~
horses.cpp:13:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
13 | #define F first
| ^
horses.cpp:49:31: note: in expansion of macro 'F'
49 | if(lis.empty()) return basic.F;
| ^
horses.cpp:13:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
13 | #define F first
| ^
horses.cpp:60:20: note: in expansion of macro 'F'
60 | else return basic.F;
| ^
horses.cpp:37:24: warning: unused variable 'pos' [-Wunused-variable]
37 | int sz = ones.size(), pos = n-1;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 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 |
8 ms |
340 KB |
Output is correct |
24 |
Correct |
8 ms |
320 KB |
Output is correct |
25 |
Correct |
7 ms |
324 KB |
Output is correct |
26 |
Correct |
7 ms |
408 KB |
Output is correct |
27 |
Correct |
11 ms |
344 KB |
Output is correct |
28 |
Correct |
8 ms |
340 KB |
Output is correct |
29 |
Correct |
10 ms |
320 KB |
Output is correct |
30 |
Correct |
8 ms |
340 KB |
Output is correct |
31 |
Correct |
4 ms |
340 KB |
Output is correct |
32 |
Correct |
7 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1552 ms |
31604 KB |
Time limit exceeded |
2 |
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 |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 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 |
7 ms |
348 KB |
Output is correct |
24 |
Correct |
6 ms |
340 KB |
Output is correct |
25 |
Correct |
7 ms |
340 KB |
Output is correct |
26 |
Correct |
7 ms |
340 KB |
Output is correct |
27 |
Correct |
10 ms |
340 KB |
Output is correct |
28 |
Correct |
7 ms |
320 KB |
Output is correct |
29 |
Correct |
9 ms |
340 KB |
Output is correct |
30 |
Correct |
8 ms |
408 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Execution timed out |
1563 ms |
11992 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 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 |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 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 |
0 ms |
212 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 |
6 ms |
352 KB |
Output is correct |
24 |
Correct |
6 ms |
320 KB |
Output is correct |
25 |
Correct |
7 ms |
340 KB |
Output is correct |
26 |
Correct |
7 ms |
320 KB |
Output is correct |
27 |
Correct |
10 ms |
360 KB |
Output is correct |
28 |
Correct |
7 ms |
324 KB |
Output is correct |
29 |
Correct |
10 ms |
348 KB |
Output is correct |
30 |
Correct |
8 ms |
316 KB |
Output is correct |
31 |
Correct |
3 ms |
324 KB |
Output is correct |
32 |
Correct |
6 ms |
340 KB |
Output is correct |
33 |
Execution timed out |
1547 ms |
33800 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |