#include "horses.h"
#include <iostream>
#define int long long
using namespace std;
const long long mod = 1e9+7;
long long n, a[500010], b[500010], node[2000010][3];
bool done;
/*
0: x product
1: max x
2: max y
*/
void build(int id, int x, int y) {
if (x == y) {
node[id][0] = a[x]%mod;
node[id][1] = a[x];
node[id][2] = b[x];
return;
}
int mid = (x+y)/2;
build(id*2,x,mid);
build(id*2+1,mid+1,y);
node[id][0] = (node[id*2][0]*node[id*2+1][0])%mod;
node[id][1] = max(node[id*2][1],node[id*2+1][1]);
node[id][2] = max(node[id*2][2],node[id*2+1][2]);
}
void update(int id, int jd, int x, int y, int pos, int val) {
if (x == y) {
node[id][jd] = val;
return;
}
int mid = (x+y)/2;
if (pos <= mid) update(id*2,jd,x,mid,pos,val);
else update(id*2+1,jd,mid+1,y,pos,val);
if (jd == 0) node[id][0] = (node[id*2][0]*node[id*2+1][0])%mod;
else if (jd == 1) node[id][1] = max(node[id*2][1],node[id*2+1][1]);
else node[id][2] = max(node[id*2][2],node[id*2+1][2]);
}
int nxt(int id, int x, int y, int r) {
if (x > r) return 0;
if (node[id][1] == 1) return 0;
if (x == y) {
done = 1;
return x;
}
int mid = (x+y)/2, tmp = nxt(id*2+1,mid+1,y,r);
if (!done) return nxt(id*2,x,mid,r);
else return tmp;
}
long long find_max(int id, int x, int y, int l, int r) {
if ((l <= x) && (y <= r)) return node[id][2];
if ((y < l) || (r < x)) return 0;
int mid = (x+y)/2;
return max(find_max(id*2,x,mid,l,r),find_max(id*2+1,mid+1,y,l,r));
}
long long find_pro(int id, int x, int y, int l, int r) {
if ((l <= x) && (y <= r)) return node[id][0];
if ((y < l) || (r < x)) return 1;
int mid = (x+y)/2;
return (find_pro(id*2,x,mid,l,r)*find_pro(id*2+1,mid+1,y,l,r))%mod;
}
long long solve() {
done = 0;
long long cur = nxt(1,1,n,n)-1, lst = n, maxx = 1;
while (maxx <= 1e9+7) {
maxx = max(maxx,find_max(1,1,n,cur+1,lst));
lst = cur+1;
maxx *= find_pro(1,1,n,lst,lst);
done = 0;
if (cur == -1) break;
cur = nxt(1,1,n,cur)-1;
}
return ((maxx%mod)*find_pro(1,1,n,1,lst-1))%mod;
}
signed init(signed N, signed X[], signed Y[]) {
n = N;
for (int i = 0; i < n; i++) a[i+1] = X[i], b[i+1] = Y[i];
build(1,1,n);
return solve();
}
signed updateX(signed pos, signed val) {
pos++;
update(1,0,1,n,pos,val%mod);
update(1,1,1,n,pos,val);
return solve();
}
signed updateY(signed pos, signed val) {
pos++;
update(1,2,1,n,pos,val);
return solve();
}
Compilation message
horses.cpp: In function 'long long int solve()':
horses.cpp:73:9: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
73 | while (maxx <= 1e9+7) {
| ^~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:88:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
88 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:95:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
95 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:101:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
101 | return solve();
| ~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4696 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 |
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 |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 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 |
4444 KB |
Output is correct |
19 |
Correct |
1 ms |
4444 KB |
Output is correct |
20 |
Correct |
1 ms |
4444 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 |
4444 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 |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4440 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 |
4444 KB |
Output is correct |
24 |
Correct |
1 ms |
4444 KB |
Output is correct |
25 |
Correct |
3 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4556 KB |
Output is correct |
27 |
Correct |
7 ms |
4444 KB |
Output is correct |
28 |
Correct |
3 ms |
4444 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
2 ms |
4444 KB |
Output is correct |
31 |
Correct |
5 ms |
4444 KB |
Output is correct |
32 |
Correct |
7 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1020 ms |
39600 KB |
Output is correct |
2 |
Correct |
154 ms |
52048 KB |
Output is correct |
3 |
Correct |
245 ms |
43252 KB |
Output is correct |
4 |
Correct |
146 ms |
47164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4696 KB |
Output is correct |
3 |
Correct |
1 ms |
4440 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 |
4536 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 |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 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 |
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 |
4512 KB |
Output is correct |
24 |
Correct |
2 ms |
4444 KB |
Output is correct |
25 |
Correct |
2 ms |
4444 KB |
Output is correct |
26 |
Correct |
2 ms |
4444 KB |
Output is correct |
27 |
Correct |
7 ms |
4444 KB |
Output is correct |
28 |
Correct |
3 ms |
4628 KB |
Output is correct |
29 |
Correct |
2 ms |
4444 KB |
Output is correct |
30 |
Correct |
2 ms |
4444 KB |
Output is correct |
31 |
Correct |
6 ms |
4440 KB |
Output is correct |
32 |
Correct |
7 ms |
4444 KB |
Output is correct |
33 |
Correct |
42 ms |
42436 KB |
Output is correct |
34 |
Correct |
35 ms |
42596 KB |
Output is correct |
35 |
Correct |
76 ms |
49588 KB |
Output is correct |
36 |
Correct |
56 ms |
49748 KB |
Output is correct |
37 |
Correct |
153 ms |
40784 KB |
Output is correct |
38 |
Correct |
51 ms |
41696 KB |
Output is correct |
39 |
Correct |
41 ms |
40788 KB |
Output is correct |
40 |
Correct |
52 ms |
44456 KB |
Output is correct |
41 |
Correct |
95 ms |
40692 KB |
Output is correct |
42 |
Correct |
128 ms |
40612 KB |
Output is correct |
43 |
Correct |
33 ms |
44880 KB |
Output is correct |
44 |
Correct |
33 ms |
44884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 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 |
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 |
4444 KB |
Output is correct |
12 |
Correct |
1 ms |
4444 KB |
Output is correct |
13 |
Correct |
1 ms |
4444 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 |
4440 KB |
Output is correct |
18 |
Correct |
1 ms |
4440 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 |
2 ms |
4444 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 |
7 ms |
4444 KB |
Output is correct |
28 |
Correct |
3 ms |
4624 KB |
Output is correct |
29 |
Correct |
2 ms |
4700 KB |
Output is correct |
30 |
Correct |
2 ms |
4444 KB |
Output is correct |
31 |
Correct |
5 ms |
4444 KB |
Output is correct |
32 |
Correct |
7 ms |
4444 KB |
Output is correct |
33 |
Correct |
1006 ms |
43416 KB |
Output is correct |
34 |
Correct |
153 ms |
52120 KB |
Output is correct |
35 |
Correct |
266 ms |
43352 KB |
Output is correct |
36 |
Correct |
146 ms |
47048 KB |
Output is correct |
37 |
Correct |
39 ms |
42604 KB |
Output is correct |
38 |
Correct |
35 ms |
42580 KB |
Output is correct |
39 |
Correct |
82 ms |
50004 KB |
Output is correct |
40 |
Correct |
56 ms |
49492 KB |
Output is correct |
41 |
Correct |
156 ms |
40788 KB |
Output is correct |
42 |
Correct |
50 ms |
41548 KB |
Output is correct |
43 |
Correct |
33 ms |
40464 KB |
Output is correct |
44 |
Correct |
46 ms |
44916 KB |
Output is correct |
45 |
Correct |
89 ms |
40528 KB |
Output is correct |
46 |
Correct |
127 ms |
40788 KB |
Output is correct |
47 |
Correct |
32 ms |
44880 KB |
Output is correct |
48 |
Correct |
33 ms |
44936 KB |
Output is correct |
49 |
Correct |
172 ms |
44540 KB |
Output is correct |
50 |
Correct |
130 ms |
44644 KB |
Output is correct |
51 |
Correct |
336 ms |
51540 KB |
Output is correct |
52 |
Correct |
128 ms |
50804 KB |
Output is correct |
53 |
Correct |
1274 ms |
42964 KB |
Output is correct |
54 |
Correct |
310 ms |
43420 KB |
Output is correct |
55 |
Correct |
174 ms |
41592 KB |
Output is correct |
56 |
Correct |
189 ms |
46404 KB |
Output is correct |
57 |
Correct |
753 ms |
42312 KB |
Output is correct |
58 |
Correct |
1194 ms |
42900 KB |
Output is correct |
59 |
Correct |
36 ms |
44940 KB |
Output is correct |