#include<bits/stdc++.h>
#include "horses.h"
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
struct node{
ll v, x, y; double dx, dy, dv;
}t[4 * 500005];
ll n;
node merge(node a, node b) {
node res;
b.dx += a.dx;
b.dv += a.dx;
if ( a.dv > b.dv) res.v = a.v, res.dv = a.dv;
else res.v = (a.x * b.v)% mod, res.dv = b.dv;
res.x = a.x * b.x % mod;
res.dx = b.dx;
return res;
}
node upd(ll p, ll lo, ll hi, ll ind, ll x, ll y) {
if (lo > ind || ind > hi) return t[p];
if (lo == hi) {
node& nd = t[p];
if ( x ) nd.dx = log(x), nd.x =x;
if ( y ) nd.dy = log(y), nd.y =y;
nd.v = (nd.x * nd.y) % mod;
nd.dv = nd.dx + nd.dy;
return nd;
}
int mid = (lo +hi)/2;
return t[p] = merge(upd(2 * p, lo, mid, ind, x, y), upd(2 * p + 1, mid + 1, hi, ind, x, y));
}
int init(int N, int X[], int Y[]) {
n = N;
for (int i = 0; i < N; i++) upd(1, 0, n - 1, i, X[i], Y[i]);
return t[1].v;
}
int updateX(int pos, int val) {
upd(1, 0, n - 1, pos, val, 0);
return t[1].v;
}
int updateY(int pos, int val) {
upd(1, 0, n - 1, pos, 0, val);
return t[1].v;
}
Compilation message
horses.cpp: In function 'node upd(ll, ll, ll, ll, ll, ll)':
horses.cpp:33:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
33 | int mid = (lo +hi)/2;
| ~~~~~~~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:40:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
40 | return t[1].v;
| ~~~~~^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:45:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
45 | return t[1].v;
| ~~~~~^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:50:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
50 | return t[1].v;
| ~~~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
1 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
344 KB |
Output is correct |
27 |
Correct |
2 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
2 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
368 ms |
54380 KB |
Output is correct |
2 |
Correct |
400 ms |
67152 KB |
Output is correct |
3 |
Correct |
387 ms |
58196 KB |
Output is correct |
4 |
Correct |
397 ms |
62292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
1 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
2 ms |
456 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
604 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
300 ms |
57608 KB |
Output is correct |
34 |
Correct |
289 ms |
57520 KB |
Output is correct |
35 |
Correct |
310 ms |
64492 KB |
Output is correct |
36 |
Correct |
307 ms |
64388 KB |
Output is correct |
37 |
Correct |
291 ms |
55732 KB |
Output is correct |
38 |
Correct |
289 ms |
56480 KB |
Output is correct |
39 |
Correct |
286 ms |
55620 KB |
Output is correct |
40 |
Correct |
307 ms |
59680 KB |
Output is correct |
41 |
Correct |
288 ms |
55680 KB |
Output is correct |
42 |
Correct |
285 ms |
55716 KB |
Output is correct |
43 |
Correct |
303 ms |
60116 KB |
Output is correct |
44 |
Correct |
302 ms |
59984 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
360 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
2 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
1 ms |
456 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
448 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
363 ms |
58344 KB |
Output is correct |
34 |
Correct |
405 ms |
67052 KB |
Output is correct |
35 |
Correct |
386 ms |
58316 KB |
Output is correct |
36 |
Correct |
387 ms |
62176 KB |
Output is correct |
37 |
Correct |
295 ms |
57608 KB |
Output is correct |
38 |
Correct |
299 ms |
57428 KB |
Output is correct |
39 |
Correct |
311 ms |
64508 KB |
Output is correct |
40 |
Correct |
310 ms |
64336 KB |
Output is correct |
41 |
Correct |
296 ms |
55632 KB |
Output is correct |
42 |
Correct |
286 ms |
56624 KB |
Output is correct |
43 |
Correct |
290 ms |
55508 KB |
Output is correct |
44 |
Correct |
320 ms |
59472 KB |
Output is correct |
45 |
Correct |
294 ms |
55652 KB |
Output is correct |
46 |
Correct |
284 ms |
55636 KB |
Output is correct |
47 |
Correct |
300 ms |
59840 KB |
Output is correct |
48 |
Correct |
301 ms |
59988 KB |
Output is correct |
49 |
Correct |
373 ms |
59404 KB |
Output is correct |
50 |
Correct |
374 ms |
59500 KB |
Output is correct |
51 |
Correct |
363 ms |
66488 KB |
Output is correct |
52 |
Correct |
368 ms |
65892 KB |
Output is correct |
53 |
Correct |
412 ms |
57952 KB |
Output is correct |
54 |
Correct |
340 ms |
58276 KB |
Output is correct |
55 |
Correct |
354 ms |
56752 KB |
Output is correct |
56 |
Correct |
376 ms |
61264 KB |
Output is correct |
57 |
Correct |
349 ms |
57172 KB |
Output is correct |
58 |
Correct |
347 ms |
57684 KB |
Output is correct |
59 |
Correct |
300 ms |
59988 KB |
Output is correct |