#include "horses.h"
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define ld long double
#define mp make_pair
#define F first
#define S second
#define pii pair<ll,ll>
using namespace :: std;
const ll maxn=5e5+500;
const ll inf=1e9+6;
const ll mod=1e9+7;
ll modizarb(long long a,long long b){return (a*b)%mod;}
ll y[maxn];
ll seg[maxn*4];
void bild(ll l,ll r,ll node){
if(l+1==r){
seg[node]=y[l];
return;
}
ll mid=(l+r)/2;
bild(l,mid,2*node);
bild(mid,r,2*node+1);
seg[node]=max(seg[2*node],seg[2*node+1]);
}
void update(ll l,ll r,ll node,ll pos){
if(l+1==r){
seg[node]=y[l];
return;
}
ll mid=(l+r)/2;
if(pos<mid)
update(l,mid,2*node,pos);
else
update(mid,r,2*node+1,pos);
seg[node]=max(seg[2*node],seg[2*node+1]);
}
ll findMx(ll l,ll r,ll L,ll R,ll node){
if(l<=L && R<=r){
return seg[node];
}
if(r<=L || R<=l){
return 0;
}
ll mid=(L+R)/2;
return max(findMx(l,r,L,mid,2*node),findMx(l,r,mid,R,2*node+1));
}
set<ll> st;
ll x[maxn];
ll rx[maxn];
ll n,Z;
ll poww(ll a,ll b){
ll ans=1;
while(b){
if(b&1){
ans=(ans*a)%mod;
}
b>>=1;
a=(a*a)%mod;
}
return ans;
}
ll findAns(){
auto it=st.end();
ll last=n;
ll ans=0;
ll t=Z;
bool br=0;
while(it!=st.begin()){
it--;
ll v=(*it);
ll yy=findMx(v,last,0,n,1);
ans=max(ans,yy);
if(ans*x[v]>inf){
br=1;
break;
}
ans*=x[v];
t=modizarb(t,rx[v]);
last=v;
}
if(!br){
ll v=0;
ll yy=findMx(v,last,0,n,1);
ans=max(ans,yy);
}
return modizarb(ans,t);
}
int init(int N, int X[], int Y[]){
n=N;
Z=1;
for(ll i=0;i<n;i++){
x[i]=X[i];
Z=modizarb(Z,X[i]);
rx[i]=poww(x[i],mod-2);
y[i]=Y[i];
if(x[i]!=1)st.insert(i);
}
bild(0,n,1);
return findAns();
}
int updateX(int pos, int val) {
Z=modizarb(Z,rx[pos]);
if(x[pos]!=1 && val==1){
st.erase(pos);
}
if(x[pos]==1 && val!=1){
st.insert(pos);
}
x[pos]=val;
Z=modizarb(Z,val);
rx[pos]=poww(x[pos],mod-2);
return findAns();
}
int updateY(int pos, int val){
y[pos]=val;
update(0,n,1,pos);
return findAns();
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:108:19: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return findAns();
~~~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:121:19: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return findAns();
~~~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:126:19: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return findAns();
~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
504 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
3 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
348 KB |
Output is correct |
3 |
Correct |
3 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
376 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
508 KB |
Output is correct |
24 |
Correct |
3 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
5 ms |
504 KB |
Output is correct |
28 |
Correct |
4 ms |
504 KB |
Output is correct |
29 |
Correct |
3 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
504 KB |
Output is correct |
31 |
Correct |
4 ms |
504 KB |
Output is correct |
32 |
Correct |
5 ms |
504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
862 ms |
49256 KB |
Output is correct |
2 |
Correct |
394 ms |
49016 KB |
Output is correct |
3 |
Correct |
431 ms |
49144 KB |
Output is correct |
4 |
Correct |
366 ms |
49016 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
380 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
3 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
2 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
504 KB |
Output is correct |
24 |
Correct |
3 ms |
376 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
4 ms |
504 KB |
Output is correct |
29 |
Correct |
3 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
504 KB |
Output is correct |
31 |
Correct |
5 ms |
380 KB |
Output is correct |
32 |
Correct |
5 ms |
504 KB |
Output is correct |
33 |
Correct |
130 ms |
24704 KB |
Output is correct |
34 |
Correct |
129 ms |
24824 KB |
Output is correct |
35 |
Correct |
335 ms |
48264 KB |
Output is correct |
36 |
Correct |
330 ms |
48120 KB |
Output is correct |
37 |
Correct |
185 ms |
24696 KB |
Output is correct |
38 |
Correct |
293 ms |
36504 KB |
Output is correct |
39 |
Correct |
122 ms |
24440 KB |
Output is correct |
40 |
Correct |
319 ms |
48248 KB |
Output is correct |
41 |
Correct |
154 ms |
24696 KB |
Output is correct |
42 |
Correct |
174 ms |
24708 KB |
Output is correct |
43 |
Correct |
305 ms |
47976 KB |
Output is correct |
44 |
Correct |
304 ms |
48012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Correct |
2 ms |
380 KB |
Output is correct |
11 |
Correct |
2 ms |
376 KB |
Output is correct |
12 |
Correct |
2 ms |
376 KB |
Output is correct |
13 |
Correct |
2 ms |
376 KB |
Output is correct |
14 |
Correct |
2 ms |
376 KB |
Output is correct |
15 |
Correct |
2 ms |
376 KB |
Output is correct |
16 |
Correct |
2 ms |
376 KB |
Output is correct |
17 |
Correct |
2 ms |
376 KB |
Output is correct |
18 |
Correct |
2 ms |
376 KB |
Output is correct |
19 |
Correct |
3 ms |
376 KB |
Output is correct |
20 |
Correct |
2 ms |
376 KB |
Output is correct |
21 |
Correct |
2 ms |
376 KB |
Output is correct |
22 |
Correct |
2 ms |
376 KB |
Output is correct |
23 |
Correct |
3 ms |
504 KB |
Output is correct |
24 |
Correct |
3 ms |
504 KB |
Output is correct |
25 |
Correct |
3 ms |
504 KB |
Output is correct |
26 |
Correct |
3 ms |
504 KB |
Output is correct |
27 |
Correct |
5 ms |
376 KB |
Output is correct |
28 |
Correct |
3 ms |
504 KB |
Output is correct |
29 |
Correct |
3 ms |
376 KB |
Output is correct |
30 |
Correct |
3 ms |
504 KB |
Output is correct |
31 |
Correct |
4 ms |
376 KB |
Output is correct |
32 |
Correct |
5 ms |
376 KB |
Output is correct |
33 |
Correct |
849 ms |
49016 KB |
Output is correct |
34 |
Correct |
398 ms |
49068 KB |
Output is correct |
35 |
Correct |
429 ms |
49140 KB |
Output is correct |
36 |
Correct |
365 ms |
48948 KB |
Output is correct |
37 |
Correct |
132 ms |
24696 KB |
Output is correct |
38 |
Correct |
129 ms |
24696 KB |
Output is correct |
39 |
Correct |
340 ms |
48004 KB |
Output is correct |
40 |
Correct |
326 ms |
48164 KB |
Output is correct |
41 |
Correct |
185 ms |
24828 KB |
Output is correct |
42 |
Correct |
214 ms |
36496 KB |
Output is correct |
43 |
Correct |
121 ms |
24440 KB |
Output is correct |
44 |
Correct |
310 ms |
48120 KB |
Output is correct |
45 |
Correct |
154 ms |
24696 KB |
Output is correct |
46 |
Correct |
173 ms |
24696 KB |
Output is correct |
47 |
Correct |
302 ms |
48184 KB |
Output is correct |
48 |
Correct |
304 ms |
48016 KB |
Output is correct |
49 |
Correct |
223 ms |
26616 KB |
Output is correct |
50 |
Correct |
204 ms |
26616 KB |
Output is correct |
51 |
Correct |
488 ms |
49124 KB |
Output is correct |
52 |
Correct |
376 ms |
49016 KB |
Output is correct |
53 |
Correct |
804 ms |
26568 KB |
Output is correct |
54 |
Correct |
364 ms |
39564 KB |
Output is correct |
55 |
Correct |
212 ms |
24824 KB |
Output is correct |
56 |
Correct |
400 ms |
49144 KB |
Output is correct |
57 |
Correct |
543 ms |
25600 KB |
Output is correct |
58 |
Correct |
732 ms |
25720 KB |
Output is correct |
59 |
Correct |
306 ms |
48088 KB |
Output is correct |