#include <stdio.h>
#include <set>
using namespace std;
#define mp make_pair
#define ll long long
const int mod=1e9+7;
const int N=500050;
struct SegmentTreeProduct
{
int pro[1<<20];
SegmentTreeProduct(){ for(int i=0;i<(1<<20);i++) pro[i]=1;}
void Set(int i, int val){ i+=1<<19;pro[i]=val;for(i>>=1;i;i>>=1) pro[i]=(ll)pro[i<<1]*pro[i<<1|1]%mod;}
int Get(int l, int r)
{
int ret=1;
for(l+=1<<19,r+=1<<19;l<=r;l>>=1,r>>=1)
{
if(l%2==1) ret=(ll)ret*pro[l++]%mod;
if(r%2==0) ret=(ll)ret*pro[r--]%mod;
}
return ret;
}
} PTree;
int max(int a, int b){ return a>b?a:b;}
struct SegmentTreeMax
{
int rmq[1<<20];
SegmentTreeMax(){ for(int i=0;i<(1<<20);i++) rmq[i]=0;}
void Set(int i, int val){ i+=1<<19;rmq[i]=val;for(i>>=1;i;i>>=1) rmq[i]=max(rmq[i<<1],rmq[i<<1|1]);}
int Get(int l, int r)
{
int ret=0;
for(l+=1<<19,r+=1<<19;l<=r;l>>=1,r>>=1)
{
if(l%2==1) ret=max(ret,rmq[l++]);
if(r%2==0) ret=max(ret,rmq[r--]);
}
return ret;
}
} MTree;
set<pair<int,int> > Set;
set<pair<int,int> >::iterator it,it1;
void Cut(int i)
{
it=Set.lower_bound(mp(i,N));
if(it==Set.begin()) return;
it--;
int l=it->first,r=it->second;
if(r<i) return;
if(l<i)
{
Set.erase(mp(l,r));
Set.insert(mp(l,i-1));
Set.insert(mp(i,r));
}
}
void Split(int i){ Cut(i);Cut(i+1);}
int x[N],y[N],n;
int Solve()
{
it=Set.end();ll p=1;int sol=(ll)PTree.Get(1,n)*y[n]%mod;
while(it!=Set.begin())
{
it--;
int b=MTree.Get(it->first,it->second);
if(p<b) p=b,sol=(ll)PTree.Get(1,it->second)*b%mod;
p*=x[it->first];
if(p>mod) break;
}
return sol;
}
int init(int N, int X[], int Y[])
{
int i,j;n=N;
for(i=1;i<=n;i++) x[i]=X[i-1],y[i]=Y[i-1];
for(i=1;i<=n;i++) PTree.Set(i,x[i]),MTree.Set(i,y[i]);
for(i=1;i<=n;i++)
{
if(x[i]>1) Set.insert(mp(i,i));
else if(x[i-1]!=1)
{
for(j=i+1;j<=n && x[j]==1;j++);
Set.insert(mp(i,j-1));
}
}
return Solve();
}
int updateX(int p, int v)
{
p++;
if(x[p]==1 && v==1) return Solve();
if(x[p]==1) Split(p);
if(v==1)
{
if(x[p-1]==1)
{
it=Set.lower_bound(mp(p,p));
it1=it;it1--;
int l=it1->first,r=it->second;
Set.erase(it1);
Set.erase(it);
Set.insert(mp(l,r));
}
if(x[p+1]==1)
{
it=Set.lower_bound(mp(p,N));
it1=it;it1--;
int l=it1->first,r=it->second;
Set.erase(it1);
Set.erase(it);
Set.insert(mp(l,r));
}
}
PTree.Set(p,v);
x[p]=v;
return Solve();
}
int updateY(int p, int v)
{
p++;
MTree.Set(p,v),y[p]=v;
return Solve();
}
Compilation message
horses.cpp: In member function 'void SegmentTreeProduct::Set(int, int)':
horses.cpp:12:99: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
void Set(int i, int val){ i+=1<<19;pro[i]=val;for(i>>=1;i;i>>=1) pro[i]=(ll)pro[i<<1]*pro[i<<1|1]%mod;}
~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In member function 'int SegmentTreeProduct::Get(int, int)':
horses.cpp:18:35: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
if(l%2==1) ret=(ll)ret*pro[l++]%mod;
~~~~~~~~~~~~~~~~^~~~
horses.cpp:19:35: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
if(r%2==0) ret=(ll)ret*pro[r--]%mod;
~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int Solve()':
horses.cpp:61:53: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
it=Set.end();ll p=1;int sol=(ll)PTree.Get(1,n)*y[n]%mod;
~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp:66:48: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
if(p<b) p=b,sol=(ll)PTree.Get(1,it->second)*b%mod;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:72:33: warning: declaration of 'N' shadows a global declaration [-Wshadow]
int init(int N, int X[], int Y[])
^
horses.cpp:7:11: note: shadowed declaration is here
const int N=500050;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
8696 KB |
Output is correct |
2 |
Correct |
11 ms |
8812 KB |
Output is correct |
3 |
Correct |
11 ms |
8868 KB |
Output is correct |
4 |
Correct |
8 ms |
8868 KB |
Output is correct |
5 |
Correct |
10 ms |
8868 KB |
Output is correct |
6 |
Correct |
10 ms |
8868 KB |
Output is correct |
7 |
Correct |
14 ms |
8888 KB |
Output is correct |
8 |
Correct |
10 ms |
8976 KB |
Output is correct |
9 |
Correct |
10 ms |
8980 KB |
Output is correct |
10 |
Correct |
11 ms |
8988 KB |
Output is correct |
11 |
Correct |
11 ms |
9116 KB |
Output is correct |
12 |
Correct |
9 ms |
9164 KB |
Output is correct |
13 |
Correct |
11 ms |
9164 KB |
Output is correct |
14 |
Correct |
9 ms |
9164 KB |
Output is correct |
15 |
Correct |
10 ms |
9164 KB |
Output is correct |
16 |
Correct |
10 ms |
9164 KB |
Output is correct |
17 |
Correct |
10 ms |
9232 KB |
Output is correct |
18 |
Correct |
11 ms |
9232 KB |
Output is correct |
19 |
Correct |
11 ms |
9232 KB |
Output is correct |
20 |
Correct |
12 ms |
9232 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
9232 KB |
Output is correct |
2 |
Correct |
10 ms |
9232 KB |
Output is correct |
3 |
Correct |
12 ms |
9232 KB |
Output is correct |
4 |
Correct |
10 ms |
9232 KB |
Output is correct |
5 |
Correct |
10 ms |
9232 KB |
Output is correct |
6 |
Correct |
12 ms |
9232 KB |
Output is correct |
7 |
Correct |
12 ms |
9232 KB |
Output is correct |
8 |
Correct |
11 ms |
9232 KB |
Output is correct |
9 |
Correct |
8 ms |
9296 KB |
Output is correct |
10 |
Correct |
9 ms |
9296 KB |
Output is correct |
11 |
Correct |
9 ms |
9296 KB |
Output is correct |
12 |
Correct |
14 ms |
9296 KB |
Output is correct |
13 |
Correct |
10 ms |
9296 KB |
Output is correct |
14 |
Correct |
12 ms |
9296 KB |
Output is correct |
15 |
Correct |
10 ms |
9296 KB |
Output is correct |
16 |
Correct |
10 ms |
9296 KB |
Output is correct |
17 |
Correct |
10 ms |
9296 KB |
Output is correct |
18 |
Correct |
10 ms |
9296 KB |
Output is correct |
19 |
Correct |
9 ms |
9296 KB |
Output is correct |
20 |
Correct |
10 ms |
9296 KB |
Output is correct |
21 |
Correct |
10 ms |
9296 KB |
Output is correct |
22 |
Correct |
9 ms |
9296 KB |
Output is correct |
23 |
Correct |
12 ms |
9296 KB |
Output is correct |
24 |
Correct |
11 ms |
9296 KB |
Output is correct |
25 |
Correct |
12 ms |
9296 KB |
Output is correct |
26 |
Correct |
11 ms |
9332 KB |
Output is correct |
27 |
Correct |
11 ms |
9376 KB |
Output is correct |
28 |
Correct |
12 ms |
9392 KB |
Output is correct |
29 |
Correct |
12 ms |
9408 KB |
Output is correct |
30 |
Correct |
11 ms |
9424 KB |
Output is correct |
31 |
Correct |
11 ms |
9468 KB |
Output is correct |
32 |
Correct |
11 ms |
9468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
403 ms |
45712 KB |
Output is correct |
2 |
Correct |
477 ms |
58352 KB |
Output is correct |
3 |
Correct |
402 ms |
62024 KB |
Output is correct |
4 |
Correct |
392 ms |
69772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
69772 KB |
Output is correct |
2 |
Correct |
11 ms |
69772 KB |
Output is correct |
3 |
Correct |
10 ms |
69772 KB |
Output is correct |
4 |
Correct |
12 ms |
69772 KB |
Output is correct |
5 |
Correct |
10 ms |
69772 KB |
Output is correct |
6 |
Correct |
10 ms |
69772 KB |
Output is correct |
7 |
Correct |
10 ms |
69772 KB |
Output is correct |
8 |
Correct |
9 ms |
69772 KB |
Output is correct |
9 |
Correct |
9 ms |
69772 KB |
Output is correct |
10 |
Correct |
9 ms |
69772 KB |
Output is correct |
11 |
Correct |
10 ms |
69772 KB |
Output is correct |
12 |
Correct |
10 ms |
69772 KB |
Output is correct |
13 |
Correct |
10 ms |
69772 KB |
Output is correct |
14 |
Correct |
10 ms |
69772 KB |
Output is correct |
15 |
Correct |
10 ms |
69772 KB |
Output is correct |
16 |
Correct |
11 ms |
69772 KB |
Output is correct |
17 |
Correct |
13 ms |
69772 KB |
Output is correct |
18 |
Correct |
12 ms |
69772 KB |
Output is correct |
19 |
Correct |
10 ms |
69772 KB |
Output is correct |
20 |
Correct |
9 ms |
69772 KB |
Output is correct |
21 |
Correct |
10 ms |
69772 KB |
Output is correct |
22 |
Correct |
10 ms |
69772 KB |
Output is correct |
23 |
Correct |
14 ms |
69772 KB |
Output is correct |
24 |
Correct |
9 ms |
69772 KB |
Output is correct |
25 |
Correct |
9 ms |
69772 KB |
Output is correct |
26 |
Correct |
11 ms |
69772 KB |
Output is correct |
27 |
Correct |
12 ms |
69772 KB |
Output is correct |
28 |
Correct |
12 ms |
69772 KB |
Output is correct |
29 |
Correct |
11 ms |
69772 KB |
Output is correct |
30 |
Correct |
12 ms |
69772 KB |
Output is correct |
31 |
Correct |
11 ms |
69772 KB |
Output is correct |
32 |
Correct |
16 ms |
69772 KB |
Output is correct |
33 |
Correct |
157 ms |
69772 KB |
Output is correct |
34 |
Correct |
154 ms |
69772 KB |
Output is correct |
35 |
Correct |
377 ms |
87876 KB |
Output is correct |
36 |
Correct |
368 ms |
98860 KB |
Output is correct |
37 |
Correct |
143 ms |
98860 KB |
Output is correct |
38 |
Correct |
365 ms |
103840 KB |
Output is correct |
39 |
Correct |
137 ms |
103840 KB |
Output is correct |
40 |
Correct |
367 ms |
111900 KB |
Output is correct |
41 |
Correct |
148 ms |
111900 KB |
Output is correct |
42 |
Correct |
170 ms |
111900 KB |
Output is correct |
43 |
Correct |
338 ms |
122296 KB |
Output is correct |
44 |
Correct |
341 ms |
128820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
128820 KB |
Output is correct |
2 |
Correct |
9 ms |
128820 KB |
Output is correct |
3 |
Correct |
11 ms |
128820 KB |
Output is correct |
4 |
Correct |
12 ms |
128820 KB |
Output is correct |
5 |
Correct |
11 ms |
128820 KB |
Output is correct |
6 |
Correct |
9 ms |
128820 KB |
Output is correct |
7 |
Correct |
10 ms |
128820 KB |
Output is correct |
8 |
Correct |
11 ms |
128820 KB |
Output is correct |
9 |
Correct |
10 ms |
128820 KB |
Output is correct |
10 |
Correct |
10 ms |
128820 KB |
Output is correct |
11 |
Correct |
10 ms |
128820 KB |
Output is correct |
12 |
Correct |
9 ms |
128820 KB |
Output is correct |
13 |
Correct |
9 ms |
128820 KB |
Output is correct |
14 |
Correct |
11 ms |
128820 KB |
Output is correct |
15 |
Correct |
10 ms |
128820 KB |
Output is correct |
16 |
Correct |
11 ms |
128820 KB |
Output is correct |
17 |
Correct |
10 ms |
128820 KB |
Output is correct |
18 |
Correct |
9 ms |
128820 KB |
Output is correct |
19 |
Correct |
9 ms |
128820 KB |
Output is correct |
20 |
Correct |
10 ms |
128820 KB |
Output is correct |
21 |
Correct |
10 ms |
128820 KB |
Output is correct |
22 |
Correct |
10 ms |
128820 KB |
Output is correct |
23 |
Correct |
11 ms |
128820 KB |
Output is correct |
24 |
Correct |
11 ms |
128820 KB |
Output is correct |
25 |
Correct |
11 ms |
128820 KB |
Output is correct |
26 |
Correct |
12 ms |
128820 KB |
Output is correct |
27 |
Correct |
11 ms |
128820 KB |
Output is correct |
28 |
Correct |
13 ms |
128820 KB |
Output is correct |
29 |
Correct |
12 ms |
128820 KB |
Output is correct |
30 |
Correct |
11 ms |
128820 KB |
Output is correct |
31 |
Correct |
11 ms |
128820 KB |
Output is correct |
32 |
Correct |
11 ms |
128820 KB |
Output is correct |
33 |
Correct |
405 ms |
133912 KB |
Output is correct |
34 |
Correct |
426 ms |
146392 KB |
Output is correct |
35 |
Correct |
413 ms |
150100 KB |
Output is correct |
36 |
Correct |
449 ms |
157804 KB |
Output is correct |
37 |
Correct |
155 ms |
157804 KB |
Output is correct |
38 |
Correct |
153 ms |
157804 KB |
Output is correct |
39 |
Correct |
384 ms |
175840 KB |
Output is correct |
40 |
Correct |
368 ms |
186536 KB |
Output is correct |
41 |
Correct |
149 ms |
186536 KB |
Output is correct |
42 |
Correct |
337 ms |
191672 KB |
Output is correct |
43 |
Correct |
143 ms |
191672 KB |
Output is correct |
44 |
Correct |
368 ms |
199620 KB |
Output is correct |
45 |
Correct |
140 ms |
199620 KB |
Output is correct |
46 |
Correct |
160 ms |
199620 KB |
Output is correct |
47 |
Correct |
354 ms |
210152 KB |
Output is correct |
48 |
Correct |
339 ms |
216504 KB |
Output is correct |
49 |
Correct |
286 ms |
216504 KB |
Output is correct |
50 |
Correct |
286 ms |
216504 KB |
Output is correct |
51 |
Correct |
443 ms |
239276 KB |
Output is correct |
52 |
Correct |
456 ms |
250872 KB |
Output is correct |
53 |
Correct |
344 ms |
250872 KB |
Output is correct |
54 |
Correct |
449 ms |
258044 KB |
Output is correct |
55 |
Correct |
208 ms |
258044 KB |
Output is correct |
56 |
Correct |
447 ms |
268004 KB |
Output is correct |
57 |
Correct |
216 ms |
268004 KB |
Output is correct |
58 |
Correct |
252 ms |
268004 KB |
Output is correct |
59 |
Correct |
355 ms |
279480 KB |
Output is correct |