#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
#define lc (id << 1)
#define rc (lc | 1)
typedef long long ll;
struct Node {
int ind;
ll v1 = 1, v2 = 1;
};
int const MOD = 1e9 + 7;
int n;
vector<int> A, B;
vector<Node> mxseg;
vector<ll> valseg;
inline ll mul(ll x, ll y) {
return x * y > MOD ? 0 : x * y;
}
Node mxmerge(Node const& l, Node const& r) {
Node res;
ll val = mul(l.v2, mul(r.v1, B[r.ind]));
if (val == 0 || val >= B[l.ind]) {
res.ind = r.ind;
res.v1 = mul(l.v1, mul(l.v2, r.v1));
res.v2 = r.v2;
}
else {
res.ind = l.ind;
res.v1 = l.v1;
res.v2 = mul(l.v2, mul(r.v1, r.v2));
}
return res;
}
void mxbuild(int id, int l, int r, int ind) {
if (ind != -1 && (ind < l || r <= ind))
return;
if (r - l == 1) {
mxseg[id].ind = l;
mxseg[id].v1 = A[l];
return;
}
int mid = (l + r) >> 1;
mxbuild(lc, l, mid, ind);
mxbuild(rc, mid, r, ind);
mxseg[id] = mxmerge(mxseg[lc], mxseg[rc]);
}
void valbuild(int id, int l, int r, int ind) {
if (ind != -1 && (ind < l || r <= ind))
return;
if (r - l == 1) {
valseg[id] = A[l];
return;
}
int mid = (l + r) >> 1;
valbuild(lc, l, mid, ind);
valbuild(rc, mid, r, ind);
valseg[id] = valseg[lc] * valseg[rc] % MOD;
}
ll valget(int id, int l, int r, int qr) {
if (r <= qr)
return valseg[id];
if (qr <= l)
return 1;
int mid = (l + r) >> 1;
return valget(lc, l, mid, qr) * valget(rc, mid, r, qr) % MOD;
}
int query() {
int ind = mxseg[1].ind;
return valget(1, 0, n, ind + 1) * B[ind] % MOD;
}
int init(int N, int X[], int Y[]) {
n = N;
A.assign(X, X + n);
B.assign(Y, Y + n);
mxseg.resize((n + 1) << 2);
valseg.resize((n + 1) << 2);
mxbuild(1, 0, n, -1);
valbuild(1, 0, n, -1);
return query();
}
int updateX(int pos, int val) {
A[pos] = val;
mxbuild(1, 0, n, pos);
valbuild(1, 0, n, pos);
return query();
}
int updateY(int pos, int val) {
B[pos] = val;
mxbuild(1, 0, n, pos);
valbuild(1, 0, n, pos);
return query();
}
Compilation message
horses.cpp: In function 'int query()':
horses.cpp:80:43: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
80 | return valget(1, 0, n, ind + 1) * B[ind] % MOD;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
512 KB |
Output is correct |
23 |
Correct |
2 ms |
492 KB |
Output is correct |
24 |
Correct |
3 ms |
492 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
2 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
620 KB |
Output is correct |
29 |
Correct |
2 ms |
492 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
31 |
Correct |
2 ms |
492 KB |
Output is correct |
32 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
193 ms |
71916 KB |
Output is correct |
2 |
Correct |
290 ms |
71788 KB |
Output is correct |
3 |
Correct |
256 ms |
71788 KB |
Output is correct |
4 |
Correct |
279 ms |
71788 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
2 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
492 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
2 ms |
492 KB |
Output is correct |
26 |
Correct |
2 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
2 ms |
492 KB |
Output is correct |
29 |
Correct |
2 ms |
492 KB |
Output is correct |
30 |
Correct |
2 ms |
620 KB |
Output is correct |
31 |
Correct |
2 ms |
492 KB |
Output is correct |
32 |
Correct |
2 ms |
512 KB |
Output is correct |
33 |
Correct |
102 ms |
70892 KB |
Output is correct |
34 |
Correct |
101 ms |
70892 KB |
Output is correct |
35 |
Correct |
118 ms |
70892 KB |
Output is correct |
36 |
Correct |
112 ms |
70892 KB |
Output is correct |
37 |
Correct |
92 ms |
70892 KB |
Output is correct |
38 |
Correct |
88 ms |
70892 KB |
Output is correct |
39 |
Correct |
80 ms |
70764 KB |
Output is correct |
40 |
Correct |
96 ms |
70892 KB |
Output is correct |
41 |
Correct |
86 ms |
70892 KB |
Output is correct |
42 |
Correct |
82 ms |
70892 KB |
Output is correct |
43 |
Correct |
88 ms |
70764 KB |
Output is correct |
44 |
Correct |
90 ms |
70764 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
2 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
492 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
2 ms |
492 KB |
Output is correct |
26 |
Correct |
2 ms |
492 KB |
Output is correct |
27 |
Correct |
2 ms |
492 KB |
Output is correct |
28 |
Correct |
3 ms |
492 KB |
Output is correct |
29 |
Correct |
2 ms |
492 KB |
Output is correct |
30 |
Correct |
2 ms |
508 KB |
Output is correct |
31 |
Correct |
2 ms |
492 KB |
Output is correct |
32 |
Correct |
2 ms |
492 KB |
Output is correct |
33 |
Correct |
192 ms |
71788 KB |
Output is correct |
34 |
Correct |
293 ms |
71956 KB |
Output is correct |
35 |
Correct |
257 ms |
71788 KB |
Output is correct |
36 |
Correct |
279 ms |
71916 KB |
Output is correct |
37 |
Correct |
108 ms |
71276 KB |
Output is correct |
38 |
Correct |
112 ms |
71276 KB |
Output is correct |
39 |
Correct |
120 ms |
71148 KB |
Output is correct |
40 |
Correct |
113 ms |
71020 KB |
Output is correct |
41 |
Correct |
92 ms |
71276 KB |
Output is correct |
42 |
Correct |
90 ms |
71288 KB |
Output is correct |
43 |
Correct |
82 ms |
71148 KB |
Output is correct |
44 |
Correct |
98 ms |
71148 KB |
Output is correct |
45 |
Correct |
83 ms |
71276 KB |
Output is correct |
46 |
Correct |
85 ms |
71276 KB |
Output is correct |
47 |
Correct |
90 ms |
71020 KB |
Output is correct |
48 |
Correct |
91 ms |
71020 KB |
Output is correct |
49 |
Correct |
287 ms |
72044 KB |
Output is correct |
50 |
Correct |
280 ms |
72044 KB |
Output is correct |
51 |
Correct |
272 ms |
72172 KB |
Output is correct |
52 |
Correct |
197 ms |
72348 KB |
Output is correct |
53 |
Correct |
267 ms |
72616 KB |
Output is correct |
54 |
Correct |
200 ms |
72428 KB |
Output is correct |
55 |
Correct |
165 ms |
71916 KB |
Output is correct |
56 |
Correct |
188 ms |
72300 KB |
Output is correct |
57 |
Correct |
174 ms |
72684 KB |
Output is correct |
58 |
Correct |
192 ms |
72556 KB |
Output is correct |
59 |
Correct |
91 ms |
71276 KB |
Output is correct |