#include "horses.h"
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 500005;
const ll mod = 1e9 + 7;
int n;
set<int> changes;
vector<int> x , y;
ll xmult = 1;
int T[1 << 20];
ll Pow(ll a, ll p)
{
if (p == 0) return 1;
if (p & 1) return (a * Pow(a, p - 1)) % mod;
return Pow((a * a) % mod, p / 2);
}
inline ll Inv(ll a) {return Pow(a % mod, mod - 2);}
void upd(int idx , int v , int l = 0 , int r = n - 1 , int pos = 0){
if(l == r){
T[pos] = v;
return;
}
int mid = (l + r) >> 1;
if(idx <= mid) upd(idx , v , l , mid , pos * 2 + 1);
else upd(idx , v , mid + 1 , r , pos * 2 + 2);
T[pos] = max(T[pos * 2 + 1] , T[pos * 2 + 2]);
}
int get(int L , int R , int l = 0 , int r= n -1 , int pos = 0){
if(r < L || R < l) return -2e9;
if(L <= l && r <= R) return T[pos];
int mid = (l + r) >> 1;
return max(get(L , R , l , mid , pos * 2 + 1) , get(L , R , mid + 1 , r , pos *2 +2));
}
struct div{
ll a , b;
bool operator<(const div&Q) const {
return a * Q.b < Q.a * b;
}
}mx;
int solve(){
mx.a = 0; mx.b = 1;
ll curxmult = 1;
for(auto it = changes.rbegin(); it != changes.rend() && curxmult < 1000000000; ++it){
int i = *it;
int j = (it == changes.rbegin() ? n : *prev(it));
mx = max(mx , {get(i, j - 1) , curxmult});
curxmult *= x[i];
}
ll res = (mx.a * Inv(mx.b)) % mod;
return res = (res * xmult) % mod;
}
int init(int N , int X[] , int Y[]){
n = N;
x.assign(X , X + N);
y.assign(Y , Y + N);
for(int i = 0; i < n; ++i){
upd(i , y[i]);
}
changes.insert(0);
for(int i = 0; i < n; ++i){
if(x[i] > 1){
changes.insert(i);
xmult = (xmult * x[i]) % mod;
}
}
return solve();
}
int updateX(int pos , int val){
if(pos && x[pos] > 1 && val == 1) changes.erase(pos);
if(pos && x[pos] == 1 && val > 1) changes.insert(pos);
xmult = (xmult * Inv(x[pos])) % mod;
xmult = (xmult * (x[pos] = val))% mod;
return solve();
}
int updateY(int pos , int val){
upd(pos , (y[pos] = val));
return solve();
}
///int main (){}
Compilation message
horses.cpp: In function 'int solve()':
horses.cpp:57:16: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return res = (res * xmult) % mod;
~~~~^~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:59:35: warning: declaration of 'N' shadows a global declaration [-Wshadow]
int init(int N , int X[] , int Y[]){
^
horses.cpp:7:11: note: shadowed declaration is here
const int N = 500005;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
5 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
5 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
4 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
256 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
256 KB |
Output is correct |
2 |
Correct |
4 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
384 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
4 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
5 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
256 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
256 KB |
Output is correct |
16 |
Correct |
4 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
256 KB |
Output is correct |
18 |
Correct |
5 ms |
384 KB |
Output is correct |
19 |
Correct |
4 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
512 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
5 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
26 |
Correct |
6 ms |
384 KB |
Output is correct |
27 |
Correct |
8 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
512 KB |
Output is correct |
29 |
Correct |
6 ms |
384 KB |
Output is correct |
30 |
Correct |
7 ms |
384 KB |
Output is correct |
31 |
Correct |
7 ms |
384 KB |
Output is correct |
32 |
Correct |
8 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
769 ms |
40576 KB |
Output is correct |
2 |
Correct |
323 ms |
39576 KB |
Output is correct |
3 |
Correct |
348 ms |
39672 KB |
Output is correct |
4 |
Correct |
383 ms |
39672 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
384 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
256 KB |
Output is correct |
4 |
Correct |
4 ms |
384 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
4 ms |
384 KB |
Output is correct |
8 |
Correct |
5 ms |
256 KB |
Output is correct |
9 |
Correct |
4 ms |
256 KB |
Output is correct |
10 |
Correct |
4 ms |
256 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
256 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
4 ms |
256 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
256 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
384 KB |
Output is correct |
23 |
Correct |
6 ms |
384 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
384 KB |
Output is correct |
26 |
Correct |
5 ms |
384 KB |
Output is correct |
27 |
Correct |
8 ms |
384 KB |
Output is correct |
28 |
Correct |
6 ms |
384 KB |
Output is correct |
29 |
Correct |
6 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
384 KB |
Output is correct |
31 |
Correct |
7 ms |
384 KB |
Output is correct |
32 |
Correct |
9 ms |
384 KB |
Output is correct |
33 |
Correct |
114 ms |
15584 KB |
Output is correct |
34 |
Correct |
109 ms |
15528 KB |
Output is correct |
35 |
Correct |
253 ms |
38956 KB |
Output is correct |
36 |
Correct |
245 ms |
38904 KB |
Output is correct |
37 |
Correct |
158 ms |
14584 KB |
Output is correct |
38 |
Correct |
166 ms |
27384 KB |
Output is correct |
39 |
Correct |
99 ms |
14328 KB |
Output is correct |
40 |
Correct |
225 ms |
39032 KB |
Output is correct |
41 |
Correct |
130 ms |
14328 KB |
Output is correct |
42 |
Correct |
143 ms |
14480 KB |
Output is correct |
43 |
Correct |
221 ms |
38880 KB |
Output is correct |
44 |
Correct |
220 ms |
38776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
256 KB |
Output is correct |
2 |
Correct |
5 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
384 KB |
Output is correct |
4 |
Correct |
5 ms |
256 KB |
Output is correct |
5 |
Correct |
5 ms |
384 KB |
Output is correct |
6 |
Correct |
5 ms |
384 KB |
Output is correct |
7 |
Correct |
5 ms |
384 KB |
Output is correct |
8 |
Correct |
4 ms |
256 KB |
Output is correct |
9 |
Correct |
5 ms |
384 KB |
Output is correct |
10 |
Correct |
4 ms |
384 KB |
Output is correct |
11 |
Correct |
4 ms |
384 KB |
Output is correct |
12 |
Correct |
4 ms |
384 KB |
Output is correct |
13 |
Correct |
4 ms |
384 KB |
Output is correct |
14 |
Correct |
5 ms |
384 KB |
Output is correct |
15 |
Correct |
4 ms |
384 KB |
Output is correct |
16 |
Correct |
5 ms |
384 KB |
Output is correct |
17 |
Correct |
5 ms |
384 KB |
Output is correct |
18 |
Correct |
4 ms |
384 KB |
Output is correct |
19 |
Correct |
5 ms |
384 KB |
Output is correct |
20 |
Correct |
5 ms |
384 KB |
Output is correct |
21 |
Correct |
5 ms |
384 KB |
Output is correct |
22 |
Correct |
4 ms |
256 KB |
Output is correct |
23 |
Correct |
6 ms |
432 KB |
Output is correct |
24 |
Correct |
5 ms |
384 KB |
Output is correct |
25 |
Correct |
6 ms |
512 KB |
Output is correct |
26 |
Correct |
6 ms |
512 KB |
Output is correct |
27 |
Correct |
8 ms |
384 KB |
Output is correct |
28 |
Correct |
7 ms |
384 KB |
Output is correct |
29 |
Correct |
6 ms |
384 KB |
Output is correct |
30 |
Correct |
6 ms |
384 KB |
Output is correct |
31 |
Correct |
7 ms |
384 KB |
Output is correct |
32 |
Correct |
8 ms |
384 KB |
Output is correct |
33 |
Correct |
773 ms |
40056 KB |
Output is correct |
34 |
Correct |
320 ms |
39800 KB |
Output is correct |
35 |
Correct |
357 ms |
39800 KB |
Output is correct |
36 |
Correct |
385 ms |
39800 KB |
Output is correct |
37 |
Correct |
110 ms |
15584 KB |
Output is correct |
38 |
Correct |
112 ms |
15608 KB |
Output is correct |
39 |
Correct |
259 ms |
38776 KB |
Output is correct |
40 |
Correct |
246 ms |
38904 KB |
Output is correct |
41 |
Correct |
161 ms |
14584 KB |
Output is correct |
42 |
Correct |
168 ms |
27372 KB |
Output is correct |
43 |
Correct |
96 ms |
14328 KB |
Output is correct |
44 |
Correct |
227 ms |
38780 KB |
Output is correct |
45 |
Correct |
131 ms |
14456 KB |
Output is correct |
46 |
Correct |
151 ms |
14476 KB |
Output is correct |
47 |
Correct |
227 ms |
38648 KB |
Output is correct |
48 |
Correct |
214 ms |
38652 KB |
Output is correct |
49 |
Correct |
221 ms |
17144 KB |
Output is correct |
50 |
Correct |
211 ms |
17272 KB |
Output is correct |
51 |
Correct |
420 ms |
39544 KB |
Output is correct |
52 |
Correct |
300 ms |
39416 KB |
Output is correct |
53 |
Correct |
780 ms |
17144 KB |
Output is correct |
54 |
Correct |
388 ms |
29944 KB |
Output is correct |
55 |
Correct |
203 ms |
15224 KB |
Output is correct |
56 |
Correct |
340 ms |
39392 KB |
Output is correct |
57 |
Correct |
495 ms |
15992 KB |
Output is correct |
58 |
Correct |
682 ms |
15992 KB |
Output is correct |
59 |
Correct |
217 ms |
38264 KB |
Output is correct |