#include "horses.h"
#include<bits/stdc++.h>
using namespace std;
const int maxn = 5e5 + 10;
const int inf = 1e9 + 1;
const int mod = 1e9 + 7;
int n;
int x[maxn], y[maxn];
struct Node{
int ans;
int opt;
int mulx;
int mudx;
} seg[4*maxn];
int Mul(int a, int b){
return min(1LL*inf, 1LL*a*b);
}
int getmul(int id, int L, int R, int l, int r){
if (r <= L or R <= l)
return 1;
if (l <= L and R <= r)
return seg[id].mulx;
int mid = (L+R) >> 1;
return Mul(getmul(2*id+0,L,mid,l,r),getmul(2*id+1,mid,R,l,r));
}
int CmpFunc(int a, int b){
if (a > b)
swap(a, b);
if (y[a] >= 1LL*y[b]*getmul(1, 0, n, a+1, b+1))
return a;
return b;
}
Node merge(Node a, Node b){
if (CmpFunc(a.opt,b.opt) == a.opt){
a.mulx = Mul(a.mulx, b.mulx);
a.mudx = 1LL*a.mudx*b.mudx%mod;
return a;
}
b.ans = 1LL*b.ans*a.mudx%mod;
b.mulx = Mul(a.mulx, b.mulx);
b.mudx = 1LL*a.mudx*b.mudx%mod;
return b;
}
void change(int id, int L, int R, int idx){
if (idx < L or R <= idx)
return;
if (L+1 == R){
seg[id].ans = 1LL*x[L]*y[L]%mod, seg[id].opt = L, seg[id].mulx = seg[id].mudx = x[L];
return;
}
int mid = (L + R) >> 1;
change(2*id+0, L, mid, idx);
change(2*id+1, mid, R, idx);
seg[id] = merge(seg[2*id+0],seg[2*id+1]);
}
void build(int id, int L, int R){
if (L+1 == R){
seg[id].ans = 1LL*x[L]*y[L]%mod, seg[id].opt = L, seg[id].mulx = seg[id].mudx = x[L];
return;
}
int mid = (L + R) >> 1;
build(2*id+0, L, mid);
build(2*id+1, mid, R);
seg[id] = merge(seg[2*id+0],seg[2*id+1]);
}
int init(int N, int X[], int Y[]){
n = N;
for (int i = 0; i < n; i++)
x[i] = X[i], y[i] = Y[i];
build(1, 0, n);
return seg[1].ans;
}
int updateX(int pos, int val){
x[pos] = val;
change(1, 0, n, pos);
return seg[1].ans;
}
int updateY(int pos, int val){
y[pos] = val;
change(1, 0, n, pos);
return seg[1].ans;
}
Compilation message
horses.cpp: In function 'int Mul(int, int)':
horses.cpp:18:12: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
18 | return min(1LL*inf, 1LL*a*b);
| ~~~^~~~~~~~~~~~~~~~~~
horses.cpp: In function 'Node merge(Node, Node)':
horses.cpp:41:29: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
41 | a.mudx = 1LL*a.mudx*b.mudx%mod;
| ~~~~~~~~~~~~~~~~~^~~~
horses.cpp:44:26: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
44 | b.ans = 1LL*b.ans*a.mudx%mod;
| ~~~~~~~~~~~~~~~~^~~~
horses.cpp:46:28: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
46 | b.mudx = 1LL*a.mudx*b.mudx%mod;
| ~~~~~~~~~~~~~~~~~^~~~
horses.cpp: In function 'void change(int, int, int, int)':
horses.cpp:54:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
54 | seg[id].ans = 1LL*x[L]*y[L]%mod, seg[id].opt = L, seg[id].mulx = seg[id].mudx = x[L];
| ~~~~~~~~~~~~~^~~~
horses.cpp: In function 'void build(int, int, int)':
horses.cpp:65:30: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
65 | seg[id].ans = 1LL*x[L]*y[L]%mod, seg[id].opt = L, seg[id].mulx = seg[id].mudx = x[L];
| ~~~~~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
3 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
2 ms |
384 KB |
Output is correct |
32 |
Correct |
3 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
591 ms |
25860 KB |
Output is correct |
2 |
Correct |
573 ms |
25592 KB |
Output is correct |
3 |
Correct |
721 ms |
25800 KB |
Output is correct |
4 |
Correct |
695 ms |
25848 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
3 ms |
384 KB |
Output is correct |
25 |
Correct |
3 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
3 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
3 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
384 KB |
Output is correct |
33 |
Correct |
260 ms |
24696 KB |
Output is correct |
34 |
Correct |
251 ms |
24696 KB |
Output is correct |
35 |
Correct |
229 ms |
24696 KB |
Output is correct |
36 |
Correct |
208 ms |
24696 KB |
Output is correct |
37 |
Correct |
248 ms |
24824 KB |
Output is correct |
38 |
Correct |
200 ms |
24696 KB |
Output is correct |
39 |
Correct |
222 ms |
24656 KB |
Output is correct |
40 |
Correct |
212 ms |
24696 KB |
Output is correct |
41 |
Correct |
211 ms |
24644 KB |
Output is correct |
42 |
Correct |
221 ms |
24612 KB |
Output is correct |
43 |
Correct |
165 ms |
24572 KB |
Output is correct |
44 |
Correct |
164 ms |
24568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
384 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
384 KB |
Output is correct |
24 |
Correct |
2 ms |
384 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
3 ms |
384 KB |
Output is correct |
28 |
Correct |
2 ms |
384 KB |
Output is correct |
29 |
Correct |
3 ms |
384 KB |
Output is correct |
30 |
Correct |
2 ms |
384 KB |
Output is correct |
31 |
Correct |
3 ms |
384 KB |
Output is correct |
32 |
Correct |
3 ms |
416 KB |
Output is correct |
33 |
Correct |
588 ms |
25716 KB |
Output is correct |
34 |
Correct |
589 ms |
25720 KB |
Output is correct |
35 |
Correct |
732 ms |
25720 KB |
Output is correct |
36 |
Correct |
693 ms |
25592 KB |
Output is correct |
37 |
Correct |
254 ms |
24696 KB |
Output is correct |
38 |
Correct |
254 ms |
24692 KB |
Output is correct |
39 |
Correct |
228 ms |
24712 KB |
Output is correct |
40 |
Correct |
208 ms |
24696 KB |
Output is correct |
41 |
Correct |
246 ms |
24712 KB |
Output is correct |
42 |
Correct |
200 ms |
24696 KB |
Output is correct |
43 |
Correct |
226 ms |
24568 KB |
Output is correct |
44 |
Correct |
204 ms |
24696 KB |
Output is correct |
45 |
Correct |
214 ms |
24696 KB |
Output is correct |
46 |
Correct |
222 ms |
24696 KB |
Output is correct |
47 |
Correct |
169 ms |
24568 KB |
Output is correct |
48 |
Correct |
167 ms |
24568 KB |
Output is correct |
49 |
Correct |
1024 ms |
25592 KB |
Output is correct |
50 |
Correct |
985 ms |
25720 KB |
Output is correct |
51 |
Correct |
651 ms |
25720 KB |
Output is correct |
52 |
Correct |
439 ms |
25592 KB |
Output is correct |
53 |
Correct |
1053 ms |
25572 KB |
Output is correct |
54 |
Correct |
599 ms |
25464 KB |
Output is correct |
55 |
Correct |
813 ms |
24824 KB |
Output is correct |
56 |
Correct |
636 ms |
25848 KB |
Output is correct |
57 |
Correct |
688 ms |
25592 KB |
Output is correct |
58 |
Correct |
809 ms |
25720 KB |
Output is correct |
59 |
Correct |
169 ms |
24604 KB |
Output is correct |