#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
typedef long long ll;
const int MAXN = 5e5 + 10;
const ll MOD = 1e9 + 7;
ll X[MAXN], Y[MAXN];
inline ll mult(ll a, ll b) {return (a * b) % MOD;}
inline ll mult(ll a, ll b, ll c) {return (mult(a, b)*c) % MOD;}
ll exp(ll x, ll b)
{
if (b == 0) return 1LL;
if (b % 2) return mult(x, exp(x, b-1));
else return exp(mult(x, x), b/2);
}
int N;
struct node
{
ll prefX, sufX, y;
bool bigPref;
ll val;
node (ll PX = 0, ll SX = 0, ll YY = 0, bool BIG = false) : prefX(PX), sufX(SX), y(YY), bigPref(BIG) {val = mult(prefX, y);}
node operator+(node outro)
{
node resp;
if (outro.y >= y || outro.bigPref || outro.prefX >= y || (sufX * outro.prefX) >= y || (sufX * outro.prefX * outro.y) >= y)
resp = node( mult(prefX, sufX, outro.prefX), outro.sufX, outro.y, bigPref || outro.bigPref || (prefX * sufX) >= MOD || (prefX * sufX * outro.prefX) >= MOD );
else resp = node(prefX, mult(sufX, outro.prefX, outro.sufX), y, bigPref);
return resp;
}
} seg[4*MAXN];
void build(int pos, int ini, int fim)
{
if (ini == fim)
{
seg[pos] = node(X[ini], 1, Y[ini]);
return;
}
int m = (ini + fim) >> 1;
int e = 2*pos; int d = 2*pos + 1;
build(e, ini, m );
build(d, m+1, fim);
seg[pos] = seg[e] + seg[d];
}
void segUpdate(int pos, int ini, int fim, int id)
{
if (id < ini || id > fim) return;
if (ini == fim)
{
seg[pos] = node(X[ini], 1, Y[ini]);
return;
}
int m = (ini + fim) >> 1;
int e = 2*pos; int d = 2*pos + 1;
segUpdate(e, ini, m , id);
segUpdate(d, m+1, fim, id);
seg[pos] = seg[e] + seg[d];
}
int init(int _N, int _X[], int _Y[])
{
N = _N;
for (int i = 1; i <= N; i++) X[i] = _X[i-1], Y[i] = _Y[i-1];
build(1, 1, N);
return (int)seg[1].val;
}
int updateX(int id, int _val)
{
++id;
X[id] = _val;
segUpdate(1, 1, N, id);
return (int)seg[1].val;
}
int updateY(int id, int _val)
{
++id;
Y[id] = _val;
segUpdate(1, 1, N, id);
return (int)seg[1].val;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
78548 KB |
Output is correct |
2 |
Correct |
28 ms |
78576 KB |
Output is correct |
3 |
Correct |
28 ms |
78468 KB |
Output is correct |
4 |
Correct |
29 ms |
78572 KB |
Output is correct |
5 |
Correct |
36 ms |
78608 KB |
Output is correct |
6 |
Correct |
28 ms |
78580 KB |
Output is correct |
7 |
Correct |
28 ms |
78564 KB |
Output is correct |
8 |
Correct |
28 ms |
78568 KB |
Output is correct |
9 |
Correct |
29 ms |
78548 KB |
Output is correct |
10 |
Correct |
34 ms |
78568 KB |
Output is correct |
11 |
Correct |
29 ms |
78600 KB |
Output is correct |
12 |
Correct |
28 ms |
78548 KB |
Output is correct |
13 |
Correct |
28 ms |
78492 KB |
Output is correct |
14 |
Correct |
28 ms |
78568 KB |
Output is correct |
15 |
Correct |
29 ms |
78548 KB |
Output is correct |
16 |
Correct |
28 ms |
78516 KB |
Output is correct |
17 |
Correct |
28 ms |
78540 KB |
Output is correct |
18 |
Correct |
29 ms |
78540 KB |
Output is correct |
19 |
Correct |
29 ms |
78572 KB |
Output is correct |
20 |
Correct |
30 ms |
78548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
78532 KB |
Output is correct |
2 |
Correct |
29 ms |
78476 KB |
Output is correct |
3 |
Correct |
29 ms |
78580 KB |
Output is correct |
4 |
Correct |
32 ms |
78468 KB |
Output is correct |
5 |
Correct |
30 ms |
78572 KB |
Output is correct |
6 |
Correct |
29 ms |
78584 KB |
Output is correct |
7 |
Correct |
30 ms |
78508 KB |
Output is correct |
8 |
Correct |
30 ms |
78484 KB |
Output is correct |
9 |
Correct |
29 ms |
78568 KB |
Output is correct |
10 |
Correct |
30 ms |
78512 KB |
Output is correct |
11 |
Correct |
30 ms |
78564 KB |
Output is correct |
12 |
Correct |
30 ms |
78544 KB |
Output is correct |
13 |
Correct |
30 ms |
78584 KB |
Output is correct |
14 |
Correct |
29 ms |
78576 KB |
Output is correct |
15 |
Correct |
30 ms |
78580 KB |
Output is correct |
16 |
Correct |
30 ms |
78540 KB |
Output is correct |
17 |
Correct |
30 ms |
78604 KB |
Output is correct |
18 |
Correct |
29 ms |
78584 KB |
Output is correct |
19 |
Correct |
29 ms |
78576 KB |
Output is correct |
20 |
Correct |
30 ms |
78504 KB |
Output is correct |
21 |
Correct |
29 ms |
78548 KB |
Output is correct |
22 |
Correct |
30 ms |
78532 KB |
Output is correct |
23 |
Correct |
30 ms |
78568 KB |
Output is correct |
24 |
Correct |
31 ms |
78576 KB |
Output is correct |
25 |
Correct |
31 ms |
78608 KB |
Output is correct |
26 |
Correct |
30 ms |
78608 KB |
Output is correct |
27 |
Correct |
30 ms |
78572 KB |
Output is correct |
28 |
Correct |
30 ms |
78616 KB |
Output is correct |
29 |
Correct |
30 ms |
78568 KB |
Output is correct |
30 |
Correct |
30 ms |
78588 KB |
Output is correct |
31 |
Correct |
30 ms |
78548 KB |
Output is correct |
32 |
Correct |
32 ms |
78548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
91296 KB |
Output is correct |
2 |
Correct |
161 ms |
103884 KB |
Output is correct |
3 |
Correct |
145 ms |
94984 KB |
Output is correct |
4 |
Correct |
154 ms |
98892 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
30 ms |
78496 KB |
Output is correct |
2 |
Correct |
31 ms |
78496 KB |
Output is correct |
3 |
Correct |
33 ms |
78612 KB |
Output is correct |
4 |
Correct |
31 ms |
78572 KB |
Output is correct |
5 |
Correct |
31 ms |
78540 KB |
Output is correct |
6 |
Correct |
30 ms |
78564 KB |
Output is correct |
7 |
Correct |
30 ms |
78540 KB |
Output is correct |
8 |
Correct |
31 ms |
78460 KB |
Output is correct |
9 |
Correct |
30 ms |
78504 KB |
Output is correct |
10 |
Correct |
31 ms |
78548 KB |
Output is correct |
11 |
Correct |
31 ms |
78548 KB |
Output is correct |
12 |
Correct |
31 ms |
78548 KB |
Output is correct |
13 |
Correct |
30 ms |
78548 KB |
Output is correct |
14 |
Correct |
34 ms |
78488 KB |
Output is correct |
15 |
Correct |
30 ms |
78568 KB |
Output is correct |
16 |
Correct |
31 ms |
78580 KB |
Output is correct |
17 |
Correct |
30 ms |
78508 KB |
Output is correct |
18 |
Correct |
31 ms |
78508 KB |
Output is correct |
19 |
Correct |
30 ms |
78532 KB |
Output is correct |
20 |
Correct |
30 ms |
78552 KB |
Output is correct |
21 |
Correct |
30 ms |
78524 KB |
Output is correct |
22 |
Correct |
30 ms |
78584 KB |
Output is correct |
23 |
Correct |
31 ms |
78520 KB |
Output is correct |
24 |
Correct |
33 ms |
78596 KB |
Output is correct |
25 |
Correct |
31 ms |
78580 KB |
Output is correct |
26 |
Correct |
31 ms |
78588 KB |
Output is correct |
27 |
Correct |
36 ms |
78576 KB |
Output is correct |
28 |
Correct |
30 ms |
78540 KB |
Output is correct |
29 |
Correct |
29 ms |
78608 KB |
Output is correct |
30 |
Correct |
31 ms |
78532 KB |
Output is correct |
31 |
Correct |
29 ms |
78548 KB |
Output is correct |
32 |
Correct |
30 ms |
78580 KB |
Output is correct |
33 |
Correct |
67 ms |
94332 KB |
Output is correct |
34 |
Correct |
67 ms |
94236 KB |
Output is correct |
35 |
Correct |
82 ms |
101244 KB |
Output is correct |
36 |
Correct |
85 ms |
101272 KB |
Output is correct |
37 |
Correct |
58 ms |
92420 KB |
Output is correct |
38 |
Correct |
59 ms |
93300 KB |
Output is correct |
39 |
Correct |
54 ms |
92308 KB |
Output is correct |
40 |
Correct |
68 ms |
96224 KB |
Output is correct |
41 |
Correct |
58 ms |
92360 KB |
Output is correct |
42 |
Correct |
53 ms |
92476 KB |
Output is correct |
43 |
Correct |
67 ms |
96684 KB |
Output is correct |
44 |
Correct |
72 ms |
96680 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
78548 KB |
Output is correct |
2 |
Correct |
31 ms |
78548 KB |
Output is correct |
3 |
Correct |
34 ms |
78560 KB |
Output is correct |
4 |
Correct |
31 ms |
78584 KB |
Output is correct |
5 |
Correct |
30 ms |
78472 KB |
Output is correct |
6 |
Correct |
30 ms |
78576 KB |
Output is correct |
7 |
Correct |
35 ms |
78464 KB |
Output is correct |
8 |
Correct |
30 ms |
78584 KB |
Output is correct |
9 |
Correct |
30 ms |
78548 KB |
Output is correct |
10 |
Correct |
30 ms |
78488 KB |
Output is correct |
11 |
Correct |
31 ms |
78528 KB |
Output is correct |
12 |
Correct |
31 ms |
78676 KB |
Output is correct |
13 |
Correct |
30 ms |
78568 KB |
Output is correct |
14 |
Correct |
30 ms |
78568 KB |
Output is correct |
15 |
Correct |
33 ms |
78668 KB |
Output is correct |
16 |
Correct |
30 ms |
78488 KB |
Output is correct |
17 |
Correct |
30 ms |
78512 KB |
Output is correct |
18 |
Correct |
32 ms |
78456 KB |
Output is correct |
19 |
Correct |
30 ms |
78588 KB |
Output is correct |
20 |
Correct |
35 ms |
78564 KB |
Output is correct |
21 |
Correct |
30 ms |
78576 KB |
Output is correct |
22 |
Correct |
30 ms |
78564 KB |
Output is correct |
23 |
Correct |
30 ms |
78548 KB |
Output is correct |
24 |
Correct |
31 ms |
78560 KB |
Output is correct |
25 |
Correct |
35 ms |
78580 KB |
Output is correct |
26 |
Correct |
30 ms |
78520 KB |
Output is correct |
27 |
Correct |
30 ms |
78548 KB |
Output is correct |
28 |
Correct |
30 ms |
78552 KB |
Output is correct |
29 |
Correct |
30 ms |
78588 KB |
Output is correct |
30 |
Correct |
30 ms |
78532 KB |
Output is correct |
31 |
Correct |
30 ms |
78580 KB |
Output is correct |
32 |
Correct |
30 ms |
78576 KB |
Output is correct |
33 |
Correct |
94 ms |
95052 KB |
Output is correct |
34 |
Correct |
175 ms |
103944 KB |
Output is correct |
35 |
Correct |
141 ms |
95088 KB |
Output is correct |
36 |
Correct |
159 ms |
98844 KB |
Output is correct |
37 |
Correct |
72 ms |
94320 KB |
Output is correct |
38 |
Correct |
68 ms |
94232 KB |
Output is correct |
39 |
Correct |
82 ms |
101216 KB |
Output is correct |
40 |
Correct |
84 ms |
101188 KB |
Output is correct |
41 |
Correct |
62 ms |
92480 KB |
Output is correct |
42 |
Correct |
59 ms |
93452 KB |
Output is correct |
43 |
Correct |
53 ms |
92360 KB |
Output is correct |
44 |
Correct |
67 ms |
96240 KB |
Output is correct |
45 |
Correct |
52 ms |
92376 KB |
Output is correct |
46 |
Correct |
53 ms |
92484 KB |
Output is correct |
47 |
Correct |
65 ms |
96688 KB |
Output is correct |
48 |
Correct |
65 ms |
96700 KB |
Output is correct |
49 |
Correct |
147 ms |
96244 KB |
Output is correct |
50 |
Correct |
152 ms |
96320 KB |
Output is correct |
51 |
Correct |
116 ms |
103292 KB |
Output is correct |
52 |
Correct |
135 ms |
102640 KB |
Output is correct |
53 |
Correct |
143 ms |
94656 KB |
Output is correct |
54 |
Correct |
96 ms |
95148 KB |
Output is correct |
55 |
Correct |
85 ms |
93384 KB |
Output is correct |
56 |
Correct |
102 ms |
98044 KB |
Output is correct |
57 |
Correct |
85 ms |
94004 KB |
Output is correct |
58 |
Correct |
87 ms |
94540 KB |
Output is correct |
59 |
Correct |
64 ms |
96684 KB |
Output is correct |