#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const long long mod = 1e9 + 7;
struct range {
public:
ll p_m, s_m, m_m, h_a;
int p_o, s_o, x, y;
range()
{
h_a = 1;
p_m = s_m = m_m = 1;
p_o = s_o = x = y = 0;
}
range(int i_, int x_, int y_)
{
h_a = x_;
s_m = 1;
p_m = x_;
x = x_;
y = y_;
m_m = y_;
p_o = s_o = 0;
}
range operator+(range b)
{
range res;
bool choose = false;
if (s_m * b.p_m > mod)
choose = true;
else if (s_m * b.p_m * b.m_m > m_m)
choose = true;
if (s_o || b.p_o)
choose = true;
if (choose) {
res.p_m = b.p_m * s_m;
int tp_o = 0;
if (res.p_m >= mod)
tp_o = 1;
res.p_m %= mod;
res.h_a = h_a * res.p_m;
res.h_a %= mod;
res.p_m *= p_m;
if (res.p_m >= mod)
tp_o = 1;
res.p_m %= mod;
res.p_o = p_o | tp_o;
res.m_m = b.m_m;
res.s_m = b.s_m;
res.s_o = b.s_o;
} else {
res.s_m = b.s_m * s_m;
int ts_o = 0;
if (res.s_m >= mod)
ts_o = 1;
res.s_m %= mod;
res.s_m *= b.p_m;
if (res.s_m >= mod)
ts_o = 1;
res.s_m %= mod;
res.s_o = b.s_o | ts_o;
res.p_m = p_m;
res.p_o = p_o;
res.m_m = m_m;
res.h_a = h_a;
}
return res;
}
void print()
{
//cout << p_m << ' ' << s_m << ' ' << m_m << ' ' << h_a << ' ' << p_o << ' ' << s_o << ' ' << x << ' ' << y << endl;
}
};
template <class T>
struct SegTree {
int n;
vector<T> v;
void rupdate(int i, int l, int r, int idx, T val)
{
if (r - l == 1) {
if (l == idx)
v[i] = val;
} else {
int m = (r - l) / 2 + l;
if (idx < m)
rupdate(2 * i, l, m, idx, val);
else
rupdate(2 * i + 1, m, r, idx, val);
v[i] = v[2 * i] + v[2 * i + 1];
}
}
void update(int idx, T val)
{
rupdate(1, 0, n, idx, val);
}
T query()
{
return v[1];
}
SegTree() { }
SegTree(vector<T> in)
{
n = 1;
while (n < in.size())
n *= 2;
v = vector<T>(2 * n + 5);
for (int i = 0; i < in.size(); i++)
update(i, in[i]);
}
};
SegTree<range> st;
vector<range> vr;
int init(int N, int X[], int Y[])
{
vr = vector<range>(N);
for (int i = 0; i < N; i++) {
vr[i] = range(i, X[i], Y[i]);
}
//cout << N << endl;
st = SegTree<range>(vr);
st.query().print();
return (st.query().h_a * st.query().m_m) % mod;
}
int updateX(int pos, int val)
{
vr[pos] = range(pos, val, vr[pos].y);
st.update(pos, vr[pos]);
st.query().print();
return (st.query().h_a * st.query().m_m) % mod;
}
int updateY(int pos, int val)
{
vr[pos] = range(pos, vr[pos].x, val);
st.update(pos, vr[pos]);
st.query().print();
return (st.query().h_a * st.query().m_m) % mod;
}
Compilation message
horses.cpp: In constructor 'range::range(int, int, int)':
horses.cpp:19:15: warning: unused parameter 'i_' [-Wunused-parameter]
19 | range(int i_, int x_, int y_)
| ~~~~^~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:129:46: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
129 | return (st.query().h_a * st.query().m_m) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:137:46: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
137 | return (st.query().h_a * st.query().m_m) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:145:46: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
145 | return (st.query().h_a * st.query().m_m) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In instantiation of 'SegTree<T>::SegTree(std::vector<_Tp>) [with T = range]':
horses.cpp:127:27: required from here
horses.cpp:109:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<range, std::allocator<range> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
109 | while (n < in.size())
| ~~^~~~~~~~~~~
horses.cpp:112:27: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<range, std::allocator<range> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
112 | for (int i = 0; i < in.size(); i++)
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
0 ms |
300 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
292 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
296 KB |
Output is correct |
7 |
Correct |
1 ms |
300 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 |
0 ms |
300 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 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 |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 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 |
0 ms |
300 KB |
Output is correct |
7 |
Correct |
0 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 |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
304 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 |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
296 KB |
Output is correct |
21 |
Correct |
1 ms |
296 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
2 ms |
436 KB |
Output is correct |
24 |
Correct |
2 ms |
496 KB |
Output is correct |
25 |
Incorrect |
2 ms |
440 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
266 ms |
100820 KB |
Output is correct |
2 |
Correct |
349 ms |
111420 KB |
Output is correct |
3 |
Correct |
328 ms |
102512 KB |
Output is correct |
4 |
Correct |
346 ms |
106428 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
300 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 |
300 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 |
300 KB |
Output is correct |
11 |
Correct |
0 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 |
340 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 |
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 |
456 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
296 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
296 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
304 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 |
296 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 |
296 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 |
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 |
2 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Incorrect |
1 ms |
468 KB |
Output isn't correct |
26 |
Halted |
0 ms |
0 KB |
- |