#include <bits/stdc++.h>
#include "horses.h"
//Soltan Cristian
#define fri(a, b) for (int i = (a); i < (b); ++i)
#define frj(a, b) for(int j = a; j < b; j++)
#define frk(a, b) for(int k = a; k < b; k++)
#define frm(a, b, i) for(int i = b; i >= a; i--)
#define ll long long
#define all(x) x.begin(), x.end()
#define mod 1000000007
#define pb push_back
#define st first
#define nd second
#define sz(x) (ll)x.size()
#define rall(x) x.rbegin(), x.rend()
#define ct(x) cout << x
#define cts(x) cout << x << ' '
#define ctn(x) cout << x << '\n'
// #define Y cout << "YES" << '\n'
// #define N cout << "NO" << '\n'
using namespace std;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vb = vector<bool>;
using ml = map<ll, ll>;
using vii = vector<vector<int>>;
using vll = vector<vector<ll>>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template <typename T>void read(T n, vector<T> &a){fri(0, n){cin >> a[i];}}
template<typename T>void print(T n, T m, vector<vector<T>> &dp){fri(0, n){ct('\n');frj(0, m){ct(setw(5));cts(dp[i][j]);}}}
const ll mxa = 500005;
struct cell{
double lsum, blsum;
ll prod, bprod;
};
int n;
ll x[mxa], y[mxa];
cell st[4 * mxa];
void combine(int v, int l, int r){
st[v].lsum = st[l].lsum + st[r].lsum;
st[v].prod = (st[l].prod * st[r].prod) % mod;
if(st[l].blsum > st[l].lsum + st[r].blsum){
st[v].blsum = st[l].blsum;
st[v].bprod = st[l].bprod;
}
else{
st[v].blsum = st[l].lsum + st[r].blsum;
st[v].bprod = (st[l].prod * st[r].bprod) % mod;
}
}
void build(int v, int tl, int tr){
if(tl == tr){
st[v].lsum = log10(x[tl]);
st[v].prod = x[tl];
st[v].blsum = st[v].lsum + log10(y[tl]);
st[v].bprod = (st[v].prod * y[tl]) % mod;
}
else{
int mid = (tl + tr) / 2;
build(v*2, tl, mid);
build(v * 2 + 1, mid + 1, tr);
combine(v, v * 2, v * 2 + 1);
}
}
void update(int v, int tl, int tr, int poz){
if(tl == tr){
st[v].lsum = log10(x[tl]);
st[v].prod = x[tl];
st[v].blsum = st[v].lsum + log10(y[tl]);
st[v].bprod = (st[v].prod * y[tl]) % mod;
}
else{
int mid = (tl + tr) / 2;
if(poz <= mid){
update(v * 2, tl, mid, poz);
}
else{
update(v * 2 + 1, mid + 1, tr, poz);
}
combine(v, v * 2, v * 2 + 1);
}
}
int init(int N, int X[], int Y[]) {
n = N;
fri(0, n){
x[i] = X[i];
y[i] = Y[i];
}
build(1, 0, n - 1);
return st[1].bprod;
}
int updateX(int pos, int val) {
x[pos] = val;
update(1, 0, n - 1, pos);
return st[1].bprod;
}
int updateY(int pos, int val) {
y[pos] = val;
update(1, 0, n - 1, pos);
return st[1].bprod;
}
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:105:15: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
105 | return st[1].bprod;
| ^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:111:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
111 | return st[1].bprod;
| ^
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:117:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
117 | return st[1].bprod;
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
308 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
312 KB |
Output is correct |
8 |
Correct |
0 ms |
316 KB |
Output is correct |
9 |
Correct |
1 ms |
312 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
308 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
316 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
320 KB |
Output is correct |
30 |
Correct |
1 ms |
320 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
72 ms |
45888 KB |
Output is correct |
2 |
Correct |
158 ms |
58352 KB |
Output is correct |
3 |
Correct |
130 ms |
49608 KB |
Output is correct |
4 |
Correct |
141 ms |
53468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
312 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
316 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
308 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
432 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
62 ms |
48836 KB |
Output is correct |
34 |
Correct |
63 ms |
48868 KB |
Output is correct |
35 |
Correct |
84 ms |
55744 KB |
Output is correct |
36 |
Correct |
85 ms |
55732 KB |
Output is correct |
37 |
Correct |
47 ms |
47052 KB |
Output is correct |
38 |
Correct |
53 ms |
47944 KB |
Output is correct |
39 |
Correct |
41 ms |
47028 KB |
Output is correct |
40 |
Correct |
60 ms |
50776 KB |
Output is correct |
41 |
Correct |
40 ms |
46912 KB |
Output is correct |
42 |
Correct |
40 ms |
47040 KB |
Output is correct |
43 |
Correct |
60 ms |
51148 KB |
Output is correct |
44 |
Correct |
59 ms |
51280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
312 KB |
Output is correct |
14 |
Correct |
1 ms |
316 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
312 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
288 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
304 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
324 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
452 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
320 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
74 ms |
49684 KB |
Output is correct |
34 |
Correct |
167 ms |
58356 KB |
Output is correct |
35 |
Correct |
123 ms |
49580 KB |
Output is correct |
36 |
Correct |
144 ms |
53476 KB |
Output is correct |
37 |
Correct |
65 ms |
48788 KB |
Output is correct |
38 |
Correct |
61 ms |
48884 KB |
Output is correct |
39 |
Correct |
82 ms |
55876 KB |
Output is correct |
40 |
Correct |
89 ms |
55752 KB |
Output is correct |
41 |
Correct |
50 ms |
47052 KB |
Output is correct |
42 |
Correct |
55 ms |
47948 KB |
Output is correct |
43 |
Correct |
40 ms |
46908 KB |
Output is correct |
44 |
Correct |
62 ms |
50880 KB |
Output is correct |
45 |
Correct |
40 ms |
46976 KB |
Output is correct |
46 |
Correct |
43 ms |
46980 KB |
Output is correct |
47 |
Correct |
63 ms |
51228 KB |
Output is correct |
48 |
Correct |
59 ms |
51212 KB |
Output is correct |
49 |
Correct |
139 ms |
50892 KB |
Output is correct |
50 |
Correct |
137 ms |
50824 KB |
Output is correct |
51 |
Correct |
119 ms |
57848 KB |
Output is correct |
52 |
Correct |
107 ms |
57144 KB |
Output is correct |
53 |
Correct |
116 ms |
49168 KB |
Output is correct |
54 |
Correct |
90 ms |
49868 KB |
Output is correct |
55 |
Correct |
72 ms |
48012 KB |
Output is correct |
56 |
Correct |
91 ms |
52700 KB |
Output is correct |
57 |
Correct |
69 ms |
48624 KB |
Output is correct |
58 |
Correct |
69 ms |
49144 KB |
Output is correct |
59 |
Correct |
59 ms |
51148 KB |
Output is correct |