#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int inf = 1e18 + 69;
const int N = 5e5 + 69;
int n, a[N], b[N], c[N], p[4 * N], g[4 * N], btr[4 * N];
int mul(int x, int y) {
long long r = 1ll * x * y;
if (r >= mod)
r %= mod;
return r;
}
void modify(int v, int tl, int tr, int pos, int x) {
if (tl == tr)
p[v] = g[v] = x;
else {
int mid = (tl + tr) / 2;
if (pos <= mid)
modify(v * 2, tl, mid, pos, x);
else
modify(v * 2 + 1, mid + 1, tr, pos, x);
if (p[v * 2] == -1 || p[v * 2 + 1] == -1 || p[v * 2] > inf / p[v * 2 + 1])
p[v] = -1;
else {
assert(p[v * 2] * p[v * 2 + 1] < inf);
p[v] = p[v * 2] * p[v * 2 + 1];
}
g[v] = mul(g[v * 2], g[v * 2 + 1]);
}
}
int get(int v, int tl, int tr, int l, int r) {
if (tl > r || tr < l)
return 1;
else if (tl >= l && tr <= r)
return p[v];
else {
int mid = (tl + tr) / 2;
auto l1 = get(v * 2, tl, mid, l, r);
auto r1 = get(v * 2 + 1, mid + 1, tr, l, r);
if (l1 == -1 || r1 == -1 || l1 > inf / r1)
return -1;
assert(l1 * r1 < inf);
return l1 * r1;
}
}
int Get(int v, int tl, int tr, int l, int r) {
if (tl > r || tr < l)
return 1;
else if (tl >= l && tr <= r)
return g[v];
else {
int mid = (tl + tr) / 2;
return mul(Get(v * 2, tl, mid, l, r), Get(v * 2 + 1, mid + 1, tr, l, r));
}
}
int Better(int i, int j) {
if (i > j)
swap(i, j);
int x = get(1, 1, n, i+ 1, j);
if (x < 0 || x > inf / b[j])
return j;
return (b[i] > b[j] * x ? i : j);
}
int Result(int i) {
return mul(Get(1, 1, n, 1, i), b[i]);
}
void Modify(int v, int tl, int tr, int pos, int x) {
if (tl == tr)
btr[v] = x;
else {
int mid = (tl + tr) / 2;
if (pos <= mid)
Modify(v * 2, tl, mid, pos, x);
else
Modify(v * 2 + 1, mid + 1, tr, pos, x);
if (btr[v * 2] == -1)
btr[v] = btr[v * 2 + 1];
else if (btr[v * 2 + 1] == -1)
btr[v] = btr[v * 2];
else
btr[v] = Better(btr[v * 2], btr[v * 2 + 1]);
}
}
int init(int N, int X[], int Y[]) {
n = N;
fill(p, p + 4 * n + 10, 1);
fill(g, g + 4 * n + 10, 1);
fill(btr, btr + 4 * n + 10, -1);
for (int i = 1;i <= n;i++) {
a[i] = X[i - 1], b[i] = Y[i - 1];
modify(1, 1, n, i, a[i]);
}
for (int i = 1;i <= n;i++)
Modify(1, 1, n, i, i);
return Result(btr[1]);
}
int updateX(int pos, int val) {
pos++;
a[pos] = val;
modify(1, 1, n, pos, a[pos]);
Modify(1, 1, n, pos, pos);
return Result(btr[1]);
}
int updateY(int pos, int val) {
pos++;
b[pos] = val;
Modify(1, 1, n, pos, pos);
return Result(btr[1]);
}
/*
3
2 1 3
3 4 1
1
2 1 2
*/
Compilation message
horses.cpp:5:22: warning: overflow in conversion from 'double' to 'int' changes value from '1.0000000000000001e+18' to '2147483647' [-Woverflow]
5 | const int inf = 1e18 + 69;
| ~~~~~^~~~
horses.cpp: In function 'int mul(int, int)':
horses.cpp:12:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
12 | return r;
| ^
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:88:14: warning: declaration of 'N' shadows a global declaration [-Wshadow]
88 | int init(int N, int X[], int Y[]) {
| ~~~~^
horses.cpp:6:11: note: shadowed declaration is here
6 | const int N = 5e5 + 69;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8544 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
8568 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
8640 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8540 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8540 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8636 KB |
Output is correct |
9 |
Correct |
2 ms |
8536 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8536 KB |
Output is correct |
14 |
Correct |
2 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
8544 KB |
Output is correct |
19 |
Correct |
2 ms |
8948 KB |
Output is correct |
20 |
Correct |
1 ms |
8544 KB |
Output is correct |
21 |
Correct |
1 ms |
8544 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
23 |
Correct |
4 ms |
8540 KB |
Output is correct |
24 |
Correct |
4 ms |
8544 KB |
Output is correct |
25 |
Correct |
3 ms |
8540 KB |
Output is correct |
26 |
Correct |
2 ms |
8540 KB |
Output is correct |
27 |
Correct |
4 ms |
8540 KB |
Output is correct |
28 |
Correct |
3 ms |
8656 KB |
Output is correct |
29 |
Correct |
3 ms |
8676 KB |
Output is correct |
30 |
Correct |
3 ms |
8540 KB |
Output is correct |
31 |
Correct |
3 ms |
8540 KB |
Output is correct |
32 |
Correct |
3 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1276 ms |
38488 KB |
Output is correct |
2 |
Correct |
1069 ms |
47256 KB |
Output is correct |
3 |
Correct |
1342 ms |
38652 KB |
Output is correct |
4 |
Correct |
1468 ms |
42188 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
8644 KB |
Output is correct |
2 |
Correct |
1 ms |
8540 KB |
Output is correct |
3 |
Correct |
1 ms |
8792 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
1 ms |
8540 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
1 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8640 KB |
Output is correct |
10 |
Correct |
1 ms |
8536 KB |
Output is correct |
11 |
Correct |
1 ms |
8540 KB |
Output is correct |
12 |
Correct |
2 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8640 KB |
Output is correct |
14 |
Correct |
1 ms |
8540 KB |
Output is correct |
15 |
Correct |
1 ms |
8540 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
1 ms |
8636 KB |
Output is correct |
20 |
Correct |
1 ms |
8540 KB |
Output is correct |
21 |
Correct |
1 ms |
8540 KB |
Output is correct |
22 |
Correct |
1 ms |
8792 KB |
Output is correct |
23 |
Correct |
4 ms |
8536 KB |
Output is correct |
24 |
Correct |
4 ms |
8540 KB |
Output is correct |
25 |
Correct |
3 ms |
8704 KB |
Output is correct |
26 |
Correct |
3 ms |
8540 KB |
Output is correct |
27 |
Correct |
3 ms |
8540 KB |
Output is correct |
28 |
Correct |
3 ms |
8540 KB |
Output is correct |
29 |
Correct |
3 ms |
8540 KB |
Output is correct |
30 |
Correct |
3 ms |
8652 KB |
Output is correct |
31 |
Correct |
3 ms |
8540 KB |
Output is correct |
32 |
Correct |
3 ms |
8540 KB |
Output is correct |
33 |
Execution timed out |
1566 ms |
37440 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
8536 KB |
Output is correct |
2 |
Correct |
1 ms |
8536 KB |
Output is correct |
3 |
Correct |
2 ms |
8536 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Correct |
1 ms |
8540 KB |
Output is correct |
6 |
Correct |
2 ms |
8536 KB |
Output is correct |
7 |
Correct |
1 ms |
8540 KB |
Output is correct |
8 |
Correct |
2 ms |
8540 KB |
Output is correct |
9 |
Correct |
1 ms |
8540 KB |
Output is correct |
10 |
Correct |
1 ms |
8540 KB |
Output is correct |
11 |
Correct |
2 ms |
8540 KB |
Output is correct |
12 |
Correct |
1 ms |
8540 KB |
Output is correct |
13 |
Correct |
1 ms |
8540 KB |
Output is correct |
14 |
Correct |
1 ms |
8792 KB |
Output is correct |
15 |
Correct |
1 ms |
8792 KB |
Output is correct |
16 |
Correct |
1 ms |
8540 KB |
Output is correct |
17 |
Correct |
1 ms |
8540 KB |
Output is correct |
18 |
Correct |
1 ms |
8540 KB |
Output is correct |
19 |
Correct |
1 ms |
8540 KB |
Output is correct |
20 |
Correct |
1 ms |
8648 KB |
Output is correct |
21 |
Correct |
1 ms |
8540 KB |
Output is correct |
22 |
Correct |
1 ms |
8540 KB |
Output is correct |
23 |
Correct |
4 ms |
8648 KB |
Output is correct |
24 |
Correct |
4 ms |
8540 KB |
Output is correct |
25 |
Correct |
3 ms |
8540 KB |
Output is correct |
26 |
Correct |
3 ms |
8540 KB |
Output is correct |
27 |
Correct |
4 ms |
8540 KB |
Output is correct |
28 |
Correct |
3 ms |
8540 KB |
Output is correct |
29 |
Correct |
3 ms |
8540 KB |
Output is correct |
30 |
Correct |
3 ms |
8700 KB |
Output is correct |
31 |
Correct |
3 ms |
8536 KB |
Output is correct |
32 |
Correct |
4 ms |
8540 KB |
Output is correct |
33 |
Correct |
1281 ms |
38488 KB |
Output is correct |
34 |
Correct |
1071 ms |
47376 KB |
Output is correct |
35 |
Correct |
1336 ms |
38420 KB |
Output is correct |
36 |
Correct |
1463 ms |
42324 KB |
Output is correct |
37 |
Execution timed out |
1551 ms |
37460 KB |
Time limit exceeded |
38 |
Halted |
0 ms |
0 KB |
- |