#include<bits/stdc++.h>
#include "horses.h"
using namespace std;
using ll=long long;
const ll MAX_VAL=500*1000+5,DECA=(1<<19),MODU=1000*1000*1000+7;
ll nbVal,rep;
ll multi[MAX_VAL],benef[DECA];
ll arbreMax[2*DECA],arbreProd[2*DECA];
set<ll> listeInter;
ll calcMax(ll deb,ll fin) {
if (deb==fin) {
return arbreMax[deb];
}
if (deb%2==1) {
return max(arbreMax[deb],calcMax(deb+1,fin));
}
if (fin%2==0) {
return max(arbreMax[fin],calcMax(deb,fin-1));
}
return calcMax(deb/2,fin/2);
}
ll calcProd(ll deb,ll fin) {
if (deb==fin) {
return arbreProd[deb];
}
if (deb%2==1) {
return (arbreProd[deb]*calcProd(deb+1,fin))%MODU;
}
if (fin%2==0) {
return (arbreProd[fin]*calcProd(deb,fin-1))%MODU;
}
return calcProd(deb/2,fin/2);
}
void majMax(ll pos,ll val) {
benef[pos]=val;
pos+=DECA;
arbreMax[pos]=val;
while (pos>1) {
pos/=2;
arbreMax[pos]=max(arbreMax[2*pos],arbreMax[2*pos+1]);
}
}
void majProd(ll pos,ll val) {
multi[pos]=val;
pos+=DECA;
arbreProd[pos]=val;
while (pos>1) {
pos/=2;
arbreProd[pos]=(arbreProd[2*pos]*arbreProd[2*pos+1])%MODU;
}
}
void calc() {
auto it=listeInter.end();
it--;
ll prodCour=1,meilleur=0;
while ((*it)!=-1 and prodCour*multi[(*it)]<MODU) {
prodCour*=multi[(*it)];
meilleur=max(meilleur,calcMax(DECA+(*it),DECA+nbVal-1));
meilleur*=multi[(*it)];
it--;
}
//cout<<meilleur<<" "<<max((*it),(ll)0)<<" ";
meilleur=max(meilleur,calcMax(DECA+max((*it),(ll)0),DECA+nbVal-1));
//cout<<meilleur<<endl;
if ((*it)==-1) {
ll maxi=calcMax(DECA,DECA+nbVal-1);
//cout<<meilleur<<" "<<maxi<<endl;
if (meilleur>maxi) {
rep=meilleur%MODU;
}
else {
rep=maxi;
}
}
else {
it++;
meilleur%=MODU;
if ((*it)>0) {
meilleur*=calcProd(DECA,DECA+(*it)-1);
}
rep=meilleur%MODU;
}
//cout<<rep<<endl;
}
int init(int N, int X[], int Y[]) {
nbVal=N;
for (ll i=0;i<nbVal;i++) {
multi[i]=X[i];
benef[i]=Y[i];
}
for (ll i=0;i<2*DECA;i++) {
arbreProd[i]=1;
}
for (ll i=0;i<nbVal;i++) {
arbreProd[DECA+i]=multi[i];
arbreMax[DECA+i]=benef[i];
}
for (ll i=DECA-1;i>0;i--) {
arbreProd[i]=(arbreProd[2*i]*arbreProd[2*i+1])%MODU;
arbreMax[i]=max(arbreMax[2*i],arbreMax[2*i+1]);
}
for (ll i=0;i<nbVal;i++) {
if (multi[i]>1) {
listeInter.insert(i);
}
}
listeInter.insert(-1);
//cout<<calc()<<endl;
calc();
return (int)rep;
}
int updateX(int pos, int val) {
if (multi[pos]>1) {
listeInter.erase(pos);
}
majProd(pos,val);
if (multi[pos]>1) {
listeInter.insert(pos);
}
/*for (auto i:listeInter) {
cout<<i<<" ";
}
cout<<": ";*/
calc();
return (int)rep;
}
int updateY(int pos, int val) {
majMax(pos,val);
calc();
return (int)rep;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
11 ms |
12608 KB |
Output is correct |
2 |
Correct |
7 ms |
12752 KB |
Output is correct |
3 |
Correct |
7 ms |
12628 KB |
Output is correct |
4 |
Correct |
6 ms |
12628 KB |
Output is correct |
5 |
Correct |
7 ms |
12628 KB |
Output is correct |
6 |
Correct |
7 ms |
12628 KB |
Output is correct |
7 |
Correct |
7 ms |
12628 KB |
Output is correct |
8 |
Correct |
8 ms |
12628 KB |
Output is correct |
9 |
Correct |
7 ms |
12628 KB |
Output is correct |
10 |
Correct |
7 ms |
12628 KB |
Output is correct |
11 |
Correct |
7 ms |
12592 KB |
Output is correct |
12 |
Correct |
7 ms |
12628 KB |
Output is correct |
13 |
Correct |
7 ms |
12628 KB |
Output is correct |
14 |
Correct |
7 ms |
12628 KB |
Output is correct |
15 |
Correct |
7 ms |
12628 KB |
Output is correct |
16 |
Correct |
6 ms |
12628 KB |
Output is correct |
17 |
Correct |
7 ms |
12628 KB |
Output is correct |
18 |
Correct |
7 ms |
12628 KB |
Output is correct |
19 |
Correct |
10 ms |
12628 KB |
Output is correct |
20 |
Correct |
8 ms |
12628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
12620 KB |
Output is correct |
2 |
Correct |
7 ms |
12628 KB |
Output is correct |
3 |
Correct |
7 ms |
12628 KB |
Output is correct |
4 |
Correct |
6 ms |
12628 KB |
Output is correct |
5 |
Correct |
7 ms |
12628 KB |
Output is correct |
6 |
Correct |
7 ms |
12628 KB |
Output is correct |
7 |
Correct |
8 ms |
12628 KB |
Output is correct |
8 |
Correct |
7 ms |
12628 KB |
Output is correct |
9 |
Correct |
9 ms |
12628 KB |
Output is correct |
10 |
Correct |
7 ms |
12628 KB |
Output is correct |
11 |
Correct |
7 ms |
12628 KB |
Output is correct |
12 |
Correct |
7 ms |
12628 KB |
Output is correct |
13 |
Correct |
7 ms |
12628 KB |
Output is correct |
14 |
Correct |
6 ms |
12628 KB |
Output is correct |
15 |
Correct |
8 ms |
12628 KB |
Output is correct |
16 |
Correct |
6 ms |
12628 KB |
Output is correct |
17 |
Correct |
6 ms |
12628 KB |
Output is correct |
18 |
Correct |
7 ms |
12628 KB |
Output is correct |
19 |
Correct |
6 ms |
12628 KB |
Output is correct |
20 |
Correct |
9 ms |
12628 KB |
Output is correct |
21 |
Correct |
6 ms |
12568 KB |
Output is correct |
22 |
Correct |
6 ms |
12628 KB |
Output is correct |
23 |
Correct |
6 ms |
12628 KB |
Output is correct |
24 |
Correct |
6 ms |
12628 KB |
Output is correct |
25 |
Correct |
7 ms |
12740 KB |
Output is correct |
26 |
Correct |
7 ms |
12744 KB |
Output is correct |
27 |
Correct |
8 ms |
12628 KB |
Output is correct |
28 |
Correct |
10 ms |
12736 KB |
Output is correct |
29 |
Correct |
9 ms |
12628 KB |
Output is correct |
30 |
Correct |
9 ms |
12740 KB |
Output is correct |
31 |
Correct |
9 ms |
12628 KB |
Output is correct |
32 |
Correct |
10 ms |
12628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
184 ms |
52704 KB |
Output is correct |
2 |
Correct |
247 ms |
65256 KB |
Output is correct |
3 |
Correct |
220 ms |
56536 KB |
Output is correct |
4 |
Correct |
260 ms |
60396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
12628 KB |
Output is correct |
2 |
Correct |
7 ms |
12628 KB |
Output is correct |
3 |
Correct |
6 ms |
12628 KB |
Output is correct |
4 |
Correct |
7 ms |
12628 KB |
Output is correct |
5 |
Correct |
6 ms |
12628 KB |
Output is correct |
6 |
Correct |
8 ms |
12628 KB |
Output is correct |
7 |
Correct |
7 ms |
12628 KB |
Output is correct |
8 |
Correct |
8 ms |
12628 KB |
Output is correct |
9 |
Correct |
6 ms |
12600 KB |
Output is correct |
10 |
Correct |
7 ms |
12628 KB |
Output is correct |
11 |
Correct |
6 ms |
12628 KB |
Output is correct |
12 |
Correct |
7 ms |
12628 KB |
Output is correct |
13 |
Correct |
6 ms |
12628 KB |
Output is correct |
14 |
Correct |
7 ms |
12628 KB |
Output is correct |
15 |
Correct |
9 ms |
12628 KB |
Output is correct |
16 |
Correct |
7 ms |
12628 KB |
Output is correct |
17 |
Correct |
6 ms |
12628 KB |
Output is correct |
18 |
Correct |
8 ms |
12628 KB |
Output is correct |
19 |
Correct |
8 ms |
12628 KB |
Output is correct |
20 |
Correct |
7 ms |
12628 KB |
Output is correct |
21 |
Correct |
6 ms |
12628 KB |
Output is correct |
22 |
Correct |
7 ms |
12628 KB |
Output is correct |
23 |
Correct |
7 ms |
12628 KB |
Output is correct |
24 |
Correct |
9 ms |
12628 KB |
Output is correct |
25 |
Correct |
7 ms |
12756 KB |
Output is correct |
26 |
Correct |
7 ms |
12756 KB |
Output is correct |
27 |
Correct |
8 ms |
12628 KB |
Output is correct |
28 |
Correct |
7 ms |
12668 KB |
Output is correct |
29 |
Correct |
7 ms |
12628 KB |
Output is correct |
30 |
Correct |
7 ms |
12756 KB |
Output is correct |
31 |
Correct |
7 ms |
12628 KB |
Output is correct |
32 |
Correct |
7 ms |
12628 KB |
Output is correct |
33 |
Correct |
36 ms |
32360 KB |
Output is correct |
34 |
Correct |
33 ms |
32416 KB |
Output is correct |
35 |
Correct |
150 ms |
62724 KB |
Output is correct |
36 |
Correct |
142 ms |
62560 KB |
Output is correct |
37 |
Correct |
38 ms |
30480 KB |
Output is correct |
38 |
Correct |
70 ms |
43284 KB |
Output is correct |
39 |
Correct |
26 ms |
30336 KB |
Output is correct |
40 |
Correct |
138 ms |
57736 KB |
Output is correct |
41 |
Correct |
25 ms |
30348 KB |
Output is correct |
42 |
Correct |
28 ms |
30360 KB |
Output is correct |
43 |
Correct |
126 ms |
58128 KB |
Output is correct |
44 |
Correct |
125 ms |
58056 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
12628 KB |
Output is correct |
2 |
Correct |
6 ms |
12628 KB |
Output is correct |
3 |
Correct |
6 ms |
12628 KB |
Output is correct |
4 |
Correct |
7 ms |
12628 KB |
Output is correct |
5 |
Correct |
7 ms |
12628 KB |
Output is correct |
6 |
Correct |
7 ms |
12628 KB |
Output is correct |
7 |
Correct |
7 ms |
12628 KB |
Output is correct |
8 |
Correct |
7 ms |
12560 KB |
Output is correct |
9 |
Correct |
8 ms |
12628 KB |
Output is correct |
10 |
Correct |
8 ms |
12516 KB |
Output is correct |
11 |
Correct |
7 ms |
12628 KB |
Output is correct |
12 |
Correct |
7 ms |
12628 KB |
Output is correct |
13 |
Correct |
7 ms |
12628 KB |
Output is correct |
14 |
Correct |
9 ms |
12628 KB |
Output is correct |
15 |
Correct |
7 ms |
12628 KB |
Output is correct |
16 |
Correct |
7 ms |
12628 KB |
Output is correct |
17 |
Correct |
7 ms |
12628 KB |
Output is correct |
18 |
Correct |
9 ms |
12628 KB |
Output is correct |
19 |
Correct |
7 ms |
12628 KB |
Output is correct |
20 |
Correct |
8 ms |
12592 KB |
Output is correct |
21 |
Correct |
7 ms |
12676 KB |
Output is correct |
22 |
Correct |
8 ms |
12628 KB |
Output is correct |
23 |
Correct |
7 ms |
12628 KB |
Output is correct |
24 |
Correct |
8 ms |
12628 KB |
Output is correct |
25 |
Correct |
7 ms |
12676 KB |
Output is correct |
26 |
Correct |
7 ms |
12756 KB |
Output is correct |
27 |
Correct |
8 ms |
12756 KB |
Output is correct |
28 |
Correct |
8 ms |
12756 KB |
Output is correct |
29 |
Correct |
7 ms |
12628 KB |
Output is correct |
30 |
Correct |
7 ms |
12740 KB |
Output is correct |
31 |
Correct |
9 ms |
12628 KB |
Output is correct |
32 |
Correct |
8 ms |
12628 KB |
Output is correct |
33 |
Correct |
177 ms |
56528 KB |
Output is correct |
34 |
Correct |
254 ms |
65228 KB |
Output is correct |
35 |
Correct |
207 ms |
56524 KB |
Output is correct |
36 |
Correct |
263 ms |
60380 KB |
Output is correct |
37 |
Correct |
33 ms |
32332 KB |
Output is correct |
38 |
Correct |
32 ms |
32316 KB |
Output is correct |
39 |
Correct |
144 ms |
62732 KB |
Output is correct |
40 |
Correct |
147 ms |
62616 KB |
Output is correct |
41 |
Correct |
41 ms |
30592 KB |
Output is correct |
42 |
Correct |
69 ms |
43344 KB |
Output is correct |
43 |
Correct |
26 ms |
30348 KB |
Output is correct |
44 |
Correct |
128 ms |
57672 KB |
Output is correct |
45 |
Correct |
30 ms |
30412 KB |
Output is correct |
46 |
Correct |
29 ms |
30400 KB |
Output is correct |
47 |
Correct |
124 ms |
58116 KB |
Output is correct |
48 |
Correct |
124 ms |
58176 KB |
Output is correct |
49 |
Correct |
80 ms |
35404 KB |
Output is correct |
50 |
Correct |
77 ms |
35340 KB |
Output is correct |
51 |
Correct |
186 ms |
64536 KB |
Output is correct |
52 |
Correct |
173 ms |
64076 KB |
Output is correct |
53 |
Correct |
172 ms |
33680 KB |
Output is correct |
54 |
Correct |
119 ms |
47180 KB |
Output is correct |
55 |
Correct |
69 ms |
31308 KB |
Output is correct |
56 |
Correct |
186 ms |
59528 KB |
Output is correct |
57 |
Correct |
76 ms |
31992 KB |
Output is correct |
58 |
Correct |
97 ms |
32432 KB |
Output is correct |
59 |
Correct |
124 ms |
58140 KB |
Output is correct |