#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const long long num=1000000001, mod=1000000007;
long long seg1[2000005], seg2[2000005], ind[2000005], x[500005], y[500005], n;
void buildSeg(long long i, long long l, long long r)
{
if (l==r)
{
seg1[i]=seg2[i]=x[l];
return;
}
long long mid=(l+r)/2;
buildSeg(i*2, l, mid);
buildSeg(i*2+1, mid+1, r);
seg1[i]=seg1[i*2]*seg1[i*2+1]%mod;
seg2[i]=min(num, seg2[i*2]*seg2[i*2+1]);
}
void updateSeg(long long i, long long l, long long r, long long pos, long long val)
{
if (l==r)
{
seg1[i]=seg2[i]=val;
return;
}
long long mid=(l+r)/2;
if (pos<=mid)
updateSeg(i*2, l, mid, pos, val);
else
updateSeg(i*2+1, mid+1, r, pos, val);
seg1[i]=seg1[i*2]*seg1[i*2+1]%mod;
seg2[i]=min(num, seg2[i*2]*seg2[i*2+1]);
}
long long querySeg(long long i, long long l, long long r, long long ql, long long qr, bool b)
{
if (ql<=l && r<=qr)
{
if (b)
return seg1[i];
else
return seg2[i];
}
long long mid=(l+r)/2, prod=1;
if (l<=qr && ql<=mid)
prod*=querySeg(i*2, l, mid, ql, qr, b);
if (mid+1<=qr && ql<=r)
prod*=querySeg(i*2+1, mid+1, r, ql, qr, b);
if (b)
return prod%mod;
else
return min(num, prod);
}
void buildInd(long long i, long long l, long long r)
{
if (l==r)
{
ind[i]=l;
return;
}
long long mid=(l+r)/2, indl, indr;
buildInd(i*2, l, mid);
buildInd(i*2+1, mid+1, r);
indl=ind[i*2];
indr=ind[i*2+1];
if (y[indl]>querySeg(1, 0, n-1, indl+1, indr, 0)*y[indr])
ind[i]=indl;
else
ind[i]=indr;
}
void updateInd(long long i, long long l, long long r, long long pos)
{
if (l==r)
return;
long long mid=(l+r)/2, indl, indr;
if (pos<=mid)
updateInd(i*2, l, mid, pos);
else
updateInd(i*2+1, mid+1, r, pos);
indl=ind[i*2];
indr=ind[i*2+1];
if (y[indl]>querySeg(1, 0, n-1, indl+1, indr, 0)*y[indr])
ind[i]=indl;
else
ind[i]=indr;
}
long long solve()
{
return querySeg(1, 0, n-1, 0, ind[1], 1)*y[ind[1]]%mod;
}
int init(int N, int X[], int Y[])
{
n=N;
for (long long i=0; i<n; i++)
x[i]=X[i];
for (long long i=0; i<n; i++)
y[i]=Y[i];
buildSeg(1, 0, n-1);
buildInd(1, 0, n-1);
return solve();
}
int updateX(int pos, int val)
{
updateSeg(1, 0, n-1, pos, val);
updateInd(1, 0, n-1, pos);
return solve();
}
int updateY(int pos, int val)
{
y[pos]=val;
updateInd(1, 0, n-1, pos);
return solve();
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:99:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
99 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:105:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
105 | return solve();
| ~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:111:14: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
111 | return solve();
| ~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
304 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
312 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
304 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
308 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
3 ms |
340 KB |
Output is correct |
24 |
Correct |
3 ms |
320 KB |
Output is correct |
25 |
Correct |
2 ms |
440 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
345 ms |
41464 KB |
Output is correct |
2 |
Correct |
397 ms |
41648 KB |
Output is correct |
3 |
Correct |
459 ms |
41420 KB |
Output is correct |
4 |
Correct |
464 ms |
41868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
264 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
312 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
308 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
304 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
444 KB |
Output is correct |
26 |
Correct |
2 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
416 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
312 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
2 ms |
320 KB |
Output is correct |
32 |
Correct |
2 ms |
320 KB |
Output is correct |
33 |
Correct |
162 ms |
40672 KB |
Output is correct |
34 |
Correct |
161 ms |
40604 KB |
Output is correct |
35 |
Correct |
156 ms |
40736 KB |
Output is correct |
36 |
Correct |
135 ms |
40744 KB |
Output is correct |
37 |
Correct |
130 ms |
38880 KB |
Output is correct |
38 |
Correct |
134 ms |
39712 KB |
Output is correct |
39 |
Correct |
101 ms |
38748 KB |
Output is correct |
40 |
Correct |
125 ms |
40928 KB |
Output is correct |
41 |
Correct |
127 ms |
38732 KB |
Output is correct |
42 |
Correct |
105 ms |
38824 KB |
Output is correct |
43 |
Correct |
106 ms |
40724 KB |
Output is correct |
44 |
Correct |
111 ms |
40636 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
304 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
308 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
304 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
308 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
452 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
320 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
316 KB |
Output is correct |
31 |
Correct |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
336 ms |
41312 KB |
Output is correct |
34 |
Correct |
419 ms |
41500 KB |
Output is correct |
35 |
Correct |
458 ms |
41232 KB |
Output is correct |
36 |
Correct |
465 ms |
41232 KB |
Output is correct |
37 |
Correct |
169 ms |
40280 KB |
Output is correct |
38 |
Correct |
170 ms |
40480 KB |
Output is correct |
39 |
Correct |
142 ms |
40140 KB |
Output is correct |
40 |
Correct |
134 ms |
40092 KB |
Output is correct |
41 |
Correct |
174 ms |
38908 KB |
Output is correct |
42 |
Correct |
123 ms |
39756 KB |
Output is correct |
43 |
Correct |
119 ms |
38732 KB |
Output is correct |
44 |
Correct |
120 ms |
39632 KB |
Output is correct |
45 |
Correct |
116 ms |
38708 KB |
Output is correct |
46 |
Correct |
131 ms |
38820 KB |
Output is correct |
47 |
Correct |
111 ms |
39444 KB |
Output is correct |
48 |
Correct |
101 ms |
39272 KB |
Output is correct |
49 |
Correct |
675 ms |
40276 KB |
Output is correct |
50 |
Correct |
633 ms |
40236 KB |
Output is correct |
51 |
Correct |
394 ms |
40008 KB |
Output is correct |
52 |
Correct |
277 ms |
39784 KB |
Output is correct |
53 |
Correct |
524 ms |
39968 KB |
Output is correct |
54 |
Correct |
361 ms |
39728 KB |
Output is correct |
55 |
Correct |
242 ms |
39056 KB |
Output is correct |
56 |
Correct |
262 ms |
39664 KB |
Output is correct |
57 |
Correct |
378 ms |
39500 KB |
Output is correct |
58 |
Correct |
386 ms |
39544 KB |
Output is correct |
59 |
Correct |
107 ms |
38400 KB |
Output is correct |