#include "horses.h"
#include <bits/stdc++.h>
#define lc v<<1
#define rc v<<1|1
using ll = long long int;
using namespace std;
const int MOD = 1000000007, MN = 5e5 + 10;
ll pow(ll x, ll y, ll mod){
ll ans=1;
while (y != 0) {
if (y & 1) ans = ans * x % mod;
y >>= 1;
x = x * x % mod;
}
return ans;
}
ll f[MN*4],g[MN],RX[MN];
int n;
set<int> st;
void update(int v, int l, int r, int p, ll x){
if(r-l==1){
f[v]=x;
return;
}
int m=(l+r)>>1;
if(p<m) update(lc,l,m,p,x);
else update(rc,m,r,p,x);
f[v]=max(f[lc],f[rc]);
}
ll get(int v, int l, int r, int tl, int tr){
if(l>=tr || tl>=r || tl>=tr) return 0;
if(l>=tl && r<=tr) return f[v];
int m=(l+r)>>1;
return max(get(lc,l,m,tl,tr),get(rc,m,r,tl,tr));
}
void upd(int t, ll x){
for(t+=5; t<MN; t+=t&-t) g[t]=g[t]*x%MOD;
}
ll gt(int t, ll x=1){
for(t+=5; t; t-=t&-t) x=x*g[t]%MOD;
return x;
}
int init(int N, int X[], int Y[]) {
n=N;
for(ll i=0; i<MN; i++) g[i]=1;
for(int i=0; i<N; i++){
update(1,0,n,i,Y[i]);
upd(i,X[i]);
RX[i]=X[i];
if(X[i]>1) st.insert(-i);
}
ll ans=0,k=-1;
for(int t : st){
if(ans>(ll)1e9) break;
t=-t;
k=t;
ans=max(ans,get(1,0,n,t,n));
ans*=RX[t];
}
ans=ans%MOD*gt(k-1)%MOD;
if(k==-1) return f[1];
return ans;
}
int updateX(int pos, int val) {
ll x=pow(RX[pos],MOD-2,MOD)*val%MOD;
upd(pos,x);
RX[pos]=val;
if(val>1) st.insert(-pos);
else st.erase(-pos);
ll ans=0,k=-1;
for(int t : st){
if(ans>(ll)1e9) break;
t=-t;
k=t;
ans=max(ans,get(1,0,n,t,n));
ans*=RX[t];
}
ans=ans%MOD*gt(k-1)%MOD;
if(k==-1) return f[1];
return ans;
}
int updateY(int pos, int val) {
update(1,0,n,pos,val);
ll ans=0,k=-1;
for(int t : st){
if(ans>(ll)1e9) break;
t=-t;
k=t;
ans=max(ans,get(1,0,n,t,n));
ans*=RX[t];
}
ans=ans%MOD*gt(k-1)%MOD;
if(k==-1) return f[1];
return ans;
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:67:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
67 | ans=ans%MOD*gt(k-1)%MOD;
| ~^~
horses.cpp:68:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
68 | if(k==-1) return f[1];
| ~~~^
horses.cpp:69:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
69 | return ans;
| ^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:86:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
86 | ans=ans%MOD*gt(k-1)%MOD;
| ~^~
horses.cpp:87:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
87 | if(k==-1) return f[1];
| ~~~^
horses.cpp:88:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
88 | return ans;
| ^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:101:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
101 | ans=ans%MOD*gt(k-1)%MOD;
| ~^~
horses.cpp:102:22: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
102 | if(k==-1) return f[1];
| ~~~^
horses.cpp:103:12: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
103 | return ans;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4180 KB |
Output is correct |
5 |
Correct |
2 ms |
4152 KB |
Output is correct |
6 |
Correct |
2 ms |
4208 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
2 ms |
4152 KB |
Output is correct |
9 |
Correct |
2 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
2 ms |
4180 KB |
Output is correct |
12 |
Correct |
2 ms |
4180 KB |
Output is correct |
13 |
Correct |
2 ms |
4152 KB |
Output is correct |
14 |
Correct |
2 ms |
4180 KB |
Output is correct |
15 |
Correct |
2 ms |
4152 KB |
Output is correct |
16 |
Correct |
2 ms |
4148 KB |
Output is correct |
17 |
Correct |
2 ms |
4180 KB |
Output is correct |
18 |
Correct |
2 ms |
4152 KB |
Output is correct |
19 |
Correct |
2 ms |
4152 KB |
Output is correct |
20 |
Correct |
2 ms |
4152 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4148 KB |
Output is correct |
5 |
Correct |
3 ms |
4180 KB |
Output is correct |
6 |
Correct |
2 ms |
4180 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
2 ms |
4152 KB |
Output is correct |
9 |
Correct |
2 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
2 ms |
4180 KB |
Output is correct |
12 |
Correct |
2 ms |
4180 KB |
Output is correct |
13 |
Correct |
2 ms |
4148 KB |
Output is correct |
14 |
Correct |
2 ms |
4152 KB |
Output is correct |
15 |
Correct |
2 ms |
4156 KB |
Output is correct |
16 |
Correct |
2 ms |
4180 KB |
Output is correct |
17 |
Correct |
2 ms |
4180 KB |
Output is correct |
18 |
Correct |
2 ms |
4180 KB |
Output is correct |
19 |
Correct |
2 ms |
4180 KB |
Output is correct |
20 |
Correct |
2 ms |
4180 KB |
Output is correct |
21 |
Correct |
2 ms |
4180 KB |
Output is correct |
22 |
Correct |
2 ms |
4180 KB |
Output is correct |
23 |
Correct |
3 ms |
4288 KB |
Output is correct |
24 |
Correct |
3 ms |
4260 KB |
Output is correct |
25 |
Correct |
5 ms |
4308 KB |
Output is correct |
26 |
Correct |
3 ms |
4272 KB |
Output is correct |
27 |
Incorrect |
5 ms |
4180 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
555 ms |
45436 KB |
Output is correct |
2 |
Correct |
323 ms |
45444 KB |
Output is correct |
3 |
Correct |
341 ms |
45368 KB |
Output is correct |
4 |
Correct |
340 ms |
45488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4152 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
2 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4148 KB |
Output is correct |
5 |
Correct |
2 ms |
4180 KB |
Output is correct |
6 |
Correct |
2 ms |
4152 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
2 ms |
4180 KB |
Output is correct |
9 |
Correct |
2 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
4188 KB |
Output is correct |
11 |
Correct |
2 ms |
4152 KB |
Output is correct |
12 |
Correct |
2 ms |
4180 KB |
Output is correct |
13 |
Correct |
2 ms |
4180 KB |
Output is correct |
14 |
Correct |
2 ms |
4180 KB |
Output is correct |
15 |
Correct |
2 ms |
4152 KB |
Output is correct |
16 |
Correct |
2 ms |
4144 KB |
Output is correct |
17 |
Correct |
2 ms |
4180 KB |
Output is correct |
18 |
Correct |
2 ms |
4148 KB |
Output is correct |
19 |
Correct |
2 ms |
4180 KB |
Output is correct |
20 |
Correct |
2 ms |
4180 KB |
Output is correct |
21 |
Correct |
2 ms |
4180 KB |
Output is correct |
22 |
Correct |
2 ms |
4180 KB |
Output is correct |
23 |
Correct |
3 ms |
4276 KB |
Output is correct |
24 |
Correct |
3 ms |
4300 KB |
Output is correct |
25 |
Correct |
3 ms |
4264 KB |
Output is correct |
26 |
Correct |
4 ms |
4308 KB |
Output is correct |
27 |
Incorrect |
5 ms |
4180 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
3 ms |
4180 KB |
Output is correct |
4 |
Correct |
2 ms |
4152 KB |
Output is correct |
5 |
Correct |
2 ms |
4152 KB |
Output is correct |
6 |
Correct |
2 ms |
4180 KB |
Output is correct |
7 |
Correct |
2 ms |
4180 KB |
Output is correct |
8 |
Correct |
2 ms |
4148 KB |
Output is correct |
9 |
Correct |
2 ms |
4180 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
2 ms |
4180 KB |
Output is correct |
12 |
Correct |
2 ms |
4180 KB |
Output is correct |
13 |
Correct |
2 ms |
4180 KB |
Output is correct |
14 |
Correct |
2 ms |
4152 KB |
Output is correct |
15 |
Correct |
2 ms |
4180 KB |
Output is correct |
16 |
Correct |
2 ms |
4180 KB |
Output is correct |
17 |
Correct |
2 ms |
4180 KB |
Output is correct |
18 |
Correct |
3 ms |
4156 KB |
Output is correct |
19 |
Correct |
4 ms |
4180 KB |
Output is correct |
20 |
Correct |
3 ms |
4148 KB |
Output is correct |
21 |
Correct |
4 ms |
4180 KB |
Output is correct |
22 |
Correct |
4 ms |
4180 KB |
Output is correct |
23 |
Correct |
3 ms |
4180 KB |
Output is correct |
24 |
Correct |
3 ms |
4308 KB |
Output is correct |
25 |
Correct |
3 ms |
4308 KB |
Output is correct |
26 |
Correct |
3 ms |
4292 KB |
Output is correct |
27 |
Incorrect |
4 ms |
4180 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |