#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
#define endl '\n'
#define st first
#define nd second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define ll long long
ll mod=1000000007;
int inf=1000000007;
ll infl=1000000000000000007;
const int pot=1<<19,N=500007;
ll pw(ll a,int b)
{
ll res=1;
while(b)
{
if(b%2) res=res*a%mod;
a=a*a%mod;
b/=2;
}
return res;
}
int seg[2*pot+7];
void ins(int v,int x)
{
v+=pot-1;
seg[v]=x;
while(v>1)
{
v/=2;
seg[v]=max(seg[2*v],seg[2*v+1]);
}
}
int que(int v,int a,int b,int l,int r)
{
if(a<=l&&b>=r) return seg[v];
if(r<a||l>b) return 0;
return max(que(2*v,a,b,l,(l+r)/2),que(2*v+1,a,b,(l+r)/2+1,r));
}
set<int>S;
ll inv[N],x[N];
ll T=1;
ll get()
{
ll W=T,p=1;
vector<int>V;
for(auto i:S)
{
if(p>1000000000) break;
W=W*inv[-i]%mod;
p=p*x[-i];
V.pb(-i);
}
reverse(all(V));
__int128 ans=que(1,1,pot,1,pot),t=1;
for(auto i:V)
{
//cout<<i<<" "<<que(1,i,pot,1,pot)<<endl;
t=t*x[i];
ans=max(ans,t*(__int128)que(1,i,pot,1,pot));
}
return ans%mod*W%mod;
}
int init(int n,int X[],int Y[])
{
for(int i=0;i<n;i++) seg[i+pot]=Y[i];
for(int i=pot-1;i>0;i--) seg[i]=max(seg[2*i],seg[2*i+1]);
for(int i=0;i<n;i++)
{
T=T*X[i]%mod;
x[i+1]=X[i];
inv[i+1]=pw(X[i],mod-2);
if(X[i]>1) S.insert(-(i+1));
}
return get();
}
int updateX(int i,int v)
{
i++;
T=T*inv[i]%mod;
S.erase(-i);
T=T*(ll)v%mod;
inv[i]=pw(v,mod-2);
if(v>1) S.insert(-i);
x[i]=v;
return get();
}
int updateY(int i,int v)
{
i++;
ins(i,v);
return get();
}
/*
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cout<<init(3,{2,1,3},{3,4,1})<<endl;
cout<<updateY(1,2)<<endl;
return 0;
}*/
Compilation message
horses.cpp: In function 'long long int get()':
horses.cpp:73:21: warning: conversion from '__int128' to 'long long int' may change value [-Wconversion]
73 | return ans%mod*W%mod;
| ~~~~~~~~~^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:84:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
84 | inv[i+1]=pw(X[i],mod-2);
| ~~~^~
horses.cpp:87:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
87 | return get();
| ~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:97:20: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
97 | inv[i]=pw(v,mod-2);
| ~~~^~
horses.cpp:100:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
100 | return get();
| ~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:107:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
107 | return get();
| ~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
2 ms |
2260 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
2260 KB |
Output is correct |
7 |
Correct |
2 ms |
2260 KB |
Output is correct |
8 |
Correct |
2 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2260 KB |
Output is correct |
10 |
Correct |
3 ms |
2372 KB |
Output is correct |
11 |
Correct |
2 ms |
2260 KB |
Output is correct |
12 |
Correct |
2 ms |
2260 KB |
Output is correct |
13 |
Correct |
2 ms |
2260 KB |
Output is correct |
14 |
Correct |
2 ms |
2260 KB |
Output is correct |
15 |
Correct |
2 ms |
2260 KB |
Output is correct |
16 |
Correct |
2 ms |
2260 KB |
Output is correct |
17 |
Correct |
2 ms |
2260 KB |
Output is correct |
18 |
Correct |
2 ms |
2260 KB |
Output is correct |
19 |
Correct |
2 ms |
2260 KB |
Output is correct |
20 |
Correct |
2 ms |
2260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
2 ms |
2260 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
2260 KB |
Output is correct |
7 |
Correct |
2 ms |
2260 KB |
Output is correct |
8 |
Correct |
2 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2260 KB |
Output is correct |
10 |
Correct |
2 ms |
2260 KB |
Output is correct |
11 |
Correct |
2 ms |
2260 KB |
Output is correct |
12 |
Correct |
3 ms |
2260 KB |
Output is correct |
13 |
Correct |
2 ms |
2260 KB |
Output is correct |
14 |
Correct |
2 ms |
2260 KB |
Output is correct |
15 |
Correct |
2 ms |
2260 KB |
Output is correct |
16 |
Correct |
2 ms |
2260 KB |
Output is correct |
17 |
Correct |
2 ms |
2260 KB |
Output is correct |
18 |
Correct |
2 ms |
2260 KB |
Output is correct |
19 |
Correct |
2 ms |
2260 KB |
Output is correct |
20 |
Correct |
2 ms |
2260 KB |
Output is correct |
21 |
Correct |
2 ms |
2260 KB |
Output is correct |
22 |
Correct |
3 ms |
2260 KB |
Output is correct |
23 |
Correct |
3 ms |
2388 KB |
Output is correct |
24 |
Correct |
3 ms |
2376 KB |
Output is correct |
25 |
Correct |
3 ms |
2388 KB |
Output is correct |
26 |
Correct |
3 ms |
2388 KB |
Output is correct |
27 |
Correct |
6 ms |
2388 KB |
Output is correct |
28 |
Correct |
5 ms |
2388 KB |
Output is correct |
29 |
Correct |
3 ms |
2388 KB |
Output is correct |
30 |
Correct |
3 ms |
2388 KB |
Output is correct |
31 |
Correct |
5 ms |
2384 KB |
Output is correct |
32 |
Correct |
8 ms |
2388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
645 ms |
40480 KB |
Output is correct |
2 |
Correct |
410 ms |
40428 KB |
Output is correct |
3 |
Correct |
386 ms |
40464 KB |
Output is correct |
4 |
Correct |
515 ms |
40464 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
2 ms |
2260 KB |
Output is correct |
5 |
Correct |
2 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
2260 KB |
Output is correct |
7 |
Correct |
2 ms |
2260 KB |
Output is correct |
8 |
Correct |
2 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2260 KB |
Output is correct |
10 |
Correct |
2 ms |
2260 KB |
Output is correct |
11 |
Correct |
2 ms |
2260 KB |
Output is correct |
12 |
Correct |
2 ms |
2260 KB |
Output is correct |
13 |
Correct |
2 ms |
2260 KB |
Output is correct |
14 |
Correct |
2 ms |
2260 KB |
Output is correct |
15 |
Correct |
2 ms |
2260 KB |
Output is correct |
16 |
Correct |
2 ms |
2260 KB |
Output is correct |
17 |
Correct |
2 ms |
2260 KB |
Output is correct |
18 |
Correct |
2 ms |
2260 KB |
Output is correct |
19 |
Correct |
2 ms |
2260 KB |
Output is correct |
20 |
Correct |
2 ms |
2260 KB |
Output is correct |
21 |
Correct |
2 ms |
2260 KB |
Output is correct |
22 |
Correct |
2 ms |
2260 KB |
Output is correct |
23 |
Correct |
3 ms |
2388 KB |
Output is correct |
24 |
Correct |
3 ms |
2388 KB |
Output is correct |
25 |
Correct |
3 ms |
2388 KB |
Output is correct |
26 |
Correct |
3 ms |
2388 KB |
Output is correct |
27 |
Correct |
6 ms |
2388 KB |
Output is correct |
28 |
Correct |
4 ms |
2388 KB |
Output is correct |
29 |
Correct |
3 ms |
2388 KB |
Output is correct |
30 |
Correct |
3 ms |
2388 KB |
Output is correct |
31 |
Correct |
4 ms |
2384 KB |
Output is correct |
32 |
Correct |
6 ms |
2388 KB |
Output is correct |
33 |
Correct |
131 ms |
20276 KB |
Output is correct |
34 |
Correct |
127 ms |
20176 KB |
Output is correct |
35 |
Correct |
294 ms |
50480 KB |
Output is correct |
36 |
Correct |
294 ms |
50404 KB |
Output is correct |
37 |
Correct |
149 ms |
18332 KB |
Output is correct |
38 |
Correct |
198 ms |
31112 KB |
Output is correct |
39 |
Correct |
122 ms |
18100 KB |
Output is correct |
40 |
Correct |
281 ms |
45544 KB |
Output is correct |
41 |
Correct |
138 ms |
18112 KB |
Output is correct |
42 |
Correct |
150 ms |
18256 KB |
Output is correct |
43 |
Correct |
276 ms |
45916 KB |
Output is correct |
44 |
Correct |
278 ms |
45912 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2260 KB |
Output is correct |
2 |
Correct |
1 ms |
2260 KB |
Output is correct |
3 |
Correct |
2 ms |
2260 KB |
Output is correct |
4 |
Correct |
2 ms |
2260 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
2 ms |
2260 KB |
Output is correct |
7 |
Correct |
2 ms |
2260 KB |
Output is correct |
8 |
Correct |
2 ms |
2260 KB |
Output is correct |
9 |
Correct |
2 ms |
2260 KB |
Output is correct |
10 |
Correct |
2 ms |
2260 KB |
Output is correct |
11 |
Correct |
2 ms |
2260 KB |
Output is correct |
12 |
Correct |
1 ms |
2260 KB |
Output is correct |
13 |
Correct |
2 ms |
2260 KB |
Output is correct |
14 |
Correct |
2 ms |
2352 KB |
Output is correct |
15 |
Correct |
2 ms |
2260 KB |
Output is correct |
16 |
Correct |
2 ms |
2260 KB |
Output is correct |
17 |
Correct |
2 ms |
2260 KB |
Output is correct |
18 |
Correct |
2 ms |
2260 KB |
Output is correct |
19 |
Correct |
2 ms |
2260 KB |
Output is correct |
20 |
Correct |
2 ms |
2260 KB |
Output is correct |
21 |
Correct |
2 ms |
2260 KB |
Output is correct |
22 |
Correct |
2 ms |
2260 KB |
Output is correct |
23 |
Correct |
3 ms |
2388 KB |
Output is correct |
24 |
Correct |
3 ms |
2388 KB |
Output is correct |
25 |
Correct |
3 ms |
2388 KB |
Output is correct |
26 |
Correct |
3 ms |
2436 KB |
Output is correct |
27 |
Correct |
6 ms |
2432 KB |
Output is correct |
28 |
Correct |
4 ms |
2388 KB |
Output is correct |
29 |
Correct |
3 ms |
2388 KB |
Output is correct |
30 |
Correct |
3 ms |
2388 KB |
Output is correct |
31 |
Correct |
5 ms |
2388 KB |
Output is correct |
32 |
Correct |
6 ms |
2388 KB |
Output is correct |
33 |
Correct |
656 ms |
44320 KB |
Output is correct |
34 |
Correct |
418 ms |
53096 KB |
Output is correct |
35 |
Correct |
413 ms |
44192 KB |
Output is correct |
36 |
Correct |
510 ms |
48124 KB |
Output is correct |
37 |
Correct |
127 ms |
20164 KB |
Output is correct |
38 |
Correct |
125 ms |
20076 KB |
Output is correct |
39 |
Correct |
302 ms |
50468 KB |
Output is correct |
40 |
Correct |
289 ms |
50396 KB |
Output is correct |
41 |
Correct |
149 ms |
18300 KB |
Output is correct |
42 |
Correct |
197 ms |
31028 KB |
Output is correct |
43 |
Correct |
122 ms |
18092 KB |
Output is correct |
44 |
Correct |
293 ms |
45520 KB |
Output is correct |
45 |
Correct |
140 ms |
18120 KB |
Output is correct |
46 |
Correct |
149 ms |
18196 KB |
Output is correct |
47 |
Correct |
274 ms |
45860 KB |
Output is correct |
48 |
Correct |
287 ms |
45868 KB |
Output is correct |
49 |
Correct |
201 ms |
23136 KB |
Output is correct |
50 |
Correct |
188 ms |
23192 KB |
Output is correct |
51 |
Correct |
454 ms |
52280 KB |
Output is correct |
52 |
Correct |
374 ms |
51820 KB |
Output is correct |
53 |
Correct |
520 ms |
21400 KB |
Output is correct |
54 |
Correct |
410 ms |
34980 KB |
Output is correct |
55 |
Correct |
177 ms |
19152 KB |
Output is correct |
56 |
Correct |
364 ms |
47332 KB |
Output is correct |
57 |
Correct |
396 ms |
19828 KB |
Output is correct |
58 |
Correct |
504 ms |
20320 KB |
Output is correct |
59 |
Correct |
270 ms |
45788 KB |
Output is correct |