#include "horses.h"
#define x first
#define y second
#include <bits/stdc++.h>
#define pii pair<int,int>
#define pb push_back
#define ll long long
#define vi vector<int>
#define vl vector<ll>
using namespace std;
const int MOD=1000000007,N=500010,M=1<<19;
const char en='\n';
const ll LLINF=1ll<<60;
int n,x[N],y[N];
set<int> le;
int segP[M*2+10],segM[M*2+10];
pii v[N];
bool debug=0;
void updP(int i,int x)
{
i+=M;
segP[i]=x;
for (i/=2;i;i/=2) segP[i]=segP[i*2]*1ll*segP[i*2+1]%MOD;
}
void updM(int i,int x)
{
i+=M;
segM[i]=x;
for (i/=2;i;i/=2) segM[i]=max(segM[i*2],segM[i*2+1]);
}
int getP(int l,int r,int lo=0,int hi=M,int i=1)
{
if (lo>=l && hi<=r) return segP[i];
if (lo>=r || hi<=l) return 1;
int mid=(lo+hi)/2;
return getP(l,r,lo,mid,i*2)*1ll*getP(l,r,mid,hi,i*2+1)%MOD;
}
int getM(int l,int r,int lo=0,int hi=M,int i=1)
{
if (lo>=l && hi<=r) return segM[i];
if (lo>=r || hi<=l) return 0;
int mid=(lo+hi)/2;
return max(getM(l,r,lo,mid,i*2),getM(l,r,mid,hi,i*2+1));
}
#define lll __int128
int getSol()
{
ll pro=1;
int e,le;
for (e=n-1;pro<=MOD-7 && e>=0;e=v[e].x) pro*=x[e],le=e;
if (debug) cout<<"moram do "<<e<<", umnozak je "<<pro<<endl;
lll ma=0;
lll jedan=1;
int f,lf;
for (f=n-1;pro && f>=0;f=v[f].x)
{
ma=max(ma,pro*jedan*y[f]);
if (debug) cout<<"na "<<f<<" je pro="<<pro<<", y="<<y[f]<<", le="<<le<<endl;
pro/=x[f];
if (debug) cout<<"od "<<f<<" do "<<v[f].x<<" je pro="<<pro<<", max_y="<<v[f].y<<", ma="<<(ll)(ma%MOD)<<endl;
ma=max(ma,pro*jedan*v[f].y);
lf=f;
}
return (ma%MOD)*getP(0,le)%MOD;
}
int init(int N, int X[], int Y[]) {
n=N;
for (int i=0;i<n;++i) x[i]=X[i],y[i]=Y[i],segP[i+M]=x[i],segM[i+M]=y[i];
for (int i=n;i<M;++i) segP[i+M]=1;
for (int i=M-1;i>0;--i) segP[i]=segP[i*2]*1ll*segP[i*2+1]%MOD,segM[i]=max(segM[i*2],segM[i*2+1]);
if (debug) cout<<"pola inita gotovo"<<endl;
for (int i=n-1;i>=0;)
{
le.insert(i);
int j=i-1,ma=0;
while (j>=0 && x[j]==1) ma=max(ma,y[j]),--j;
v[i]={j,ma};
if (debug) cout<<"od "<<i<<" do "<<j<<" sa maks="<<ma<<endl;
i=j;
}
//if (debug) cout<<"rjesenje inita je "<<getSol()<<endl;
return getSol();
}
int updateX(int pos, int val) {
int sxp=x[pos];
x[pos]=val;
updP(pos,val);
if (sxp==1)
{
if (val==1 || pos==n-1) return getSol();
int z=*le.upper_bound(pos);
int et=v[z].x;
v[z]={pos,getM(pos+1,z)};
v[pos]={et,getM(et+1,pos)};
le.insert(pos);
if (debug) for (int i=n-1;i>=0;i=v[i].x) cout<<"od "<<i<<" do "<<v[i].x<<" sa maks="<<v[i].y<<endl;
return getSol();
}
else
{
if (val!=1 || pos==n-1)
{
return getSol();
}
int z=*le.upper_bound(pos);
v[z]={v[pos].x,getM(v[pos].x+1,z)};
v[pos]={0,0};
le.erase(le.find(pos));
return getSol();
}
return getSol();
}
int updateY(int pos, int val) {
y[pos]=val;
updM(pos,val);
if (pos!=n-1)
{
int z=*le.upper_bound(pos);
v[z].y=getM(v[z].x+1,z);
}
return getSol();
}
Compilation message
horses.cpp: In function 'void updP(int, int)':
horses.cpp:22:22: warning: declaration of 'first' shadows a global declaration [-Wshadow]
void updP(int i,int x)
^
horses.cpp:2:11: note: shadowed declaration is here
#define x first
^
horses.cpp:15:7: note: in expansion of macro 'x'
int n,x[N],y[N];
^
horses.cpp:26:53: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
for (i/=2;i;i/=2) segP[i]=segP[i*2]*1ll*segP[i*2+1]%MOD;
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'void updM(int, int)':
horses.cpp:29:22: warning: declaration of 'first' shadows a global declaration [-Wshadow]
void updM(int i,int x)
^
horses.cpp:2:11: note: shadowed declaration is here
#define x first
^
horses.cpp:15:7: note: in expansion of macro 'x'
int n,x[N],y[N];
^
horses.cpp: In function 'int getP(int, int, int, int, int)':
horses.cpp:41:56: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return getP(l,r,lo,mid,i*2)*1ll*getP(l,r,mid,hi,i*2+1)%MOD;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int getSol()':
horses.cpp:57:8: warning: declaration of 'le' shadows a global declaration [-Wshadow]
int e,le;
^~
horses.cpp:16:10: note: shadowed declaration is here
set<int> le;
^~
horses.cpp:72:28: warning: conversion to 'int' from '__int128' may alter its value [-Wconversion]
return (ma%MOD)*getP(0,le)%MOD;
~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp:62:8: warning: variable 'lf' set but not used [-Wunused-but-set-variable]
int f,lf;
^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:75:33: warning: declaration of 'N' shadows a global declaration [-Wshadow]
int init(int N, int X[], int Y[]) {
^
horses.cpp:11:26: note: shadowed declaration is here
const int MOD=1000000007,N=500010,M=1<<19;
^
horses.cpp:79:59: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
for (int i=M-1;i>0;--i) segP[i]=segP[i*2]*1ll*segP[i*2+1]%MOD,segM[i]=max(segM[i*2],segM[i*2+1]);
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int getSol()':
horses.cpp:72:22: warning: 'le' may be used uninitialized in this function [-Wmaybe-uninitialized]
return (ma%MOD)*getP(0,le)%MOD;
~~~~^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6528 KB |
Output is correct |
2 |
Correct |
9 ms |
6528 KB |
Output is correct |
3 |
Correct |
8 ms |
6528 KB |
Output is correct |
4 |
Correct |
8 ms |
6528 KB |
Output is correct |
5 |
Correct |
8 ms |
6528 KB |
Output is correct |
6 |
Correct |
8 ms |
6528 KB |
Output is correct |
7 |
Correct |
8 ms |
6528 KB |
Output is correct |
8 |
Correct |
8 ms |
6528 KB |
Output is correct |
9 |
Correct |
7 ms |
6528 KB |
Output is correct |
10 |
Correct |
8 ms |
6528 KB |
Output is correct |
11 |
Correct |
8 ms |
6528 KB |
Output is correct |
12 |
Correct |
8 ms |
6528 KB |
Output is correct |
13 |
Correct |
8 ms |
6528 KB |
Output is correct |
14 |
Correct |
8 ms |
6528 KB |
Output is correct |
15 |
Correct |
9 ms |
6528 KB |
Output is correct |
16 |
Correct |
8 ms |
6528 KB |
Output is correct |
17 |
Correct |
8 ms |
6528 KB |
Output is correct |
18 |
Correct |
8 ms |
6528 KB |
Output is correct |
19 |
Correct |
8 ms |
6528 KB |
Output is correct |
20 |
Correct |
8 ms |
6528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
6528 KB |
Output is correct |
2 |
Correct |
8 ms |
6528 KB |
Output is correct |
3 |
Correct |
8 ms |
6576 KB |
Output is correct |
4 |
Correct |
8 ms |
6528 KB |
Output is correct |
5 |
Correct |
8 ms |
6528 KB |
Output is correct |
6 |
Correct |
8 ms |
6528 KB |
Output is correct |
7 |
Correct |
8 ms |
6484 KB |
Output is correct |
8 |
Correct |
8 ms |
6528 KB |
Output is correct |
9 |
Correct |
8 ms |
6528 KB |
Output is correct |
10 |
Correct |
8 ms |
6528 KB |
Output is correct |
11 |
Correct |
8 ms |
6528 KB |
Output is correct |
12 |
Correct |
8 ms |
6528 KB |
Output is correct |
13 |
Correct |
8 ms |
6528 KB |
Output is correct |
14 |
Correct |
8 ms |
6528 KB |
Output is correct |
15 |
Correct |
8 ms |
6540 KB |
Output is correct |
16 |
Correct |
8 ms |
6448 KB |
Output is correct |
17 |
Correct |
8 ms |
6656 KB |
Output is correct |
18 |
Correct |
8 ms |
6528 KB |
Output is correct |
19 |
Correct |
8 ms |
6528 KB |
Output is correct |
20 |
Correct |
7 ms |
6528 KB |
Output is correct |
21 |
Correct |
8 ms |
6528 KB |
Output is correct |
22 |
Correct |
8 ms |
6528 KB |
Output is correct |
23 |
Correct |
9 ms |
6528 KB |
Output is correct |
24 |
Correct |
9 ms |
6528 KB |
Output is correct |
25 |
Correct |
9 ms |
6656 KB |
Output is correct |
26 |
Correct |
9 ms |
6784 KB |
Output is correct |
27 |
Correct |
9 ms |
6528 KB |
Output is correct |
28 |
Correct |
9 ms |
6656 KB |
Output is correct |
29 |
Correct |
9 ms |
6528 KB |
Output is correct |
30 |
Correct |
9 ms |
6656 KB |
Output is correct |
31 |
Correct |
9 ms |
6528 KB |
Output is correct |
32 |
Correct |
10 ms |
6528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
296 ms |
48560 KB |
Output is correct |
2 |
Correct |
359 ms |
57336 KB |
Output is correct |
3 |
Correct |
344 ms |
48420 KB |
Output is correct |
4 |
Correct |
274 ms |
52344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6528 KB |
Output is correct |
2 |
Correct |
9 ms |
6528 KB |
Output is correct |
3 |
Correct |
7 ms |
6448 KB |
Output is correct |
4 |
Correct |
7 ms |
6572 KB |
Output is correct |
5 |
Correct |
8 ms |
6528 KB |
Output is correct |
6 |
Correct |
8 ms |
6528 KB |
Output is correct |
7 |
Correct |
8 ms |
6528 KB |
Output is correct |
8 |
Correct |
8 ms |
6528 KB |
Output is correct |
9 |
Correct |
8 ms |
6528 KB |
Output is correct |
10 |
Correct |
8 ms |
6528 KB |
Output is correct |
11 |
Correct |
8 ms |
6528 KB |
Output is correct |
12 |
Correct |
7 ms |
6528 KB |
Output is correct |
13 |
Correct |
8 ms |
6528 KB |
Output is correct |
14 |
Correct |
8 ms |
6528 KB |
Output is correct |
15 |
Correct |
9 ms |
6528 KB |
Output is correct |
16 |
Correct |
7 ms |
6528 KB |
Output is correct |
17 |
Correct |
8 ms |
6528 KB |
Output is correct |
18 |
Correct |
8 ms |
6528 KB |
Output is correct |
19 |
Correct |
7 ms |
6528 KB |
Output is correct |
20 |
Correct |
8 ms |
6528 KB |
Output is correct |
21 |
Correct |
8 ms |
6528 KB |
Output is correct |
22 |
Correct |
8 ms |
6528 KB |
Output is correct |
23 |
Correct |
9 ms |
6528 KB |
Output is correct |
24 |
Correct |
10 ms |
6548 KB |
Output is correct |
25 |
Correct |
8 ms |
6656 KB |
Output is correct |
26 |
Correct |
9 ms |
6532 KB |
Output is correct |
27 |
Correct |
13 ms |
6528 KB |
Output is correct |
28 |
Correct |
9 ms |
6528 KB |
Output is correct |
29 |
Correct |
9 ms |
6528 KB |
Output is correct |
30 |
Correct |
10 ms |
6656 KB |
Output is correct |
31 |
Correct |
9 ms |
6528 KB |
Output is correct |
32 |
Correct |
10 ms |
6732 KB |
Output is correct |
33 |
Correct |
47 ms |
24056 KB |
Output is correct |
34 |
Correct |
47 ms |
24056 KB |
Output is correct |
35 |
Correct |
208 ms |
54648 KB |
Output is correct |
36 |
Correct |
208 ms |
54648 KB |
Output is correct |
37 |
Correct |
42 ms |
20472 KB |
Output is correct |
38 |
Correct |
107 ms |
35320 KB |
Output is correct |
39 |
Correct |
29 ms |
18432 KB |
Output is correct |
40 |
Correct |
212 ms |
49664 KB |
Output is correct |
41 |
Correct |
36 ms |
18552 KB |
Output is correct |
42 |
Correct |
37 ms |
18552 KB |
Output is correct |
43 |
Correct |
180 ms |
50040 KB |
Output is correct |
44 |
Correct |
190 ms |
50012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
8 ms |
6528 KB |
Output is correct |
2 |
Correct |
8 ms |
6528 KB |
Output is correct |
3 |
Correct |
8 ms |
6528 KB |
Output is correct |
4 |
Correct |
8 ms |
6528 KB |
Output is correct |
5 |
Correct |
8 ms |
6528 KB |
Output is correct |
6 |
Correct |
8 ms |
6528 KB |
Output is correct |
7 |
Correct |
8 ms |
6528 KB |
Output is correct |
8 |
Correct |
8 ms |
6528 KB |
Output is correct |
9 |
Correct |
8 ms |
6528 KB |
Output is correct |
10 |
Correct |
8 ms |
6528 KB |
Output is correct |
11 |
Correct |
8 ms |
6528 KB |
Output is correct |
12 |
Correct |
8 ms |
6484 KB |
Output is correct |
13 |
Correct |
8 ms |
6656 KB |
Output is correct |
14 |
Correct |
8 ms |
6528 KB |
Output is correct |
15 |
Correct |
8 ms |
6528 KB |
Output is correct |
16 |
Correct |
8 ms |
6528 KB |
Output is correct |
17 |
Correct |
8 ms |
6528 KB |
Output is correct |
18 |
Correct |
8 ms |
6528 KB |
Output is correct |
19 |
Correct |
8 ms |
6528 KB |
Output is correct |
20 |
Correct |
8 ms |
6528 KB |
Output is correct |
21 |
Correct |
8 ms |
6528 KB |
Output is correct |
22 |
Correct |
8 ms |
6444 KB |
Output is correct |
23 |
Correct |
9 ms |
6528 KB |
Output is correct |
24 |
Correct |
9 ms |
6528 KB |
Output is correct |
25 |
Correct |
9 ms |
6628 KB |
Output is correct |
26 |
Correct |
10 ms |
6656 KB |
Output is correct |
27 |
Correct |
9 ms |
6572 KB |
Output is correct |
28 |
Correct |
9 ms |
6528 KB |
Output is correct |
29 |
Correct |
8 ms |
6528 KB |
Output is correct |
30 |
Correct |
9 ms |
6656 KB |
Output is correct |
31 |
Correct |
9 ms |
6528 KB |
Output is correct |
32 |
Correct |
9 ms |
6528 KB |
Output is correct |
33 |
Correct |
288 ms |
48504 KB |
Output is correct |
34 |
Correct |
348 ms |
57448 KB |
Output is correct |
35 |
Correct |
322 ms |
48380 KB |
Output is correct |
36 |
Correct |
254 ms |
52344 KB |
Output is correct |
37 |
Correct |
46 ms |
24060 KB |
Output is correct |
38 |
Correct |
46 ms |
23992 KB |
Output is correct |
39 |
Correct |
217 ms |
54728 KB |
Output is correct |
40 |
Correct |
316 ms |
54648 KB |
Output is correct |
41 |
Correct |
45 ms |
20600 KB |
Output is correct |
42 |
Correct |
107 ms |
35352 KB |
Output is correct |
43 |
Correct |
29 ms |
18432 KB |
Output is correct |
44 |
Correct |
190 ms |
49768 KB |
Output is correct |
45 |
Correct |
32 ms |
18552 KB |
Output is correct |
46 |
Correct |
36 ms |
18424 KB |
Output is correct |
47 |
Correct |
187 ms |
50168 KB |
Output is correct |
48 |
Correct |
183 ms |
50040 KB |
Output is correct |
49 |
Correct |
189 ms |
27388 KB |
Output is correct |
50 |
Correct |
202 ms |
27388 KB |
Output is correct |
51 |
Correct |
280 ms |
56480 KB |
Output is correct |
52 |
Correct |
293 ms |
56184 KB |
Output is correct |
53 |
Correct |
197 ms |
23716 KB |
Output is correct |
54 |
Correct |
204 ms |
39288 KB |
Output is correct |
55 |
Correct |
80 ms |
19496 KB |
Output is correct |
56 |
Correct |
283 ms |
51448 KB |
Output is correct |
57 |
Correct |
107 ms |
20140 KB |
Output is correct |
58 |
Correct |
143 ms |
20724 KB |
Output is correct |
59 |
Correct |
191 ms |
50144 KB |
Output is correct |