#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], MX[MAXN];
struct node
{
ll k, x;
ll val;
ll lzK = 1, lzX = -1;
node(ll KK = 0, ll XX = 0) {k = KK; x = XX; val = ((k * x) % MOD);}
node operator+(node outro)
{
if (val > outro.val) return *this;
return outro;
}
} seg[4*MAXN];
int N;
ll exp(ll x, ll y)
{
if (y == 0) return 1;
if (y == 1) return x;
if (y % 2) return ((x * exp(x, y-1)) % MOD);
else
{
ll aux = exp(x, (y / 2));
return ((aux * aux) % MOD);
}
}
void refreshK(int pos, int ini, int fim)
{
if (seg[pos].lzK == 1) return;
seg[pos].k = ((seg[pos].k * seg[pos].lzK) % MOD);
seg[pos].val = ((seg[pos].x * seg[pos].k) % MOD);
if (ini != fim)
{
int e = 2*pos; int d = 2*pos + 1;
seg[e].lzK *= seg[pos].lzK; seg[e].lzK %= MOD;
seg[d].lzK *= seg[pos].lzK; seg[d].lzK %= MOD;
}
seg[pos].lzK = 1;
}
void refreshX(int pos, int ini, int fim)
{
if (seg[pos].lzX == -1) return;
seg[pos].x = seg[pos].lzX;
seg[pos].val = ((seg[pos].k * seg[pos].x) % MOD);
//Nesse caso, sempre temos que ini == fim
seg[pos].lzX = -1;
}
void refresh(int pos, int ini, int fim)
{
refreshK(pos, ini, fim);
refreshX(pos, ini, fim);
}
void update(int pos, int ini, int fim, int p, int q, ll valK, ll valX)
{
refresh(pos, ini, fim);
if (q < ini || p > fim) return;
if (p <= ini && fim <= q)
{
if (valX == -1) seg[pos].lzK = valK;
else seg[pos].lzX = valX;
refresh(pos, ini, fim);
return;
}
int m = (ini + fim) >> 1;
int e = 2*pos; int d = 2*pos + 1;
update(e, ini, m, p, q, valK, valX);
update(d, m+1, fim, p, q, valK, valX);
seg[pos] = seg[e] + seg[d];
}
void build(int pos, int ini, int fim)
{
if (ini == fim)
{
seg[pos] = node(MX[ini], 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];
}
int init(int _N, int _X[], int _Y[])
{
N = _N;
MX[0] = 1;
for (int i = 1; i <= N; i++) {X[i] = _X[i-1]; MX[i] = X[i] * MX[i-1]; Y[i] = _Y[i-1];}
build(1, 1, N);
// for (int i = 1; i <= N; i++) cerr << X[i] << '\n';
return (int)(seg[1].val);
}
int updateX(int id, int _val)
{
id++;
ll val = (long long)(_val);
update(1, 1, N, id, N, ((exp(X[id], (MOD-2)) * val) % MOD), -1);
X[id] = val;
return (int)(seg[1].val);
}
int updateY(int id, int _val)
{
id++;
ll val = (long long)(_val);
update(1, 1, N, id, id, 1, val);
Y[id] = val;
return (int)(seg[1].val);
}
Compilation message
horses.cpp: In function 'void refreshX(int, int, int)':
horses.cpp:53:28: warning: unused parameter 'ini' [-Wunused-parameter]
53 | void refreshX(int pos, int ini, int fim)
| ~~~~^~~
horses.cpp:53:37: warning: unused parameter 'fim' [-Wunused-parameter]
53 | void refreshX(int pos, int ini, int fim)
| ~~~~^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
78564 KB |
Output is correct |
2 |
Correct |
35 ms |
78524 KB |
Output is correct |
3 |
Correct |
31 ms |
78588 KB |
Output is correct |
4 |
Correct |
32 ms |
78588 KB |
Output is correct |
5 |
Correct |
41 ms |
78572 KB |
Output is correct |
6 |
Correct |
37 ms |
78520 KB |
Output is correct |
7 |
Correct |
31 ms |
78604 KB |
Output is correct |
8 |
Correct |
31 ms |
78580 KB |
Output is correct |
9 |
Correct |
31 ms |
78588 KB |
Output is correct |
10 |
Correct |
32 ms |
78580 KB |
Output is correct |
11 |
Correct |
34 ms |
78668 KB |
Output is correct |
12 |
Correct |
32 ms |
78516 KB |
Output is correct |
13 |
Correct |
33 ms |
78476 KB |
Output is correct |
14 |
Correct |
32 ms |
78568 KB |
Output is correct |
15 |
Correct |
33 ms |
78580 KB |
Output is correct |
16 |
Correct |
32 ms |
78520 KB |
Output is correct |
17 |
Correct |
32 ms |
78548 KB |
Output is correct |
18 |
Correct |
31 ms |
78572 KB |
Output is correct |
19 |
Correct |
33 ms |
78500 KB |
Output is correct |
20 |
Correct |
33 ms |
78568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
78552 KB |
Output is correct |
2 |
Correct |
33 ms |
78576 KB |
Output is correct |
3 |
Correct |
33 ms |
78576 KB |
Output is correct |
4 |
Correct |
32 ms |
78500 KB |
Output is correct |
5 |
Correct |
32 ms |
78512 KB |
Output is correct |
6 |
Correct |
32 ms |
78572 KB |
Output is correct |
7 |
Correct |
36 ms |
78484 KB |
Output is correct |
8 |
Correct |
35 ms |
78540 KB |
Output is correct |
9 |
Correct |
33 ms |
78476 KB |
Output is correct |
10 |
Correct |
32 ms |
78572 KB |
Output is correct |
11 |
Correct |
32 ms |
78544 KB |
Output is correct |
12 |
Correct |
32 ms |
78548 KB |
Output is correct |
13 |
Correct |
32 ms |
78616 KB |
Output is correct |
14 |
Correct |
32 ms |
78592 KB |
Output is correct |
15 |
Correct |
33 ms |
78576 KB |
Output is correct |
16 |
Correct |
32 ms |
78548 KB |
Output is correct |
17 |
Correct |
32 ms |
78512 KB |
Output is correct |
18 |
Correct |
39 ms |
78536 KB |
Output is correct |
19 |
Correct |
35 ms |
78488 KB |
Output is correct |
20 |
Correct |
32 ms |
78560 KB |
Output is correct |
21 |
Incorrect |
32 ms |
78560 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
100 ms |
98952 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
78500 KB |
Output is correct |
2 |
Correct |
38 ms |
78544 KB |
Output is correct |
3 |
Correct |
34 ms |
78592 KB |
Output is correct |
4 |
Correct |
32 ms |
78520 KB |
Output is correct |
5 |
Correct |
32 ms |
78600 KB |
Output is correct |
6 |
Correct |
38 ms |
78576 KB |
Output is correct |
7 |
Correct |
31 ms |
78564 KB |
Output is correct |
8 |
Correct |
32 ms |
78512 KB |
Output is correct |
9 |
Correct |
32 ms |
78564 KB |
Output is correct |
10 |
Correct |
32 ms |
78596 KB |
Output is correct |
11 |
Correct |
32 ms |
78516 KB |
Output is correct |
12 |
Correct |
38 ms |
78576 KB |
Output is correct |
13 |
Correct |
32 ms |
78540 KB |
Output is correct |
14 |
Correct |
37 ms |
78544 KB |
Output is correct |
15 |
Correct |
39 ms |
78544 KB |
Output is correct |
16 |
Correct |
32 ms |
78540 KB |
Output is correct |
17 |
Correct |
33 ms |
78576 KB |
Output is correct |
18 |
Correct |
32 ms |
78580 KB |
Output is correct |
19 |
Correct |
35 ms |
78572 KB |
Output is correct |
20 |
Correct |
39 ms |
78504 KB |
Output is correct |
21 |
Incorrect |
34 ms |
78592 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
78548 KB |
Output is correct |
2 |
Correct |
32 ms |
78592 KB |
Output is correct |
3 |
Correct |
32 ms |
78580 KB |
Output is correct |
4 |
Correct |
33 ms |
78548 KB |
Output is correct |
5 |
Correct |
36 ms |
78592 KB |
Output is correct |
6 |
Correct |
33 ms |
78504 KB |
Output is correct |
7 |
Correct |
32 ms |
78588 KB |
Output is correct |
8 |
Correct |
32 ms |
78520 KB |
Output is correct |
9 |
Correct |
35 ms |
78576 KB |
Output is correct |
10 |
Correct |
32 ms |
78564 KB |
Output is correct |
11 |
Correct |
33 ms |
78624 KB |
Output is correct |
12 |
Correct |
33 ms |
78540 KB |
Output is correct |
13 |
Correct |
33 ms |
78504 KB |
Output is correct |
14 |
Correct |
32 ms |
78584 KB |
Output is correct |
15 |
Correct |
40 ms |
78556 KB |
Output is correct |
16 |
Correct |
39 ms |
78536 KB |
Output is correct |
17 |
Correct |
33 ms |
78516 KB |
Output is correct |
18 |
Correct |
31 ms |
78524 KB |
Output is correct |
19 |
Correct |
34 ms |
78480 KB |
Output is correct |
20 |
Correct |
32 ms |
78592 KB |
Output is correct |
21 |
Incorrect |
33 ms |
78556 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |