#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define ii pair<int,int>
#define fi first
#define se second
typedef long long ll ;
typedef long double lf ;
const ll mod = 1e9 + 7 ;
int n ;
ii arr[500010] ;
pair< lf ,lf > st[2000010] ;
pair< ll ,ll > res[2000010] ;
void updval(int node){
st[node].fi = st[2*node].fi + st[2*node+1].fi ; res[node].fi = res[2*node].fi * res[2*node+1].fi ;
res[node].fi %= mod ;
if( st[2*node].fi + st[2*node+1].se >= st[2*node].se ){
st[node].se = st[2*node].fi + st[2*node+1].se ;
res[node].se = ( res[2*node].fi * res[2*node+1].se ) %mod ;
}
else{
st[node].se = st[2*node].se ;
res[node].se = res[2*node].se ;
}
}
void build(int node ,int f,int l){
if(f == l){
res[node] = {1LL * arr[f].fi , 1LL * arr[f].fi * arr[f].se } ;
res[node].se %= mod ;
st[node] = { log((lf)arr[f].fi) , log((lf)arr[f].fi * (lf)arr[f].se) } ;
return ;
}
build(2*node , f , (f+l)/2 ) ; build(2*node +1 , (f+l)/2 + 1 , l ) ;
updval(node) ;
}
void upd(int node , int f,int l , int x){
if(f == l){
res[node] = {1LL * arr[f].fi , 1LL * arr[f].fi * arr[f].se } ;
res[node].se %= mod ;
st[node] = { log((lf)arr[f].fi) , log((lf)arr[f].fi * (lf)arr[f].se) } ;
return ;
}
int mid = (f+l)>>1 ;
if(mid < x) upd(2*node+1 , mid+1 , l , x) ;
else upd(2*node , f , mid , x) ;
updval(node) ;
// printf("%d %d : %d %d %lf %lf" , f, l,res[node].fi , ) ;
}
int init(int N, int X[], int Y[]) {
n = N ;
for(int i=0; i<n ;i++) arr[i] = {X[i] , Y[i]} ;
build(1 , 0 , n-1 ) ;
return res[1].se ;
}
int updateX(int pos, int val) {
arr[pos].fi = val ;
upd(1 , 0 , n-1, pos) ;
return res[1].se ;
}
int updateY(int pos, int val) {
arr[pos].se = val ;
upd(1 , 0 , n-1, pos) ;
return res[1].se ;
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:6:12: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
#define se second
^
horses.cpp:59:16: note: in expansion of macro 'se'
return res[1].se ;
^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:6:12: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
#define se second
^
horses.cpp:65:16: note: in expansion of macro 'se'
return res[1].se ;
^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:6:12: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
#define se second
^
horses.cpp:71:16: note: in expansion of macro 'se'
return res[1].se ;
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
99692 KB |
Output is correct |
2 |
Correct |
0 ms |
99692 KB |
Output is correct |
3 |
Correct |
0 ms |
99692 KB |
Output is correct |
4 |
Correct |
0 ms |
99692 KB |
Output is correct |
5 |
Correct |
0 ms |
99692 KB |
Output is correct |
6 |
Correct |
0 ms |
99692 KB |
Output is correct |
7 |
Correct |
0 ms |
99692 KB |
Output is correct |
8 |
Correct |
0 ms |
99692 KB |
Output is correct |
9 |
Correct |
0 ms |
99692 KB |
Output is correct |
10 |
Correct |
0 ms |
99692 KB |
Output is correct |
11 |
Correct |
0 ms |
99692 KB |
Output is correct |
12 |
Correct |
0 ms |
99692 KB |
Output is correct |
13 |
Correct |
0 ms |
99692 KB |
Output is correct |
14 |
Correct |
0 ms |
99692 KB |
Output is correct |
15 |
Correct |
0 ms |
99692 KB |
Output is correct |
16 |
Correct |
0 ms |
99692 KB |
Output is correct |
17 |
Correct |
0 ms |
99692 KB |
Output is correct |
18 |
Correct |
0 ms |
99692 KB |
Output is correct |
19 |
Correct |
0 ms |
99692 KB |
Output is correct |
20 |
Correct |
0 ms |
99692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
99692 KB |
Output is correct |
2 |
Correct |
0 ms |
99692 KB |
Output is correct |
3 |
Correct |
0 ms |
99692 KB |
Output is correct |
4 |
Correct |
0 ms |
99692 KB |
Output is correct |
5 |
Correct |
0 ms |
99692 KB |
Output is correct |
6 |
Correct |
0 ms |
99692 KB |
Output is correct |
7 |
Correct |
0 ms |
99692 KB |
Output is correct |
8 |
Correct |
0 ms |
99692 KB |
Output is correct |
9 |
Correct |
0 ms |
99692 KB |
Output is correct |
10 |
Correct |
0 ms |
99692 KB |
Output is correct |
11 |
Correct |
0 ms |
99692 KB |
Output is correct |
12 |
Correct |
0 ms |
99692 KB |
Output is correct |
13 |
Correct |
0 ms |
99692 KB |
Output is correct |
14 |
Correct |
0 ms |
99692 KB |
Output is correct |
15 |
Correct |
0 ms |
99692 KB |
Output is correct |
16 |
Correct |
0 ms |
99692 KB |
Output is correct |
17 |
Correct |
0 ms |
99692 KB |
Output is correct |
18 |
Correct |
0 ms |
99692 KB |
Output is correct |
19 |
Correct |
0 ms |
99692 KB |
Output is correct |
20 |
Correct |
0 ms |
99692 KB |
Output is correct |
21 |
Correct |
0 ms |
99692 KB |
Output is correct |
22 |
Correct |
0 ms |
99692 KB |
Output is correct |
23 |
Correct |
0 ms |
99692 KB |
Output is correct |
24 |
Correct |
0 ms |
99692 KB |
Output is correct |
25 |
Correct |
0 ms |
99692 KB |
Output is correct |
26 |
Correct |
0 ms |
99692 KB |
Output is correct |
27 |
Correct |
0 ms |
99692 KB |
Output is correct |
28 |
Correct |
0 ms |
99692 KB |
Output is correct |
29 |
Correct |
0 ms |
99692 KB |
Output is correct |
30 |
Correct |
0 ms |
99692 KB |
Output is correct |
31 |
Correct |
0 ms |
99692 KB |
Output is correct |
32 |
Correct |
0 ms |
99692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
153 ms |
103604 KB |
Output is correct |
2 |
Correct |
253 ms |
103604 KB |
Output is correct |
3 |
Correct |
223 ms |
103604 KB |
Output is correct |
4 |
Correct |
213 ms |
103604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
99692 KB |
Output is correct |
2 |
Correct |
0 ms |
99692 KB |
Output is correct |
3 |
Correct |
0 ms |
99692 KB |
Output is correct |
4 |
Correct |
0 ms |
99692 KB |
Output is correct |
5 |
Correct |
0 ms |
99692 KB |
Output is correct |
6 |
Correct |
0 ms |
99692 KB |
Output is correct |
7 |
Correct |
0 ms |
99692 KB |
Output is correct |
8 |
Correct |
0 ms |
99692 KB |
Output is correct |
9 |
Correct |
0 ms |
99692 KB |
Output is correct |
10 |
Correct |
0 ms |
99692 KB |
Output is correct |
11 |
Correct |
0 ms |
99692 KB |
Output is correct |
12 |
Correct |
0 ms |
99692 KB |
Output is correct |
13 |
Correct |
0 ms |
99692 KB |
Output is correct |
14 |
Correct |
0 ms |
99692 KB |
Output is correct |
15 |
Correct |
0 ms |
99692 KB |
Output is correct |
16 |
Correct |
0 ms |
99692 KB |
Output is correct |
17 |
Correct |
0 ms |
99692 KB |
Output is correct |
18 |
Correct |
0 ms |
99692 KB |
Output is correct |
19 |
Correct |
0 ms |
99692 KB |
Output is correct |
20 |
Correct |
0 ms |
99692 KB |
Output is correct |
21 |
Correct |
0 ms |
99692 KB |
Output is correct |
22 |
Correct |
0 ms |
99692 KB |
Output is correct |
23 |
Correct |
0 ms |
99692 KB |
Output is correct |
24 |
Correct |
0 ms |
99692 KB |
Output is correct |
25 |
Correct |
0 ms |
99692 KB |
Output is correct |
26 |
Correct |
0 ms |
99692 KB |
Output is correct |
27 |
Correct |
0 ms |
99692 KB |
Output is correct |
28 |
Correct |
0 ms |
99692 KB |
Output is correct |
29 |
Correct |
0 ms |
99692 KB |
Output is correct |
30 |
Correct |
0 ms |
99692 KB |
Output is correct |
31 |
Correct |
0 ms |
99692 KB |
Output is correct |
32 |
Correct |
0 ms |
99692 KB |
Output is correct |
33 |
Correct |
113 ms |
103604 KB |
Output is correct |
34 |
Correct |
109 ms |
103604 KB |
Output is correct |
35 |
Correct |
109 ms |
103604 KB |
Output is correct |
36 |
Correct |
103 ms |
103604 KB |
Output is correct |
37 |
Correct |
113 ms |
103604 KB |
Output is correct |
38 |
Correct |
83 ms |
103604 KB |
Output is correct |
39 |
Correct |
106 ms |
103604 KB |
Output is correct |
40 |
Correct |
83 ms |
103604 KB |
Output is correct |
41 |
Correct |
99 ms |
103604 KB |
Output is correct |
42 |
Correct |
103 ms |
103604 KB |
Output is correct |
43 |
Correct |
89 ms |
103604 KB |
Output is correct |
44 |
Correct |
66 ms |
103604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
99692 KB |
Output is correct |
2 |
Correct |
0 ms |
99692 KB |
Output is correct |
3 |
Correct |
0 ms |
99692 KB |
Output is correct |
4 |
Correct |
0 ms |
99692 KB |
Output is correct |
5 |
Correct |
0 ms |
99692 KB |
Output is correct |
6 |
Correct |
0 ms |
99692 KB |
Output is correct |
7 |
Correct |
0 ms |
99692 KB |
Output is correct |
8 |
Correct |
0 ms |
99692 KB |
Output is correct |
9 |
Correct |
0 ms |
99692 KB |
Output is correct |
10 |
Correct |
0 ms |
99692 KB |
Output is correct |
11 |
Correct |
0 ms |
99692 KB |
Output is correct |
12 |
Correct |
0 ms |
99692 KB |
Output is correct |
13 |
Correct |
0 ms |
99692 KB |
Output is correct |
14 |
Correct |
0 ms |
99692 KB |
Output is correct |
15 |
Correct |
0 ms |
99692 KB |
Output is correct |
16 |
Correct |
0 ms |
99692 KB |
Output is correct |
17 |
Correct |
0 ms |
99692 KB |
Output is correct |
18 |
Correct |
0 ms |
99692 KB |
Output is correct |
19 |
Correct |
0 ms |
99692 KB |
Output is correct |
20 |
Correct |
0 ms |
99692 KB |
Output is correct |
21 |
Correct |
0 ms |
99692 KB |
Output is correct |
22 |
Correct |
0 ms |
99692 KB |
Output is correct |
23 |
Correct |
0 ms |
99692 KB |
Output is correct |
24 |
Correct |
0 ms |
99692 KB |
Output is correct |
25 |
Correct |
0 ms |
99692 KB |
Output is correct |
26 |
Correct |
0 ms |
99692 KB |
Output is correct |
27 |
Correct |
0 ms |
99692 KB |
Output is correct |
28 |
Correct |
0 ms |
99692 KB |
Output is correct |
29 |
Correct |
0 ms |
99692 KB |
Output is correct |
30 |
Correct |
0 ms |
99692 KB |
Output is correct |
31 |
Correct |
0 ms |
99692 KB |
Output is correct |
32 |
Correct |
0 ms |
99692 KB |
Output is correct |
33 |
Correct |
146 ms |
103604 KB |
Output is correct |
34 |
Correct |
223 ms |
103604 KB |
Output is correct |
35 |
Correct |
243 ms |
103604 KB |
Output is correct |
36 |
Correct |
263 ms |
103604 KB |
Output is correct |
37 |
Correct |
109 ms |
103604 KB |
Output is correct |
38 |
Correct |
119 ms |
103604 KB |
Output is correct |
39 |
Correct |
96 ms |
103604 KB |
Output is correct |
40 |
Correct |
116 ms |
103604 KB |
Output is correct |
41 |
Correct |
96 ms |
103604 KB |
Output is correct |
42 |
Correct |
93 ms |
103604 KB |
Output is correct |
43 |
Correct |
109 ms |
103604 KB |
Output is correct |
44 |
Correct |
76 ms |
103604 KB |
Output is correct |
45 |
Correct |
103 ms |
103604 KB |
Output is correct |
46 |
Correct |
99 ms |
103604 KB |
Output is correct |
47 |
Correct |
83 ms |
103604 KB |
Output is correct |
48 |
Correct |
99 ms |
103604 KB |
Output is correct |
49 |
Correct |
259 ms |
103604 KB |
Output is correct |
50 |
Correct |
249 ms |
103604 KB |
Output is correct |
51 |
Correct |
179 ms |
103604 KB |
Output is correct |
52 |
Correct |
169 ms |
103604 KB |
Output is correct |
53 |
Correct |
249 ms |
103604 KB |
Output is correct |
54 |
Correct |
149 ms |
103604 KB |
Output is correct |
55 |
Correct |
183 ms |
103604 KB |
Output is correct |
56 |
Correct |
169 ms |
103604 KB |
Output is correct |
57 |
Correct |
159 ms |
103604 KB |
Output is correct |
58 |
Correct |
149 ms |
103604 KB |
Output is correct |
59 |
Correct |
83 ms |
103604 KB |
Output is correct |