#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn=500000+10,mod=1e9+7,lg=19,kaf=(1<<(lg));
int allx[maxn],ally[maxn],n;
set<int>st;
struct segment{
struct node{
int maxa,zarb;
node(){
maxa=0;
zarb=1;
}
};
node seg[(1<<(lg+1))];
void upd(int i,int w){
i+=kaf;
seg[i].zarb=seg[i].maxa=w;
i>>=1;
while(i>0){
seg[i].maxa=max(seg[(i<<1)].maxa,seg[(i<<1)^1].maxa);
seg[i].zarb=1ll*seg[(i<<1)].zarb*seg[(i<<1)^1].zarb%mod;
i>>=1;
}
}
int porszarb(int i,int l,int r,int tl,int tr){
if(l>r||l>tr||r<tl||tl>tr){
return 1;
}
if(l>=tl&&r<=tr){
return seg[i].zarb;
}
int m=(l+r)>>1;
return 1ll*porszarb((i<<1),l,m,tl,tr)*porszarb((i<<1)^1,m+1,r,tl,tr)%mod;
}
int porsmx(int i,int l,int r,int tl,int tr){
if(l>r||l>tr||r<tl||tl>tr){
return 0;
}
if(l>=tl&&r<=tr){
return seg[i].maxa;
}
int m=(l+r)>>1;
if(tl>m){
return porsmx((i<<1)^1,m+1,r,tl,tr);
}
return max(porsmx((i<<1),l,m,tl,tr),porsmx((i<<1)^1,m+1,r,tl,tr));
}
}segx,segy;
int calc(){
long long unnow=1;
vector<int>ind;
while((int)st.size()>0){
unnow*=allx[(*st.rbegin())];
ind.push_back((*st.rbegin()));
st.erase((*st.rbegin()));
if(unnow>1000000000){
break;
}
}
unnow/=allx[ind.back()];
long long mx=0;
for(int i=0;i<(int)ind.size();i++){
mx=max(mx,unnow*segy.porsmx(1,0,kaf-1,ind[i],n));
unnow/=allx[ind[i]];
}
mx%=mod;
mx*=segx.porszarb(1,0,kaf-1,0,ind.back());
mx%=mod;
for(auto x:ind){
st.insert(x);
}
return mx;
}
int init(int N, int X[], int Y[]) {
n=N;
allx[0]=1;
st.insert(0);
for(int i=1;i<=n;i++){
//cout<<i<<endl;
allx[i]=X[i-1];
segx.upd(i,allx[i]);
ally[i]=Y[i-1];
segy.upd(i,ally[i]);
if(allx[i]>1){
st.insert(i);
}
}
return calc();
}
int updateX(int pos, int val) {
pos++;
allx[pos]=val;
if(allx[pos]==1){
st.erase(pos);
}else{
st.insert(pos);
}
segx.upd(pos,val);
return calc();
}
int updateY(int pos, int val) {
pos++;
ally[pos]=val;
segy.upd(pos,val);
return calc();
}
Compilation message
horses.cpp: In member function 'void segment::upd(int, int)':
horses.cpp:22:55: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
22 | seg[i].zarb=1ll*seg[(i<<1)].zarb*seg[(i<<1)^1].zarb%mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In member function 'int segment::porszarb(int, int, int, int, int)':
horses.cpp:34:71: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
34 | return 1ll*porszarb((i<<1),l,m,tl,tr)*porszarb((i<<1)^1,m+1,r,tl,tr)%mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int calc()':
horses.cpp:73:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
73 | return mx;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
19036 KB |
Output is correct |
2 |
Correct |
3 ms |
19036 KB |
Output is correct |
3 |
Correct |
2 ms |
19036 KB |
Output is correct |
4 |
Correct |
2 ms |
19036 KB |
Output is correct |
5 |
Correct |
2 ms |
19056 KB |
Output is correct |
6 |
Correct |
3 ms |
19036 KB |
Output is correct |
7 |
Correct |
2 ms |
19036 KB |
Output is correct |
8 |
Correct |
2 ms |
19036 KB |
Output is correct |
9 |
Correct |
3 ms |
19036 KB |
Output is correct |
10 |
Correct |
2 ms |
19036 KB |
Output is correct |
11 |
Correct |
2 ms |
19036 KB |
Output is correct |
12 |
Correct |
3 ms |
19036 KB |
Output is correct |
13 |
Correct |
5 ms |
19036 KB |
Output is correct |
14 |
Correct |
2 ms |
19036 KB |
Output is correct |
15 |
Correct |
2 ms |
19036 KB |
Output is correct |
16 |
Correct |
2 ms |
19036 KB |
Output is correct |
17 |
Correct |
3 ms |
19036 KB |
Output is correct |
18 |
Correct |
3 ms |
19036 KB |
Output is correct |
19 |
Correct |
3 ms |
19036 KB |
Output is correct |
20 |
Correct |
2 ms |
18872 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
19036 KB |
Output is correct |
2 |
Correct |
3 ms |
19036 KB |
Output is correct |
3 |
Correct |
3 ms |
19036 KB |
Output is correct |
4 |
Correct |
2 ms |
19036 KB |
Output is correct |
5 |
Correct |
3 ms |
19036 KB |
Output is correct |
6 |
Correct |
2 ms |
19036 KB |
Output is correct |
7 |
Correct |
2 ms |
19036 KB |
Output is correct |
8 |
Correct |
2 ms |
19036 KB |
Output is correct |
9 |
Correct |
2 ms |
19036 KB |
Output is correct |
10 |
Correct |
2 ms |
19036 KB |
Output is correct |
11 |
Correct |
3 ms |
19036 KB |
Output is correct |
12 |
Correct |
2 ms |
19036 KB |
Output is correct |
13 |
Correct |
3 ms |
19036 KB |
Output is correct |
14 |
Correct |
3 ms |
19036 KB |
Output is correct |
15 |
Correct |
3 ms |
19036 KB |
Output is correct |
16 |
Correct |
2 ms |
19036 KB |
Output is correct |
17 |
Correct |
3 ms |
19036 KB |
Output is correct |
18 |
Correct |
2 ms |
19032 KB |
Output is correct |
19 |
Correct |
3 ms |
19036 KB |
Output is correct |
20 |
Correct |
2 ms |
19036 KB |
Output is correct |
21 |
Correct |
3 ms |
19036 KB |
Output is correct |
22 |
Correct |
3 ms |
19036 KB |
Output is correct |
23 |
Correct |
4 ms |
19036 KB |
Output is correct |
24 |
Correct |
3 ms |
19036 KB |
Output is correct |
25 |
Correct |
4 ms |
19036 KB |
Output is correct |
26 |
Correct |
4 ms |
19036 KB |
Output is correct |
27 |
Correct |
7 ms |
19036 KB |
Output is correct |
28 |
Correct |
4 ms |
19036 KB |
Output is correct |
29 |
Correct |
4 ms |
19036 KB |
Output is correct |
30 |
Correct |
4 ms |
19036 KB |
Output is correct |
31 |
Correct |
5 ms |
19036 KB |
Output is correct |
32 |
Correct |
6 ms |
19036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1387 ms |
49236 KB |
Output is correct |
2 |
Correct |
425 ms |
61692 KB |
Output is correct |
3 |
Correct |
481 ms |
52836 KB |
Output is correct |
4 |
Correct |
588 ms |
56660 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
19032 KB |
Output is correct |
2 |
Correct |
3 ms |
19036 KB |
Output is correct |
3 |
Correct |
4 ms |
16988 KB |
Output is correct |
4 |
Correct |
3 ms |
19068 KB |
Output is correct |
5 |
Correct |
3 ms |
19036 KB |
Output is correct |
6 |
Correct |
3 ms |
19032 KB |
Output is correct |
7 |
Correct |
3 ms |
19036 KB |
Output is correct |
8 |
Correct |
2 ms |
19036 KB |
Output is correct |
9 |
Correct |
3 ms |
19036 KB |
Output is correct |
10 |
Correct |
3 ms |
19036 KB |
Output is correct |
11 |
Correct |
3 ms |
19036 KB |
Output is correct |
12 |
Correct |
3 ms |
19036 KB |
Output is correct |
13 |
Correct |
2 ms |
19036 KB |
Output is correct |
14 |
Correct |
3 ms |
19036 KB |
Output is correct |
15 |
Correct |
3 ms |
19036 KB |
Output is correct |
16 |
Correct |
3 ms |
19036 KB |
Output is correct |
17 |
Correct |
3 ms |
19064 KB |
Output is correct |
18 |
Correct |
3 ms |
19036 KB |
Output is correct |
19 |
Correct |
3 ms |
19032 KB |
Output is correct |
20 |
Correct |
2 ms |
19036 KB |
Output is correct |
21 |
Correct |
3 ms |
19060 KB |
Output is correct |
22 |
Correct |
3 ms |
19064 KB |
Output is correct |
23 |
Correct |
4 ms |
19036 KB |
Output is correct |
24 |
Correct |
4 ms |
19036 KB |
Output is correct |
25 |
Correct |
4 ms |
19032 KB |
Output is correct |
26 |
Correct |
4 ms |
19124 KB |
Output is correct |
27 |
Correct |
7 ms |
19036 KB |
Output is correct |
28 |
Correct |
5 ms |
19036 KB |
Output is correct |
29 |
Correct |
4 ms |
19036 KB |
Output is correct |
30 |
Correct |
6 ms |
19036 KB |
Output is correct |
31 |
Correct |
7 ms |
19036 KB |
Output is correct |
32 |
Correct |
7 ms |
18880 KB |
Output is correct |
33 |
Correct |
149 ms |
24668 KB |
Output is correct |
34 |
Correct |
148 ms |
24808 KB |
Output is correct |
35 |
Correct |
285 ms |
48052 KB |
Output is correct |
36 |
Correct |
288 ms |
48204 KB |
Output is correct |
37 |
Correct |
180 ms |
24656 KB |
Output is correct |
38 |
Correct |
215 ms |
36700 KB |
Output is correct |
39 |
Correct |
138 ms |
24536 KB |
Output is correct |
40 |
Correct |
263 ms |
48008 KB |
Output is correct |
41 |
Correct |
156 ms |
24540 KB |
Output is correct |
42 |
Correct |
169 ms |
24760 KB |
Output is correct |
43 |
Correct |
250 ms |
47956 KB |
Output is correct |
44 |
Correct |
238 ms |
47952 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
19036 KB |
Output is correct |
2 |
Correct |
3 ms |
19032 KB |
Output is correct |
3 |
Correct |
3 ms |
19036 KB |
Output is correct |
4 |
Correct |
3 ms |
19036 KB |
Output is correct |
5 |
Correct |
2 ms |
19036 KB |
Output is correct |
6 |
Correct |
2 ms |
19036 KB |
Output is correct |
7 |
Correct |
3 ms |
19036 KB |
Output is correct |
8 |
Correct |
3 ms |
19036 KB |
Output is correct |
9 |
Correct |
3 ms |
19036 KB |
Output is correct |
10 |
Correct |
2 ms |
19036 KB |
Output is correct |
11 |
Correct |
3 ms |
19036 KB |
Output is correct |
12 |
Correct |
3 ms |
19036 KB |
Output is correct |
13 |
Correct |
3 ms |
19036 KB |
Output is correct |
14 |
Correct |
3 ms |
19036 KB |
Output is correct |
15 |
Correct |
3 ms |
19032 KB |
Output is correct |
16 |
Correct |
3 ms |
19036 KB |
Output is correct |
17 |
Correct |
4 ms |
19064 KB |
Output is correct |
18 |
Correct |
3 ms |
19060 KB |
Output is correct |
19 |
Correct |
2 ms |
19036 KB |
Output is correct |
20 |
Correct |
3 ms |
19036 KB |
Output is correct |
21 |
Correct |
3 ms |
19036 KB |
Output is correct |
22 |
Correct |
3 ms |
19036 KB |
Output is correct |
23 |
Correct |
4 ms |
19088 KB |
Output is correct |
24 |
Correct |
3 ms |
19036 KB |
Output is correct |
25 |
Correct |
7 ms |
19036 KB |
Output is correct |
26 |
Correct |
4 ms |
19036 KB |
Output is correct |
27 |
Correct |
7 ms |
19096 KB |
Output is correct |
28 |
Correct |
4 ms |
19036 KB |
Output is correct |
29 |
Correct |
4 ms |
19036 KB |
Output is correct |
30 |
Correct |
3 ms |
19056 KB |
Output is correct |
31 |
Correct |
5 ms |
19036 KB |
Output is correct |
32 |
Correct |
7 ms |
19036 KB |
Output is correct |
33 |
Correct |
1482 ms |
49072 KB |
Output is correct |
34 |
Correct |
404 ms |
61528 KB |
Output is correct |
35 |
Correct |
465 ms |
52764 KB |
Output is correct |
36 |
Correct |
565 ms |
56636 KB |
Output is correct |
37 |
Correct |
148 ms |
28700 KB |
Output is correct |
38 |
Correct |
142 ms |
28672 KB |
Output is correct |
39 |
Correct |
284 ms |
58956 KB |
Output is correct |
40 |
Correct |
272 ms |
58812 KB |
Output is correct |
41 |
Correct |
178 ms |
26960 KB |
Output is correct |
42 |
Correct |
233 ms |
39504 KB |
Output is correct |
43 |
Correct |
136 ms |
26708 KB |
Output is correct |
44 |
Correct |
246 ms |
53912 KB |
Output is correct |
45 |
Correct |
154 ms |
26708 KB |
Output is correct |
46 |
Correct |
163 ms |
26708 KB |
Output is correct |
47 |
Correct |
239 ms |
54352 KB |
Output is correct |
48 |
Correct |
239 ms |
54348 KB |
Output is correct |
49 |
Correct |
239 ms |
31780 KB |
Output is correct |
50 |
Correct |
236 ms |
31616 KB |
Output is correct |
51 |
Correct |
579 ms |
60816 KB |
Output is correct |
52 |
Correct |
363 ms |
60440 KB |
Output is correct |
53 |
Correct |
671 ms |
29976 KB |
Output is correct |
54 |
Correct |
609 ms |
43448 KB |
Output is correct |
55 |
Correct |
220 ms |
27728 KB |
Output is correct |
56 |
Correct |
331 ms |
55632 KB |
Output is correct |
57 |
Correct |
362 ms |
28244 KB |
Output is correct |
58 |
Correct |
469 ms |
28900 KB |
Output is correct |
59 |
Correct |
241 ms |
54132 KB |
Output is correct |