#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const long long lim = 1e9 + 1;
const long long mod = 1e9 + 7;
const int mxN = 5e5 + 10;
int n;
long long aX[mxN], aY[mxN];
long long mul(long long x, long long y) {
return min(x * y, lim);
}
struct Node {
int id;
long long p, s;
long long np, ns;
friend Node operator + (Node a, Node b) {
Node c;
long long suffix = mul(a.s, b.p);
if(aY[a.id] > mul(suffix, aY[b.id])) {
c.id = a.id;
c.p = a.p;
c.s = mul(a.s, mul(b.p, b.s));
c.np = a.np;
c.ns = a.ns * b.np % mod * b.ns % mod;
} else {
c.id = b.id;
c.p = mul(mul(a.p, a.s), b.p);
c.s = b.s;
c.np = a.np * a.ns % mod * b.np % mod;
c.ns = b.ns;
}
return c;
}
} ST[mxN << 2];
void build(int id, int l, int r) {
if(l == r) {
ST[id] = {l, aX[l], 1, aX[l], 1};
return ;
}
int mid = (l + r) / 2;
build(id * 2, l, mid);
build(id * 2 + 1, mid + 1, r);
ST[id] = ST[id * 2] + ST[id * 2 + 1];
}
void update(int id, int l, int r, int x) {
if(r < x || x < l) return ;
if(l == r) {
ST[id] = {l, aX[l], 1, aX[l], 1};
return ;
}
int mid = (l + r) / 2;
update(id * 2, l, mid, x);
update(id * 2 + 1, mid + 1, r, x);
ST[id] = ST[id * 2] + ST[id * 2 + 1];
}
int init(int N, int X[], int Y[]) {
n = N;
for(int i = 0; i < N; i ++) aX[i] = X[i];
for(int i = 0; i < N; i ++) aY[i] = Y[i];
build(1, 0, N - 1);
return ST[1].np * aY[ST[1].id] % mod;
}
int updateX(int pos, int val) {
aX[pos] = val;
update(1, 0, n - 1, pos);
return ST[1].np * aY[ST[1].id] % mod;
}
int updateY(int pos, int val) {
aY[pos] = val;
update(1, 0, n - 1, pos);
return ST[1].np * aY[ST[1].id] % mod;
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:76:36: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
76 | return ST[1].np * aY[ST[1].id] % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:82:36: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
82 | return ST[1].np * aY[ST[1].id] % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:88:36: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
88 | return ST[1].np * aY[ST[1].id] % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
4540 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4544 KB |
Output is correct |
13 |
Correct |
1 ms |
4536 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4448 KB |
Output is correct |
19 |
Correct |
1 ms |
4448 KB |
Output is correct |
20 |
Correct |
1 ms |
4448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4448 KB |
Output is correct |
2 |
Correct |
1 ms |
4448 KB |
Output is correct |
3 |
Correct |
1 ms |
4448 KB |
Output is correct |
4 |
Correct |
1 ms |
4448 KB |
Output is correct |
5 |
Correct |
1 ms |
4448 KB |
Output is correct |
6 |
Correct |
1 ms |
4448 KB |
Output is correct |
7 |
Correct |
1 ms |
4448 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4448 KB |
Output is correct |
10 |
Correct |
2 ms |
4448 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4456 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4456 KB |
Output is correct |
16 |
Correct |
1 ms |
4448 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
2 ms |
4452 KB |
Output is correct |
19 |
Correct |
1 ms |
4452 KB |
Output is correct |
20 |
Correct |
1 ms |
4448 KB |
Output is correct |
21 |
Correct |
1 ms |
4548 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4452 KB |
Output is correct |
24 |
Correct |
1 ms |
4452 KB |
Output is correct |
25 |
Correct |
1 ms |
4456 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4440 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
2 ms |
4440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
58 ms |
57568 KB |
Output is correct |
2 |
Correct |
139 ms |
66892 KB |
Output is correct |
3 |
Correct |
100 ms |
58260 KB |
Output is correct |
4 |
Correct |
185 ms |
61956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4440 KB |
Output is correct |
6 |
Correct |
1 ms |
4544 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4536 KB |
Output is correct |
12 |
Correct |
1 ms |
4540 KB |
Output is correct |
13 |
Correct |
1 ms |
4536 KB |
Output is correct |
14 |
Correct |
1 ms |
4540 KB |
Output is correct |
15 |
Correct |
1 ms |
4444 KB |
Output is correct |
16 |
Correct |
1 ms |
4444 KB |
Output is correct |
17 |
Correct |
1 ms |
4444 KB |
Output is correct |
18 |
Correct |
1 ms |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 KB |
Output is correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4440 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
1 ms |
4444 KB |
Output is correct |
28 |
Correct |
2 ms |
4564 KB |
Output is correct |
29 |
Correct |
1 ms |
4444 KB |
Output is correct |
30 |
Correct |
1 ms |
4444 KB |
Output is correct |
31 |
Correct |
1 ms |
4444 KB |
Output is correct |
32 |
Correct |
2 ms |
4444 KB |
Output is correct |
33 |
Correct |
43 ms |
57424 KB |
Output is correct |
34 |
Correct |
46 ms |
57384 KB |
Output is correct |
35 |
Correct |
57 ms |
64536 KB |
Output is correct |
36 |
Correct |
56 ms |
64312 KB |
Output is correct |
37 |
Correct |
33 ms |
55568 KB |
Output is correct |
38 |
Correct |
31 ms |
56500 KB |
Output is correct |
39 |
Correct |
26 ms |
55388 KB |
Output is correct |
40 |
Correct |
39 ms |
59424 KB |
Output is correct |
41 |
Correct |
36 ms |
55564 KB |
Output is correct |
42 |
Correct |
28 ms |
55636 KB |
Output is correct |
43 |
Correct |
37 ms |
59704 KB |
Output is correct |
44 |
Correct |
37 ms |
59744 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
1 ms |
4444 KB |
Output is correct |
10 |
Correct |
1 ms |
4536 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4448 KB |
Output is correct |
13 |
Correct |
1 ms |
4456 KB |
Output is correct |
14 |
Correct |
1 ms |
4452 KB |
Output is correct |
15 |
Correct |
1 ms |
4452 KB |
Output is correct |
16 |
Correct |
1 ms |
4452 KB |
Output is correct |
17 |
Correct |
1 ms |
4452 KB |
Output is correct |
18 |
Correct |
1 ms |
4456 KB |
Output is correct |
19 |
Correct |
1 ms |
4456 KB |
Output is correct |
20 |
Correct |
1 ms |
4440 KB |
Output is correct |
21 |
Correct |
1 ms |
4440 KB |
Output is correct |
22 |
Correct |
1 ms |
4444 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Correct |
2 ms |
4440 KB |
Output is correct |
28 |
Correct |
1 ms |
4444 KB |
Output is correct |
29 |
Correct |
1 ms |
4440 KB |
Output is correct |
30 |
Correct |
1 ms |
4440 KB |
Output is correct |
31 |
Correct |
2 ms |
4444 KB |
Output is correct |
32 |
Correct |
1 ms |
4444 KB |
Output is correct |
33 |
Correct |
72 ms |
58252 KB |
Output is correct |
34 |
Correct |
152 ms |
67440 KB |
Output is correct |
35 |
Correct |
103 ms |
58152 KB |
Output is correct |
36 |
Correct |
154 ms |
62140 KB |
Output is correct |
37 |
Correct |
41 ms |
57432 KB |
Output is correct |
38 |
Correct |
42 ms |
57684 KB |
Output is correct |
39 |
Correct |
77 ms |
64244 KB |
Output is correct |
40 |
Correct |
59 ms |
64580 KB |
Output is correct |
41 |
Correct |
31 ms |
55476 KB |
Output is correct |
42 |
Correct |
36 ms |
56472 KB |
Output is correct |
43 |
Correct |
30 ms |
55376 KB |
Output is correct |
44 |
Correct |
40 ms |
59308 KB |
Output is correct |
45 |
Correct |
28 ms |
55572 KB |
Output is correct |
46 |
Correct |
25 ms |
55700 KB |
Output is correct |
47 |
Correct |
37 ms |
59824 KB |
Output is correct |
48 |
Correct |
39 ms |
59880 KB |
Output is correct |
49 |
Correct |
122 ms |
59392 KB |
Output is correct |
50 |
Correct |
114 ms |
59448 KB |
Output is correct |
51 |
Correct |
88 ms |
66212 KB |
Output is correct |
52 |
Correct |
93 ms |
66048 KB |
Output is correct |
53 |
Correct |
118 ms |
57876 KB |
Output is correct |
54 |
Correct |
105 ms |
58248 KB |
Output is correct |
55 |
Correct |
58 ms |
56660 KB |
Output is correct |
56 |
Correct |
91 ms |
61320 KB |
Output is correct |
57 |
Correct |
59 ms |
57168 KB |
Output is correct |
58 |
Correct |
60 ms |
57632 KB |
Output is correct |
59 |
Correct |
37 ms |
59728 KB |
Output is correct |