#include "horses.h"
#include <bits/stdc++.h>
typedef long double ld;
typedef long long ll;
using namespace std;
int n;
const int NN = 1e6+5;
const ll mod = 1e9+7;
ll a[NN];
ll b[NN];
//=============================================
ll binpow(ll p, ll q){
if(q == 0)return 1ll;
ll temp = binpow(p, q/2);
temp *= temp;
temp %= mod;
if(q%2==1)temp *= p;
return temp%mod;
}ll inver(ll p){
return binpow(p, mod-2);
}//===============================================
struct Node {
ld sum;
ll mul;
};
Node neutral = {0., 1ll};
int sz;
vector<Node> t;
vector<Node> ans;
Node combine(Node f, Node s){
return {f.sum+s.sum, (f.mul*s.mul)%mod};
}
Node mx(Node f, Node s){
if(f.sum > s.sum)return f;
else return s;
}
void build(){
sz=1;
while(sz<n)sz<<=1;
t.assign(sz*2, neutral);
ans.assign(sz*2, neutral);
for(int i=0;i<n;i++){
t[i+sz].sum = log2(a[i]);
t[i+sz].mul = a[i];
}for(int i=1;i<sz;i++){
t[i+sz].sum += t[i+sz-1].sum;
t[i+sz].mul *= t[i+sz-1].mul;t[i+sz].mul%=mod;
}for(int i=0;i<sz;i++){
ans[i+sz].sum = t[i+sz].sum+log2(b[i]);
ans[i+sz].mul =(t[i+sz].mul*b[i])%mod;
}for(int i=sz-1;i>0;i--){
ans[i] = mx(ans[i*2], ans[i*2+1]);
}
}
Node getpref(int i){
ld ansd = 0.;
ll ansl = 1;
for(i+=sz; i>0; i>>=1){
ansd += t[i].sum;
ansl *= t[i].mul;ansl%=mod;
}return {ansd, ansl};
}
void push(int L, int R, int node){
if(R-L == 1)return;
t[node*2] = combine(t[node], t[node*2]);
t[node*2+1]=combine(t[node], t[node*2+1]);
ans[node*2] = combine(ans[node*2], t[node]);
ans[node*2+1]=combine(ans[node*2+1], t[node]);
t[node] = neutral;
ans[node] = mx(ans[node*2], ans[node*2+1]);
}
void modifyX(int l, int r, int L, int R, Node val, int node){
if(L >= r || R <= l)return;
push(L, R, node);
if(L >= l && R <= r){
t[node] = combine(t[node], val);
ans[node]=combine(ans[node], val);
return;
}int mid = (L+R)/2;
modifyX(l, r, L, mid, val, node*2);
modifyX(l, r, mid, R, val, node*2+1);
ans[node] = mx(ans[node*2], ans[node*2+1]);
}
void modifyY(int pos, int L, int R, Node val, int node){
if(R-L == 1){
ans[node] = val;
return;
}int mid = (L+R)/2;
push(L, R, node);
if(mid <= pos){
modifyY(pos, mid, R, val, node*2+1);
}else {
modifyY(pos, L, mid, val, node*2);
}ans[node] = mx(ans[node*2], ans[node*2+1]);
}//===============================================
int init(int N, int X[], int Y[]) {
n = N;
for(int i=0;i<n;i++)a[i] = X[i];
for(int i=0;i<n;i++)b[i] = Y[i];
build();
return ans[1].mul;
}
int updateX(int pos, int val) {
// Node X = getpref(pos);
modifyX(pos, sz, 0, sz, {log2(val)-log2(a[pos]), ((val*inver(a[pos]))%mod)}, 1);
a[pos] = val;
return ans[1].mul;
}
int updateY(int pos, int val) {
Node X = getpref(pos);
modifyY(pos, 0, sz, {X.sum+log2(val), (X.mul*val)%mod}, 1);
b[pos] = val;
return ans[1].mul;
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:105:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
105 | return ans[1].mul;
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:112:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
112 | return ans[1].mul;
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:119:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
119 | return ans[1].mul;
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
288 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 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 |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
256 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 |
256 KB |
Output is correct |
19 |
Correct |
0 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 |
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 |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
256 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 |
256 KB |
Output is correct |
13 |
Correct |
1 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 |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 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 |
544 KB |
Output is correct |
24 |
Correct |
2 ms |
640 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
2 ms |
512 KB |
Output is correct |
28 |
Correct |
2 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
1 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
512 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
200 ms |
78712 KB |
Output is correct |
2 |
Correct |
418 ms |
78784 KB |
Output is correct |
3 |
Correct |
365 ms |
82556 KB |
Output is correct |
4 |
Correct |
423 ms |
86520 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 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 |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
0 ms |
256 KB |
Output is correct |
13 |
Correct |
0 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
256 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 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 |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
2 ms |
512 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
2 ms |
512 KB |
Output is correct |
28 |
Correct |
2 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
3 ms |
640 KB |
Output is correct |
31 |
Correct |
1 ms |
512 KB |
Output is correct |
32 |
Correct |
1 ms |
512 KB |
Output is correct |
33 |
Correct |
122 ms |
77816 KB |
Output is correct |
34 |
Correct |
125 ms |
81912 KB |
Output is correct |
35 |
Correct |
144 ms |
87288 KB |
Output is correct |
36 |
Correct |
147 ms |
87288 KB |
Output is correct |
37 |
Correct |
98 ms |
79992 KB |
Output is correct |
38 |
Correct |
117 ms |
80888 KB |
Output is correct |
39 |
Correct |
85 ms |
79992 KB |
Output is correct |
40 |
Correct |
114 ms |
83704 KB |
Output is correct |
41 |
Correct |
81 ms |
79952 KB |
Output is correct |
42 |
Correct |
84 ms |
79992 KB |
Output is correct |
43 |
Correct |
98 ms |
84088 KB |
Output is correct |
44 |
Correct |
99 ms |
84088 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 |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
288 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
0 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 |
256 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 |
0 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 |
512 KB |
Output is correct |
24 |
Correct |
2 ms |
512 KB |
Output is correct |
25 |
Correct |
2 ms |
512 KB |
Output is correct |
26 |
Correct |
2 ms |
512 KB |
Output is correct |
27 |
Correct |
2 ms |
512 KB |
Output is correct |
28 |
Correct |
2 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
1 ms |
512 KB |
Output is correct |
32 |
Correct |
2 ms |
512 KB |
Output is correct |
33 |
Correct |
200 ms |
78704 KB |
Output is correct |
34 |
Correct |
426 ms |
88168 KB |
Output is correct |
35 |
Correct |
357 ms |
82552 KB |
Output is correct |
36 |
Correct |
420 ms |
86392 KB |
Output is correct |
37 |
Correct |
127 ms |
81788 KB |
Output is correct |
38 |
Correct |
122 ms |
81784 KB |
Output is correct |
39 |
Correct |
146 ms |
87672 KB |
Output is correct |
40 |
Correct |
144 ms |
87672 KB |
Output is correct |
41 |
Correct |
97 ms |
79992 KB |
Output is correct |
42 |
Correct |
113 ms |
80888 KB |
Output is correct |
43 |
Correct |
82 ms |
79864 KB |
Output is correct |
44 |
Correct |
115 ms |
83720 KB |
Output is correct |
45 |
Correct |
81 ms |
79864 KB |
Output is correct |
46 |
Correct |
95 ms |
79992 KB |
Output is correct |
47 |
Correct |
99 ms |
84088 KB |
Output is correct |
48 |
Correct |
99 ms |
84088 KB |
Output is correct |
49 |
Correct |
390 ms |
83832 KB |
Output is correct |
50 |
Correct |
401 ms |
83920 KB |
Output is correct |
51 |
Correct |
291 ms |
88696 KB |
Output is correct |
52 |
Correct |
302 ms |
88568 KB |
Output is correct |
53 |
Correct |
364 ms |
82172 KB |
Output is correct |
54 |
Correct |
301 ms |
82812 KB |
Output is correct |
55 |
Correct |
210 ms |
80888 KB |
Output is correct |
56 |
Correct |
303 ms |
85580 KB |
Output is correct |
57 |
Correct |
198 ms |
81528 KB |
Output is correct |
58 |
Correct |
228 ms |
81984 KB |
Output is correct |
59 |
Correct |
99 ms |
84088 KB |
Output is correct |