#include<bits/stdc++.h>
#include "horses.h"
using namespace std;
using ll = long long;
const ll MAX_N = 4e6 + 2;
const ll mod = 1e9 + 7;
struct node{
ll v, x, y; double dx, dy, dv;
}t[4 * 500005];
int 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 != -1) nd.dx = log(x), nd.x =x;
if ( y != -1) 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, -1);
return t[1].v;
}
int updateY(int pos, int val) {
upd(1, 0, n - 1, pos, -1, val);
return t[1].x;
}
Compilation message
horses.cpp: In function 'node upd(ll, ll, ll, ll, ll, ll)':
horses.cpp:34:20: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
34 | int mid = (lo +hi)/2;
| ~~~~~~~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:41:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
41 | return t[1].v;
| ~~~~~^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:46:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
46 | return t[1].v;
| ~~~~~^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:51:14: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
51 | return t[1].x;
| ~~~~~^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 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 |
344 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 |
344 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 |
440 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
0 ms |
440 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
440 KB |
Output is correct |
20 |
Correct |
0 ms |
348 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 |
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 |
388 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
444 KB |
Output is correct |
10 |
Correct |
1 ms |
344 KB |
Output is correct |
11 |
Correct |
1 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 |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
344 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 |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
348 ms |
58324 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
360 KB |
Output is correct |
6 |
Correct |
1 ms |
356 KB |
Output is correct |
7 |
Correct |
0 ms |
356 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
356 KB |
Output is correct |
10 |
Correct |
0 ms |
360 KB |
Output is correct |
11 |
Correct |
0 ms |
356 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 |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
600 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
0 ms |
344 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
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 |
1 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 |
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 |
1 ms |
604 KB |
Output is correct |
18 |
Correct |
0 ms |
416 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
1 ms |
348 KB |
Output is correct |
21 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
22 |
Halted |
0 ms |
0 KB |
- |