#include "horses.h"
#include <cassert>
#include <vector>
#include <ios>
#define REP(i, n) for (int i=0; i<(n); ++i)
#define FOR(i, p, n) for (int i=(p); i<=(n); ++i)
#define V std::vector
typedef V <int> vi;
typedef long long ll;
typedef V <ll> vll;
#define CAP (ll(1e9+5))
#define MOD 1'000'000'007
struct stilnode{
ll m,c; // modulo i z capem
stilnode(){
m=c=0;
}
stilnode(int i){
m=c=i;
}
stilnode(ll nm, ll nc){
m=nm,c=nc;
}
stilnode operator^(const stilnode &i) const{
return {m*i.m%MOD, std::min(c*i.c, CAP)};
}
};
struct stiltype{
V <stilnode> t;
int comp;
stiltype(){}
stiltype(int n, int X[]){
for (comp=1; comp<n; comp<<=1);
t.resize(comp<<1);
--comp;
REP(i, n)
t[i+comp+1]=X[i];
for (int i=comp; i; --i)
t[i]=t[i<<1]^t[(i<<1)+1];
}
void wst(int i, int w){
t[i+=comp]=w;
for (i>>=1; i; i>>=1)
t[i]=t[i<<1]^t[(i<<1)+1];
}
stilnode zap(int p, int k){
stilnode r={1, 1};
for (p+=comp,k+=comp+1; p<k; p>>=1,k>>=1){
if (p&1)
r=r^t[p++];
if (k&1)
r=r^t[--k];
}
return r;
}
} stil;
struct stmintype{
vi t;
vi Y;
int comp;
int lacz(int i, int j){
if (!i||!j)
return i+j;
if (i>j)
std::swap(i, j);
ll lew=Y[i],praw=Y[j]*stil.zap(i+1, j).c;
return lew>=praw ? i : j;
}
stmintype(){}
stmintype(int n, int v[]){ // translacja v!!!
for (comp=1; comp<n; comp<<=1);
t.resize(comp<<1);
Y.resize(n+1);
--comp;
REP(i, n)
Y[i+1]=v[i];
FOR(i, 1, n)
t[i+comp]=i;
for (int i=comp; i; --i)
t[i]=lacz(t[i<<1], t[(i<<1)+1]);
}
void wst(int i, int w=0){
if (w) // w=0 -> noop
Y[i]=w;
for (i+=comp,i>>=1; i; i>>=1)
t[i]=lacz(t[i<<1], t[(i<<1)+1]);
}
} stmin;
int n;
int wynbru(){
ll l=1,w=0;
for (int i=1; i<=n; ++i){
l*=stil.t[i+stil.comp].m;
w=std::max(w, l*stmin.Y[i]);
}
return int(w%MOD);
}
int wyn(){
int wpos=stmin.t[1];
ll w=stil.zap(1, wpos).m*stmin.Y[wpos]%MOD;
#ifdef LOCAL
assert(w==wynbru());
printf("%lld\n", w);
#endif
return int(w);
}
int init(int N, int X[], int Y[]) {
n=N;
stil=stiltype(N, X);
stmin=stmintype(N, Y);
return wyn();
}
int updateX(int pos, int val) {
++pos;
stil.wst(pos, val);
stmin.wst(pos);
return wyn();
}
int updateY(int pos, int val) {
++pos;
stmin.wst(pos, val);
return wyn();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
336 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
464 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
27596 KB |
Output is correct |
2 |
Correct |
144 ms |
40152 KB |
Output is correct |
3 |
Correct |
142 ms |
31456 KB |
Output is correct |
4 |
Correct |
144 ms |
35276 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
292 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
56 ms |
29720 KB |
Output is correct |
34 |
Correct |
51 ms |
30612 KB |
Output is correct |
35 |
Correct |
57 ms |
37512 KB |
Output is correct |
36 |
Correct |
59 ms |
37492 KB |
Output is correct |
37 |
Correct |
41 ms |
29000 KB |
Output is correct |
38 |
Correct |
34 ms |
29776 KB |
Output is correct |
39 |
Correct |
36 ms |
28744 KB |
Output is correct |
40 |
Correct |
49 ms |
32584 KB |
Output is correct |
41 |
Correct |
33 ms |
28748 KB |
Output is correct |
42 |
Correct |
32 ms |
28784 KB |
Output is correct |
43 |
Correct |
39 ms |
32976 KB |
Output is correct |
44 |
Correct |
38 ms |
32972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
296 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
464 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
70 ms |
31492 KB |
Output is correct |
34 |
Correct |
146 ms |
40212 KB |
Output is correct |
35 |
Correct |
147 ms |
31352 KB |
Output is correct |
36 |
Correct |
150 ms |
35272 KB |
Output is correct |
37 |
Correct |
50 ms |
30712 KB |
Output is correct |
38 |
Correct |
48 ms |
30644 KB |
Output is correct |
39 |
Correct |
64 ms |
37588 KB |
Output is correct |
40 |
Correct |
60 ms |
37580 KB |
Output is correct |
41 |
Correct |
44 ms |
28876 KB |
Output is correct |
42 |
Correct |
35 ms |
29696 KB |
Output is correct |
43 |
Correct |
35 ms |
28748 KB |
Output is correct |
44 |
Correct |
52 ms |
32588 KB |
Output is correct |
45 |
Correct |
38 ms |
28744 KB |
Output is correct |
46 |
Correct |
43 ms |
28832 KB |
Output is correct |
47 |
Correct |
37 ms |
33036 KB |
Output is correct |
48 |
Correct |
39 ms |
33160 KB |
Output is correct |
49 |
Correct |
199 ms |
32676 KB |
Output is correct |
50 |
Correct |
201 ms |
32608 KB |
Output is correct |
51 |
Correct |
96 ms |
39464 KB |
Output is correct |
52 |
Correct |
104 ms |
38900 KB |
Output is correct |
53 |
Correct |
220 ms |
30960 KB |
Output is correct |
54 |
Correct |
89 ms |
31572 KB |
Output is correct |
55 |
Correct |
107 ms |
29736 KB |
Output is correct |
56 |
Correct |
140 ms |
34432 KB |
Output is correct |
57 |
Correct |
82 ms |
30448 KB |
Output is correct |
58 |
Correct |
96 ms |
31036 KB |
Output is correct |
59 |
Correct |
38 ms |
32972 KB |
Output is correct |