#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
const int md = (int) 1e9 + 7;
const long long inf = 1ll << 30;
inline int mul(int x, int y) {
return (int) ((long long) x * y % md);
}
class node {
public:
int all;
int left;
int right;
int sell;
int prod;
int ans;
};
vector<node> tree;
vector<int> a, b;
int n;
void pull(int x, int z) {
tree[x].all = min((long long) tree[x + 1].all * tree[z].all, inf);
tree[x].prod = mul(tree[x + 1].prod, tree[z].prod);
if (tree[x + 1].sell > (long long) tree[x + 1].right * tree[z].left) {
tree[x].ans = tree[x + 1].ans;
tree[x].sell = tree[x + 1].sell;
tree[x].left = tree[x + 1].left;
tree[x].right = min((long long) tree[x + 1].right * tree[z].all, inf);
} else {
tree[x].ans = mul(tree[z].ans, tree[x + 1].prod);
tree[x].sell = tree[z].sell;
tree[x].left = min((long long) tree[x + 1].all * tree[z].left, inf);
tree[x].right = tree[z].right;
}
}
void build(int x, int l, int r) {
if (l == r) {
tree[x].all = a[l];
tree[x].prod = a[l];
tree[x].ans = mul(a[l], b[l]);
tree[x].sell = b[l];
tree[x].left = min((long long) a[l] * b[l], inf);
tree[x].right = 1;
} else {
int y = (l + r) >> 1, z = x + ((y - l + 1) << 1);
build(x + 1, l, y);
build(z, y + 1, r);
pull(x, z);
}
}
void modify(int x, int l, int r, int p) {
if (l == r) {
tree[x].all = a[l];
tree[x].prod = a[l];
tree[x].ans = mul(a[l], b[l]);
tree[x].sell = b[l];
tree[x].left = min((long long) a[l] * b[l], inf);
tree[x].right = 1;
} else {
int y = (l + r) >> 1, z = x + ((y - l + 1) << 1);
if (p <= y) {
modify(x + 1, l, y, p);
} else {
modify(z, y + 1, r, p);
}
pull(x, z);
}
}
int init(int N, int X[], int Y[]) {
n = N;
for (int i = 0; i < n; ++i) {
a.push_back(X[i]);
b.push_back(Y[i]);
}
tree.resize(n * 2 - 1);
build(0, 0, n - 1);
return tree[0].ans;
}
int updateX(int pos, int val) {
a[pos] = val;
modify(0, 0, n - 1, pos);
return tree[0].ans;
}
int updateY(int pos, int val) {
b[pos] = val;
modify(0, 0, n - 1, pos);
return tree[0].ans;
}
Compilation message
horses.cpp: In function 'void pull(int, int)':
horses.cpp:28:20: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
tree[x].all = min((long long) tree[x + 1].all * tree[z].all, inf);
~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp:34:24: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
tree[x].right = min((long long) tree[x + 1].right * tree[z].all, inf);
~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp:38:23: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
tree[x].left = min((long long) tree[x + 1].all * tree[z].left, inf);
~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'void build(int, int, int)':
horses.cpp:49:23: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
tree[x].left = min((long long) a[l] * b[l], inf);
~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
horses.cpp: In function 'void modify(int, int, int, int)':
horses.cpp:65:23: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
tree[x].left = min((long long) a[l] * b[l], inf);
~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
512 KB |
Output is correct |
2 |
Correct |
2 ms |
256 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
3 ms |
368 KB |
Output is correct |
7 |
Correct |
3 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
256 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
256 KB |
Output is correct |
12 |
Correct |
3 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
3 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
3 ms |
256 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
3 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
3 ms |
384 KB |
Output is correct |
12 |
Correct |
3 ms |
256 KB |
Output is correct |
13 |
Correct |
3 ms |
256 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
3 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
256 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
256 KB |
Output is correct |
20 |
Correct |
2 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
512 KB |
Output is correct |
24 |
Correct |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
512 KB |
Output is correct |
26 |
Correct |
3 ms |
384 KB |
Output is correct |
27 |
Correct |
2 ms |
384 KB |
Output is correct |
28 |
Correct |
3 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
3 ms |
384 KB |
Output is correct |
31 |
Correct |
3 ms |
384 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
113 ms |
36736 KB |
Output is correct |
2 |
Correct |
212 ms |
45484 KB |
Output is correct |
3 |
Correct |
176 ms |
36700 KB |
Output is correct |
4 |
Correct |
192 ms |
40548 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
3 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
384 KB |
Output is correct |
7 |
Correct |
2 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
3 ms |
384 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
256 KB |
Output is correct |
13 |
Correct |
2 ms |
256 KB |
Output is correct |
14 |
Correct |
3 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
256 KB |
Output is correct |
19 |
Correct |
3 ms |
256 KB |
Output is correct |
20 |
Correct |
4 ms |
384 KB |
Output is correct |
21 |
Correct |
2 ms |
384 KB |
Output is correct |
22 |
Correct |
2 ms |
384 KB |
Output is correct |
23 |
Correct |
3 ms |
512 KB |
Output is correct |
24 |
Correct |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
384 KB |
Output is correct |
26 |
Correct |
3 ms |
512 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
3 ms |
384 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
3 ms |
384 KB |
Output is correct |
31 |
Correct |
3 ms |
512 KB |
Output is correct |
32 |
Correct |
3 ms |
384 KB |
Output is correct |
33 |
Correct |
86 ms |
35932 KB |
Output is correct |
34 |
Correct |
71 ms |
35932 KB |
Output is correct |
35 |
Correct |
91 ms |
42812 KB |
Output is correct |
36 |
Correct |
98 ms |
42832 KB |
Output is correct |
37 |
Correct |
61 ms |
34112 KB |
Output is correct |
38 |
Correct |
63 ms |
35056 KB |
Output is correct |
39 |
Correct |
54 ms |
34012 KB |
Output is correct |
40 |
Correct |
86 ms |
37848 KB |
Output is correct |
41 |
Correct |
53 ms |
34012 KB |
Output is correct |
42 |
Correct |
54 ms |
34140 KB |
Output is correct |
43 |
Correct |
74 ms |
38308 KB |
Output is correct |
44 |
Correct |
66 ms |
38236 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
404 KB |
Output is correct |
2 |
Correct |
3 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
2 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
3 ms |
384 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
384 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
2 ms |
384 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
256 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
3 ms |
384 KB |
Output is correct |
18 |
Correct |
2 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
384 KB |
Output is correct |
20 |
Correct |
2 ms |
368 KB |
Output is correct |
21 |
Correct |
3 ms |
256 KB |
Output is correct |
22 |
Correct |
3 ms |
256 KB |
Output is correct |
23 |
Correct |
3 ms |
512 KB |
Output is correct |
24 |
Correct |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
3 ms |
512 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
3 ms |
384 KB |
Output is correct |
29 |
Correct |
3 ms |
384 KB |
Output is correct |
30 |
Correct |
3 ms |
384 KB |
Output is correct |
31 |
Correct |
3 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
33 |
Correct |
98 ms |
36572 KB |
Output is correct |
34 |
Correct |
196 ms |
45508 KB |
Output is correct |
35 |
Correct |
199 ms |
36676 KB |
Output is correct |
36 |
Correct |
204 ms |
40532 KB |
Output is correct |
37 |
Correct |
77 ms |
35928 KB |
Output is correct |
38 |
Correct |
70 ms |
36020 KB |
Output is correct |
39 |
Correct |
90 ms |
42840 KB |
Output is correct |
40 |
Correct |
94 ms |
42740 KB |
Output is correct |
41 |
Correct |
65 ms |
34104 KB |
Output is correct |
42 |
Correct |
62 ms |
35024 KB |
Output is correct |
43 |
Correct |
52 ms |
34108 KB |
Output is correct |
44 |
Correct |
70 ms |
37852 KB |
Output is correct |
45 |
Correct |
55 ms |
34016 KB |
Output is correct |
46 |
Correct |
60 ms |
34112 KB |
Output is correct |
47 |
Correct |
71 ms |
38384 KB |
Output is correct |
48 |
Correct |
70 ms |
38364 KB |
Output is correct |
49 |
Correct |
199 ms |
37848 KB |
Output is correct |
50 |
Correct |
204 ms |
37856 KB |
Output is correct |
51 |
Correct |
131 ms |
44680 KB |
Output is correct |
52 |
Correct |
143 ms |
44120 KB |
Output is correct |
53 |
Correct |
216 ms |
36316 KB |
Output is correct |
54 |
Correct |
111 ms |
36744 KB |
Output is correct |
55 |
Correct |
91 ms |
35036 KB |
Output is correct |
56 |
Correct |
113 ms |
39624 KB |
Output is correct |
57 |
Correct |
93 ms |
35676 KB |
Output is correct |
58 |
Correct |
98 ms |
36188 KB |
Output is correct |
59 |
Correct |
73 ms |
38240 KB |
Output is correct |