#include<bits/stdc++.h>
using namespace std;
const int MAXN = 500010;
const long long int MOD = 1e9 + 7;
int n;
long long int x[MAXN], y[MAXN];
long long int seg[4 * MAXN], lz[4 * MAXN];
void refresh(int pos, int bg, int ed)
{
if(lz[pos] == 1) return;
long long int Lz = lz[pos]; lz[pos] = 1;
seg[pos] = (seg[pos] * Lz) % MOD;
if(bg == ed) return;
int mid = (bg + ed) >> 1, l = 2 * pos, r = l + 1;
lz[l] = (lz[l] * Lz) % MOD;
lz[r] = (lz[r] * Lz) % MOD;
}
void upd(int pos, int bg, int ed, int p, int q, long long int val)
{
refresh(pos, bg, ed);
if(q < p || q < bg || ed < p) return;
if(p <= bg && ed <= q)
{
lz[pos] = (lz[pos] * val) % MOD;
refresh(pos, bg, ed);
return;
}
int mid = (bg + ed) >> 1, l = 2 * pos, r = l + 1;
upd(l, bg, mid, p, q, val);
upd(r, mid + 1, ed, p, q, val);
seg[pos] = max(seg[l], seg[r]);
}
long long int fe(long long int a, long long int p)
{
if(p == 0) return 1;
if(p == 1) return a;
long long int b = fe(a, p / 2);
b = (b * b) % MOD;
if(p & 1) b = (b * a) % MOD;
return b;
}
int updateX(int pos, int val)
{
pos++;
upd(1, 1, n, pos, n, fe(x[pos], MOD - 2));
x[pos] = val;
upd(1, 1, n, pos, n, x[pos]);
refresh(1, 1, n);
return (int) seg[1];
}
int updateY(int pos, int val)
{
pos++;
upd(1, 1, n, pos, pos, fe(y[pos], MOD - 2));
y[pos] = val;
upd(1, 1, n, pos, pos, y[pos]);
refresh(1, 1, n);
return (int) seg[1];
}
int init(int N, int X[], int Y[])
{
n = N;
for(int i = n; i > 0; i--) x[i] = X[i - 1];
for(int i = n; i > 0; i--) y[i] = Y[i - 1];
for(int i = 1; i < 4 * MAXN; i++) lz[i] = 1, seg[i] = 1;
for(int i = 1; i <= n; i++)
{
upd(1, 1, n, i, n, x[i]);
upd(1, 1, n, i, i, y[i]);
}
refresh(1, 1, n);
return (int) seg[1];
}
/*
int N;
long long int X[MAXN], Y[MAXN];
int main ()
{
scanf("%d", &N);
for(int i = 0; i < N; i++) scanf("%lld", &X[i]);
for(int i = 0; i < N; i++) scanf("%lld", &Y[i]);
printf("%d\n", init(N, X, Y));
printf("%d\n", updateY(1, 2));
}
3
2 1 3
3 4 1
*/
Compilation message
horses.cpp: In function 'void refresh(int, int, int)':
horses.cpp:19:6: warning: unused variable 'mid' [-Wunused-variable]
19 | int mid = (bg + ed) >> 1, l = 2 * pos, r = l + 1;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31564 KB |
Output is correct |
2 |
Correct |
15 ms |
31516 KB |
Output is correct |
3 |
Correct |
17 ms |
31608 KB |
Output is correct |
4 |
Correct |
16 ms |
31568 KB |
Output is correct |
5 |
Correct |
19 ms |
31556 KB |
Output is correct |
6 |
Correct |
16 ms |
31564 KB |
Output is correct |
7 |
Correct |
18 ms |
31564 KB |
Output is correct |
8 |
Correct |
16 ms |
31564 KB |
Output is correct |
9 |
Correct |
16 ms |
31564 KB |
Output is correct |
10 |
Correct |
16 ms |
31564 KB |
Output is correct |
11 |
Correct |
16 ms |
31584 KB |
Output is correct |
12 |
Correct |
15 ms |
31564 KB |
Output is correct |
13 |
Correct |
15 ms |
31600 KB |
Output is correct |
14 |
Correct |
16 ms |
31564 KB |
Output is correct |
15 |
Correct |
16 ms |
31564 KB |
Output is correct |
16 |
Correct |
16 ms |
31564 KB |
Output is correct |
17 |
Correct |
16 ms |
31564 KB |
Output is correct |
18 |
Correct |
17 ms |
31596 KB |
Output is correct |
19 |
Correct |
15 ms |
31564 KB |
Output is correct |
20 |
Correct |
16 ms |
31568 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31560 KB |
Output is correct |
2 |
Correct |
15 ms |
31584 KB |
Output is correct |
3 |
Correct |
16 ms |
31520 KB |
Output is correct |
4 |
Correct |
16 ms |
31564 KB |
Output is correct |
5 |
Correct |
17 ms |
31556 KB |
Output is correct |
6 |
Correct |
18 ms |
31576 KB |
Output is correct |
7 |
Correct |
16 ms |
31508 KB |
Output is correct |
8 |
Correct |
17 ms |
31516 KB |
Output is correct |
9 |
Correct |
16 ms |
31548 KB |
Output is correct |
10 |
Correct |
16 ms |
31620 KB |
Output is correct |
11 |
Correct |
16 ms |
31564 KB |
Output is correct |
12 |
Correct |
16 ms |
31520 KB |
Output is correct |
13 |
Correct |
16 ms |
31564 KB |
Output is correct |
14 |
Correct |
17 ms |
31552 KB |
Output is correct |
15 |
Correct |
16 ms |
31592 KB |
Output is correct |
16 |
Correct |
16 ms |
31616 KB |
Output is correct |
17 |
Correct |
16 ms |
31628 KB |
Output is correct |
18 |
Correct |
16 ms |
31568 KB |
Output is correct |
19 |
Correct |
15 ms |
31564 KB |
Output is correct |
20 |
Correct |
16 ms |
31564 KB |
Output is correct |
21 |
Incorrect |
15 ms |
31564 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
563 ms |
44324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31600 KB |
Output is correct |
2 |
Correct |
15 ms |
31564 KB |
Output is correct |
3 |
Correct |
17 ms |
31560 KB |
Output is correct |
4 |
Correct |
16 ms |
31508 KB |
Output is correct |
5 |
Correct |
16 ms |
31568 KB |
Output is correct |
6 |
Correct |
16 ms |
31624 KB |
Output is correct |
7 |
Correct |
16 ms |
31572 KB |
Output is correct |
8 |
Correct |
16 ms |
31564 KB |
Output is correct |
9 |
Correct |
16 ms |
31564 KB |
Output is correct |
10 |
Correct |
16 ms |
31524 KB |
Output is correct |
11 |
Correct |
16 ms |
31564 KB |
Output is correct |
12 |
Correct |
16 ms |
31564 KB |
Output is correct |
13 |
Correct |
19 ms |
31564 KB |
Output is correct |
14 |
Correct |
16 ms |
31564 KB |
Output is correct |
15 |
Correct |
16 ms |
31564 KB |
Output is correct |
16 |
Correct |
16 ms |
31564 KB |
Output is correct |
17 |
Correct |
16 ms |
31564 KB |
Output is correct |
18 |
Correct |
16 ms |
31600 KB |
Output is correct |
19 |
Correct |
16 ms |
31564 KB |
Output is correct |
20 |
Correct |
15 ms |
31564 KB |
Output is correct |
21 |
Incorrect |
16 ms |
31564 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
16 ms |
31564 KB |
Output is correct |
2 |
Correct |
16 ms |
31564 KB |
Output is correct |
3 |
Correct |
17 ms |
31536 KB |
Output is correct |
4 |
Correct |
19 ms |
31624 KB |
Output is correct |
5 |
Correct |
16 ms |
31600 KB |
Output is correct |
6 |
Correct |
18 ms |
31564 KB |
Output is correct |
7 |
Correct |
17 ms |
31564 KB |
Output is correct |
8 |
Correct |
16 ms |
31564 KB |
Output is correct |
9 |
Correct |
16 ms |
31552 KB |
Output is correct |
10 |
Correct |
16 ms |
31564 KB |
Output is correct |
11 |
Correct |
16 ms |
31564 KB |
Output is correct |
12 |
Correct |
16 ms |
31564 KB |
Output is correct |
13 |
Correct |
16 ms |
31564 KB |
Output is correct |
14 |
Correct |
16 ms |
31564 KB |
Output is correct |
15 |
Correct |
16 ms |
31564 KB |
Output is correct |
16 |
Correct |
16 ms |
31600 KB |
Output is correct |
17 |
Correct |
16 ms |
31564 KB |
Output is correct |
18 |
Correct |
16 ms |
31592 KB |
Output is correct |
19 |
Correct |
16 ms |
31564 KB |
Output is correct |
20 |
Correct |
18 ms |
31504 KB |
Output is correct |
21 |
Incorrect |
16 ms |
31564 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |