#include "horses.h"
#define mp make_pair
#define f first
#define s second
#include <bits/stdc++.h>
using namespace std;
struct SegTree
{
int n;
vector<pair<int, double>> data;
vector<double> lazy;
SegTree(int n) : n(n), data(n<<2), lazy(n<<2) {}
pair<int, double> merge(pair<int, double> a, pair<int, double> b)
{
if (b.s > a.s)
return b;
else
return a;
}
void push(int l, int r, int index)
{
data[index].s += lazy[index];
if (r - l > 1)
{
lazy[index<<1] += lazy[index];
lazy[(index<<1)|1] += lazy[index];
}
lazy[index] = 0;
}
void update_range(int l, int r, int index, int ss, int ee, double val)
{
push(l, r, index);
if (ss >= r || l >= ee)
return;
if (ee >= r && l >= ss)
{
lazy[index] += val;
push(l, r, index);
return;
}
int m = l+r>>1;
update_range(l, m, index<<1, ss, ee, val);
update_range(m, r, (index<<1)|1, ss, ee, val);
data[index] = merge(data[index<<1], data[(index<<1)|1]);
}
void set(int l, int r, int index, int i, double val)
{
push(l, r, index);
if (i >= r || l > i)
return;
if (r - l == 1)
{
data[index].f = i;
data[index].s += val;
return;
}
int m = l+r>>1;
set(l, m, index<<1, i, val);
set(m, r, (index<<1)|1, i, val);
data[index] = merge(data[index<<1], data[(index<<1)|1]);
}
pair<int, double> get(int l, int r, int index, int ss, int ee)
{
push(l, r, index);
if (ss >= r || l >= ee)
return mp(-1, -1);
if (ee >= r && l >= ss)
return data[index];
int m = l+r>>1;
pair<int, double> lres = get(l, m, index<<1, ss, ee);
pair<int, double> rres = get(m, r, (index<<1)|1, ss, ee);
return merge(lres, rres);
}
void set(int i, double val) { set(0, n, 1, i, val); }
pair<int, double> get(int ss, int ee) { return get(0, n, 1, ss, ee); }
void update_range(int ss, int ee, double val) { update_range(0, n, 1, ss, ee, val); }
};
constexpr static int MXSIZE = 5e5;
constexpr static int MOD = 1e9 + 7;
double xl[MXSIZE];
double yl[MXSIZE];
int x[MXSIZE], y[MXSIZE];
int mul(int64_t a, int64_t b)
{
return (a * b) % MOD;
}
int st[MXSIZE<<1];
SegTree stm(0);
int n;
void update(int i, int val) { for (st[i+=n]=val;i>1;i>>=1) st[i>>1] = mul(st[i], st[i^1]); }
int get(int l, int r)
{
int res = 1;
for (l+=n,r+=n;l<r;l>>=1,r>>=1)
{
if (l&1) res = mul(res, st[l++]);
if (r&1) res = mul(res, st[--r]);
}
return res;
}
int get_best()
{
int i = stm.get(0, n).f;
return mul(get(0, i+1), y[i]);
}
int init(int N, int X[], int Y[])
{
n = N;
stm = SegTree(n);
for (int i = 0; i < n; i++)
{
x[i] = X[i];
y[i] = Y[i];
xl[i] = log2(x[i]);
yl[i] = log2(y[i]);
update(i, x[i]);
}
for (int i = 0; i < n; i++)
stm.set(i, yl[i]);
for (int i = 0; i < n; i++)
stm.update_range(i, n, xl[i]);
return get_best();
}
int updateY(int pos, int val)
{
y[pos] = val;
double _new = log2(val);
double change = _new - yl[pos];
yl[pos] = _new;
stm.set(pos, change);
return get_best();
}
int updateX(int pos, int val)
{
x[pos] = val;
update(pos, val);
double _new = log2(val);
double change = _new - xl[pos];
xl[pos] = _new;
stm.update_range(pos, n, change);
return get_best();
}
Compilation message
horses.cpp: In constructor 'SegTree::SegTree(int)':
horses.cpp:14:21: warning: declaration of 'n' shadows a member of 'SegTree' [-Wshadow]
14 | SegTree(int n) : n(n), data(n<<2), lazy(n<<2) {}
| ~~~~^
horses.cpp:11:13: note: shadowed declaration is here
11 | int n;
| ^
horses.cpp: In constructor 'SegTree::SegTree(int)':
horses.cpp:14:21: warning: declaration of 'n' shadows a member of 'SegTree' [-Wshadow]
14 | SegTree(int n) : n(n), data(n<<2), lazy(n<<2) {}
| ~~~~^
horses.cpp:11:13: note: shadowed declaration is here
11 | int n;
| ^
horses.cpp: In constructor 'SegTree::SegTree(int)':
horses.cpp:14:21: warning: declaration of 'n' shadows a member of 'SegTree' [-Wshadow]
14 | SegTree(int n) : n(n), data(n<<2), lazy(n<<2) {}
| ~~~~^
horses.cpp:11:13: note: shadowed declaration is here
11 | int n;
| ^
horses.cpp: In member function 'void SegTree::update_range(int, int, int, int, int, double)':
horses.cpp:43:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
43 | int m = l+r>>1;
| ~^~
horses.cpp: In member function 'void SegTree::set(int, int, int, int, double)':
horses.cpp:59:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
59 | int m = l+r>>1;
| ~^~
horses.cpp: In member function 'std::pair<int, double> SegTree::get(int, int, int, int, int)':
horses.cpp:71:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
71 | int m = l+r>>1;
| ~^~
horses.cpp: In function 'int mul(int64_t, int64_t)':
horses.cpp:90:24: warning: conversion from 'int64_t' {aka 'long int'} to 'int' may change value [-Wconversion]
90 | return (a * b) % MOD;
| ~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
264 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
448 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
472 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
383 ms |
69404 KB |
Output is correct |
2 |
Correct |
510 ms |
80372 KB |
Output is correct |
3 |
Correct |
425 ms |
71560 KB |
Output is correct |
4 |
Correct |
449 ms |
75360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
300 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
352 ms |
70768 KB |
Output is correct |
34 |
Correct |
339 ms |
70760 KB |
Output is correct |
35 |
Correct |
372 ms |
77692 KB |
Output is correct |
36 |
Correct |
362 ms |
77644 KB |
Output is correct |
37 |
Correct |
327 ms |
68992 KB |
Output is correct |
38 |
Correct |
368 ms |
69852 KB |
Output is correct |
39 |
Correct |
323 ms |
68888 KB |
Output is correct |
40 |
Correct |
354 ms |
72720 KB |
Output is correct |
41 |
Correct |
355 ms |
68884 KB |
Output is correct |
42 |
Correct |
371 ms |
68960 KB |
Output is correct |
43 |
Correct |
342 ms |
73164 KB |
Output is correct |
44 |
Correct |
370 ms |
73208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
312 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
2 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
448 KB |
Output is correct |
30 |
Correct |
2 ms |
596 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
1 ms |
468 KB |
Output is correct |
33 |
Correct |
387 ms |
71600 KB |
Output is correct |
34 |
Correct |
482 ms |
80388 KB |
Output is correct |
35 |
Correct |
436 ms |
71500 KB |
Output is correct |
36 |
Correct |
464 ms |
75416 KB |
Output is correct |
37 |
Correct |
342 ms |
70768 KB |
Output is correct |
38 |
Correct |
345 ms |
70768 KB |
Output is correct |
39 |
Correct |
371 ms |
77772 KB |
Output is correct |
40 |
Correct |
374 ms |
77700 KB |
Output is correct |
41 |
Correct |
361 ms |
68940 KB |
Output is correct |
42 |
Correct |
337 ms |
69940 KB |
Output is correct |
43 |
Correct |
331 ms |
68888 KB |
Output is correct |
44 |
Correct |
360 ms |
72744 KB |
Output is correct |
45 |
Correct |
352 ms |
68876 KB |
Output is correct |
46 |
Correct |
327 ms |
68920 KB |
Output is correct |
47 |
Correct |
357 ms |
73212 KB |
Output is correct |
48 |
Correct |
368 ms |
73212 KB |
Output is correct |
49 |
Correct |
476 ms |
72840 KB |
Output is correct |
50 |
Correct |
451 ms |
72836 KB |
Output is correct |
51 |
Correct |
435 ms |
79164 KB |
Output is correct |
52 |
Correct |
474 ms |
79132 KB |
Output is correct |
53 |
Correct |
463 ms |
71124 KB |
Output is correct |
54 |
Correct |
416 ms |
71696 KB |
Output is correct |
55 |
Correct |
415 ms |
69892 KB |
Output is correct |
56 |
Correct |
397 ms |
74640 KB |
Output is correct |
57 |
Correct |
377 ms |
70608 KB |
Output is correct |
58 |
Correct |
374 ms |
71088 KB |
Output is correct |
59 |
Correct |
391 ms |
73208 KB |
Output is correct |