#include <bits/stdc++.h>
#include "horses.h"
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using Node = pair<double, int>;
const int mod = 1e9 + 7;
const int maxn = 1e5 + 5;
int n;
vector<int> X(5*maxn), Y(5*maxn), PS(5*maxn);
vector<double> logX(5*maxn), logY(5*maxn), PL(5*maxn);
Node merge(Node a, Node b) {
if(a.first > b.first) return a;
return b;
}
struct SegTree {
int N;
vector<ll> prod;
vector<Node> tree;
vector<double> lazy;
void init() {
N = n;
prod.resize(5*N+5);
tree.resize(5*N+5);
lazy.resize(5*N+5);
build(1, 0, N-1);
}
void push(int u, int tl, int tr) {
if(lazy[u] == 0) return ;
tree[u].first += lazy[u];
if(tl != tr) {
lazy[2*u] += lazy[u];
lazy[2*u+1] += lazy[u];
}
lazy[u] = 0;
}
void build(int u, int tl, int tr) {
if(tl == tr) {
tree[u] = { PL[tl] + logY[tl], tl };
prod[u] = X[tl];
} else {
int tm = (tl + tr) / 2;
build(2*u, tl, tm);
build(2*u+1, tm+1, tr);
prod[u] = (prod[2*u] * prod[2*u+1]) % mod;
tree[u] = merge(tree[2*u], tree[2*u+1]);
}
}
void updateProd(int u, int tl, int tr, int pos, int val) {
if(tl == tr) {
prod[u] = val;
} else {
int tm = (tl + tr) / 2;
if(pos <= tm)
updateProd(2*u, tl, tm, pos, val);
else
updateProd(2*u+1, tm+1, tr, pos, val);
prod[u] = (prod[2*u] * prod[2*u+1]) % mod;
}
}
void updatePos(int u, int tl, int tr, int l, int r, double val) {
push(u, tl, tr);
if(tl > tr || tl > r || l > tr) return ;
if(l <= tl && tr <= r) {
lazy[u] += val;
push(u, tl, tr);
return ;
}
int tm = (tl + tr) / 2;
updatePos(2*u, tl, tm, l, r, val);
updatePos(2*u+1, tm+1, tr, l, r, val);
tree[u] = merge(tree[2*u], tree[2*u+1]);
}
ll getProd(int u, int tl, int tr, int l, int r) {
if(tl > tr || l > tr || tl > r) return 1;
if(l <= tl && tr <= r) return prod[u];
int tm = (tl + tr) / 2;
return (
getProd(2*u, tl, tm, l, r) *
getProd(2*u+1, tm+1, tr, l, r)
) % mod;
}
Node getPos(int u, int tl, int tr, int l, int r) {
if(tl > tr || l > tr || tl > r) return { -1e18, 0 };
push(u, tl, tr);
if(l <= tl && tr <= r) return tree[u];
int tm = (tl + tr) / 2;
return merge(
getPos(2*u, tl, tm, l, r),
getPos(2*u+1, tm+1, tr, l, r)
);
}
void updateProd(int pos, int val) { updateProd(1, 0, N-1, pos, val); }
ll getProd(int p) { return getProd(1, 0, N-1, 0, p); }
int getPos() { return getPos(1, 0, N-1, 0, N-1).second; }
void updatePos(int l, int r, double val) { updatePos(1, 0, N-1, l, r, val); }
} tree;
int calc() {
int pos = tree.getPos();
ll ans = (tree.getProd(pos) * Y[pos]) % mod;
return (int)ans;
}
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];
PS[i] = X[i];
if(i) PS[i] = (1ll * PS[i] * PS[i-1]) % mod;
logX[i] = log2(X[i]), logY[i] = log2(y[i]);
PL[i] = logX[i];
if(i) PL[i] += PL[i-1];
}
tree.init();
return calc();
}
int updateX(int p, int v) {
tree.updatePos(p, n-1, -logX[p]);
X[p] = v, logX[p] = log2(v);
tree.updateProd(p, v);
tree.updatePos(p, n-1, log2(v));
return calc();
}
int updateY(int p, int v) {
tree.updatePos(p, p, -logY[p]);
Y[p] = v, logY[p] = log2(v);
tree.updatePos(p, p, log2(v));
return calc();
}
// int main() {
// int n;
// cin >> n;
// int x[n], y[n];
// for(int i=0; i<n; i++) cin >> x[i];
// for(int i=0; i<n; i++) cin >> y[i];
// cout << init(n, x, y) << '\n';
// int m;
// cin >> m;
// while(m--) {
// int t, p, v;
// cin >> t >> p >> v;
// if(t == 1) cout << updateX(p, v) << '\n';
// else cout << updateY(p, v) << '\n';
// }
// return 0;
// }
Compilation message
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:134:47: warning: conversion from 'long long int' to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
134 | if(i) PS[i] = (1ll * PS[i] * PS[i-1]) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
18012 KB |
Output is correct |
2 |
Correct |
5 ms |
18012 KB |
Output is correct |
3 |
Correct |
6 ms |
18012 KB |
Output is correct |
4 |
Correct |
6 ms |
18008 KB |
Output is correct |
5 |
Correct |
6 ms |
18012 KB |
Output is correct |
6 |
Correct |
6 ms |
18012 KB |
Output is correct |
7 |
Correct |
6 ms |
18012 KB |
Output is correct |
8 |
Correct |
6 ms |
18012 KB |
Output is correct |
9 |
Correct |
6 ms |
18012 KB |
Output is correct |
10 |
Correct |
6 ms |
18012 KB |
Output is correct |
11 |
Correct |
5 ms |
18012 KB |
Output is correct |
12 |
Correct |
6 ms |
18024 KB |
Output is correct |
13 |
Correct |
5 ms |
17928 KB |
Output is correct |
14 |
Correct |
6 ms |
18012 KB |
Output is correct |
15 |
Correct |
6 ms |
18012 KB |
Output is correct |
16 |
Correct |
5 ms |
17940 KB |
Output is correct |
17 |
Correct |
6 ms |
18012 KB |
Output is correct |
18 |
Correct |
7 ms |
18012 KB |
Output is correct |
19 |
Correct |
6 ms |
18012 KB |
Output is correct |
20 |
Correct |
6 ms |
18012 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
18012 KB |
Output is correct |
2 |
Correct |
5 ms |
18080 KB |
Output is correct |
3 |
Correct |
6 ms |
18008 KB |
Output is correct |
4 |
Correct |
6 ms |
18008 KB |
Output is correct |
5 |
Correct |
6 ms |
18080 KB |
Output is correct |
6 |
Correct |
6 ms |
18008 KB |
Output is correct |
7 |
Correct |
6 ms |
18008 KB |
Output is correct |
8 |
Correct |
6 ms |
18012 KB |
Output is correct |
9 |
Correct |
6 ms |
18080 KB |
Output is correct |
10 |
Correct |
7 ms |
17832 KB |
Output is correct |
11 |
Correct |
5 ms |
18012 KB |
Output is correct |
12 |
Correct |
6 ms |
17976 KB |
Output is correct |
13 |
Correct |
5 ms |
18024 KB |
Output is correct |
14 |
Correct |
5 ms |
18012 KB |
Output is correct |
15 |
Correct |
5 ms |
18012 KB |
Output is correct |
16 |
Correct |
6 ms |
17932 KB |
Output is correct |
17 |
Correct |
6 ms |
18012 KB |
Output is correct |
18 |
Correct |
6 ms |
18008 KB |
Output is correct |
19 |
Correct |
7 ms |
18012 KB |
Output is correct |
20 |
Correct |
6 ms |
18012 KB |
Output is correct |
21 |
Correct |
6 ms |
18008 KB |
Output is correct |
22 |
Correct |
6 ms |
18080 KB |
Output is correct |
23 |
Correct |
8 ms |
18268 KB |
Output is correct |
24 |
Correct |
6 ms |
18264 KB |
Output is correct |
25 |
Correct |
6 ms |
18268 KB |
Output is correct |
26 |
Correct |
6 ms |
18180 KB |
Output is correct |
27 |
Correct |
7 ms |
18012 KB |
Output is correct |
28 |
Correct |
6 ms |
18268 KB |
Output is correct |
29 |
Correct |
6 ms |
18012 KB |
Output is correct |
30 |
Correct |
7 ms |
18012 KB |
Output is correct |
31 |
Correct |
6 ms |
18012 KB |
Output is correct |
32 |
Correct |
6 ms |
18092 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
105040 KB |
Output is correct |
2 |
Correct |
208 ms |
113776 KB |
Output is correct |
3 |
Correct |
176 ms |
104920 KB |
Output is correct |
4 |
Correct |
203 ms |
108624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
18012 KB |
Output is correct |
2 |
Correct |
6 ms |
18012 KB |
Output is correct |
3 |
Correct |
6 ms |
18012 KB |
Output is correct |
4 |
Correct |
5 ms |
17952 KB |
Output is correct |
5 |
Correct |
6 ms |
18012 KB |
Output is correct |
6 |
Correct |
5 ms |
18012 KB |
Output is correct |
7 |
Correct |
5 ms |
18012 KB |
Output is correct |
8 |
Correct |
6 ms |
18012 KB |
Output is correct |
9 |
Correct |
5 ms |
18012 KB |
Output is correct |
10 |
Correct |
5 ms |
18012 KB |
Output is correct |
11 |
Correct |
6 ms |
18012 KB |
Output is correct |
12 |
Correct |
7 ms |
18012 KB |
Output is correct |
13 |
Correct |
5 ms |
18008 KB |
Output is correct |
14 |
Correct |
6 ms |
18012 KB |
Output is correct |
15 |
Correct |
6 ms |
18080 KB |
Output is correct |
16 |
Correct |
6 ms |
18012 KB |
Output is correct |
17 |
Correct |
5 ms |
18012 KB |
Output is correct |
18 |
Correct |
6 ms |
18012 KB |
Output is correct |
19 |
Correct |
6 ms |
18012 KB |
Output is correct |
20 |
Correct |
6 ms |
18012 KB |
Output is correct |
21 |
Correct |
8 ms |
18012 KB |
Output is correct |
22 |
Correct |
6 ms |
18012 KB |
Output is correct |
23 |
Correct |
6 ms |
18268 KB |
Output is correct |
24 |
Correct |
7 ms |
18272 KB |
Output is correct |
25 |
Correct |
7 ms |
18264 KB |
Output is correct |
26 |
Correct |
6 ms |
18268 KB |
Output is correct |
27 |
Correct |
6 ms |
18012 KB |
Output is correct |
28 |
Correct |
6 ms |
18012 KB |
Output is correct |
29 |
Correct |
6 ms |
18012 KB |
Output is correct |
30 |
Correct |
6 ms |
18012 KB |
Output is correct |
31 |
Correct |
6 ms |
18092 KB |
Output is correct |
32 |
Correct |
6 ms |
18264 KB |
Output is correct |
33 |
Correct |
64 ms |
104268 KB |
Output is correct |
34 |
Correct |
61 ms |
104188 KB |
Output is correct |
35 |
Correct |
90 ms |
110792 KB |
Output is correct |
36 |
Correct |
82 ms |
110928 KB |
Output is correct |
37 |
Correct |
52 ms |
102352 KB |
Output is correct |
38 |
Correct |
55 ms |
103248 KB |
Output is correct |
39 |
Correct |
46 ms |
102312 KB |
Output is correct |
40 |
Correct |
69 ms |
106248 KB |
Output is correct |
41 |
Correct |
52 ms |
102252 KB |
Output is correct |
42 |
Correct |
52 ms |
102228 KB |
Output is correct |
43 |
Correct |
63 ms |
106576 KB |
Output is correct |
44 |
Correct |
63 ms |
106576 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
18008 KB |
Output is correct |
2 |
Correct |
8 ms |
18012 KB |
Output is correct |
3 |
Correct |
5 ms |
18008 KB |
Output is correct |
4 |
Correct |
6 ms |
18024 KB |
Output is correct |
5 |
Correct |
6 ms |
18012 KB |
Output is correct |
6 |
Correct |
5 ms |
18012 KB |
Output is correct |
7 |
Correct |
6 ms |
18008 KB |
Output is correct |
8 |
Correct |
6 ms |
18012 KB |
Output is correct |
9 |
Correct |
6 ms |
18012 KB |
Output is correct |
10 |
Correct |
6 ms |
18012 KB |
Output is correct |
11 |
Correct |
6 ms |
18008 KB |
Output is correct |
12 |
Correct |
5 ms |
18012 KB |
Output is correct |
13 |
Correct |
6 ms |
18012 KB |
Output is correct |
14 |
Correct |
6 ms |
18012 KB |
Output is correct |
15 |
Correct |
6 ms |
18012 KB |
Output is correct |
16 |
Correct |
5 ms |
18012 KB |
Output is correct |
17 |
Correct |
5 ms |
18044 KB |
Output is correct |
18 |
Correct |
6 ms |
18012 KB |
Output is correct |
19 |
Correct |
5 ms |
18076 KB |
Output is correct |
20 |
Correct |
6 ms |
17832 KB |
Output is correct |
21 |
Correct |
6 ms |
18012 KB |
Output is correct |
22 |
Correct |
6 ms |
17940 KB |
Output is correct |
23 |
Correct |
6 ms |
18520 KB |
Output is correct |
24 |
Correct |
7 ms |
18268 KB |
Output is correct |
25 |
Correct |
7 ms |
18148 KB |
Output is correct |
26 |
Correct |
6 ms |
18268 KB |
Output is correct |
27 |
Correct |
7 ms |
18152 KB |
Output is correct |
28 |
Correct |
6 ms |
18268 KB |
Output is correct |
29 |
Correct |
7 ms |
18012 KB |
Output is correct |
30 |
Correct |
6 ms |
18052 KB |
Output is correct |
31 |
Correct |
6 ms |
18264 KB |
Output is correct |
32 |
Correct |
6 ms |
18088 KB |
Output is correct |
33 |
Correct |
109 ms |
105044 KB |
Output is correct |
34 |
Correct |
210 ms |
113488 KB |
Output is correct |
35 |
Correct |
176 ms |
104932 KB |
Output is correct |
36 |
Correct |
209 ms |
108748 KB |
Output is correct |
37 |
Correct |
63 ms |
104148 KB |
Output is correct |
38 |
Correct |
58 ms |
104272 KB |
Output is correct |
39 |
Correct |
83 ms |
110928 KB |
Output is correct |
40 |
Correct |
84 ms |
110856 KB |
Output is correct |
41 |
Correct |
52 ms |
102232 KB |
Output is correct |
42 |
Correct |
54 ms |
103248 KB |
Output is correct |
43 |
Correct |
46 ms |
102228 KB |
Output is correct |
44 |
Correct |
69 ms |
106204 KB |
Output is correct |
45 |
Correct |
43 ms |
102228 KB |
Output is correct |
46 |
Correct |
46 ms |
102400 KB |
Output is correct |
47 |
Correct |
61 ms |
106616 KB |
Output is correct |
48 |
Correct |
62 ms |
106488 KB |
Output is correct |
49 |
Correct |
180 ms |
106060 KB |
Output is correct |
50 |
Correct |
184 ms |
106192 KB |
Output is correct |
51 |
Correct |
147 ms |
112980 KB |
Output is correct |
52 |
Correct |
138 ms |
112468 KB |
Output is correct |
53 |
Correct |
159 ms |
104800 KB |
Output is correct |
54 |
Correct |
131 ms |
105040 KB |
Output is correct |
55 |
Correct |
101 ms |
103200 KB |
Output is correct |
56 |
Correct |
148 ms |
107904 KB |
Output is correct |
57 |
Correct |
98 ms |
104016 KB |
Output is correct |
58 |
Correct |
104 ms |
104340 KB |
Output is correct |
59 |
Correct |
61 ms |
106504 KB |
Output is correct |