#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 500000;
const int MOD = 1000000007;
template<typename T, typename Upd>
struct Aint {
T aint[1+4*MAX_N];
T neutralQry, initVal;
Upd upd;
Aint(T nq, T iv) {
neutralQry = nq;
initVal = iv;
for(int i = 0; i <= 4*MAX_N; ++i)
aint[i] = initVal;
}
void update(int poz, T val, int l = 1, int r = MAX_N, int nod = 1) {
if(poz < l || r < poz) return;
if(l == r)
aint[nod] = upd.update(aint[nod], val);
else {
int mid = (l + r) / 2;
update(poz, val, l, mid, 2 * nod);
update(poz, val, mid + 1, r, 2 * nod + 1);
aint[nod] = upd.query(aint[2 * nod], aint[2 * nod + 1]);
}
}
T query(int i, int j, int l = 1, int r = MAX_N, int nod = 1) {
if(j < l || r < i) return neutralQry;
if(i <= l && r <= j) return aint[nod];
else {
int mid = (l + r) / 2;
return upd.query(query(i, j, l, mid, 2 * nod),
query(i, j, mid + 1, r, 2 * nod + 1));
}
}
};
struct Upd1 {
int update(int a, int b) { return b; }
int query(int a, int b) { return max(a, b); }
};
struct Upd2 {
int update(int a, int b) { return b; }
int query(int a, int b) { return (long long)a * b % MOD;}
};
int N;
int x[1+MAX_N], y[1+MAX_N];
set<int> rel;
Aint<int, Upd1> maxaint(-1, -1);
Aint<int, Upd2> prodaint(1, 1);
int getResult() {
long long best, rez;
best = rez = 0;
set<int>::reverse_iterator it = rel.rbegin();
while(it != rel.rend() && best != -1) {
int pos = *it, maxy = maxaint.query(max(1, pos), N);
if(maxy > best) {
best = maxy;
rez = (long long)prodaint.query(1, max(1, pos)) * maxy % MOD;
}
if(best <= 1000000000 / x[pos])
best = best * x[pos];
else
best = -1;
it++;
}
return rez;
}
int init(int n, int _x[], int _y[]) {
N = n;
x[0] = y[0] = 1;
rel.insert(0);
for(int i = 1; i <= n; ++i) {
x[i] = _x[i - 1];
y[i] = _y[i - 1];
if(x[i] != 1)
rel.insert(i);
maxaint.update(i, y[i]);
prodaint.update(i, x[i]);
}
return getResult();
}
int updateX(int pos, int val) {
pos++;
rel.erase(pos);
x[pos] = val;
if(val != 1)
rel.insert(pos);
prodaint.update(pos, val);
return getResult();
}
int updateY(int pos, int val) {
pos++;
y[pos] = val;
maxaint.update(pos, val);
return getResult();
}
Compilation message
horses.cpp: In member function 'int Upd1::update(int, int)':
horses.cpp:46:18: warning: unused parameter 'a' [-Wunused-parameter]
int update(int a, int b) { return b; }
^
horses.cpp: In member function 'int Upd2::update(int, int)':
horses.cpp:51:18: warning: unused parameter 'a' [-Wunused-parameter]
int update(int a, int b) { return b; }
^
horses.cpp: In member function 'int Upd2::query(int, int)':
horses.cpp:52:54: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
int query(int a, int b) { return (long long)a * b % MOD;}
~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int getResult()':
horses.cpp:82:10: warning: conversion to 'int' from 'long long int' may alter its value [-Wconversion]
return rez;
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
15964 KB |
Output is correct |
2 |
Correct |
13 ms |
15992 KB |
Output is correct |
3 |
Correct |
15 ms |
15992 KB |
Output is correct |
4 |
Correct |
13 ms |
15992 KB |
Output is correct |
5 |
Correct |
14 ms |
15992 KB |
Output is correct |
6 |
Correct |
14 ms |
15992 KB |
Output is correct |
7 |
Correct |
14 ms |
15992 KB |
Output is correct |
8 |
Correct |
14 ms |
15992 KB |
Output is correct |
9 |
Correct |
14 ms |
15992 KB |
Output is correct |
10 |
Correct |
13 ms |
15992 KB |
Output is correct |
11 |
Correct |
14 ms |
15908 KB |
Output is correct |
12 |
Correct |
13 ms |
15992 KB |
Output is correct |
13 |
Correct |
14 ms |
15992 KB |
Output is correct |
14 |
Correct |
14 ms |
15992 KB |
Output is correct |
15 |
Correct |
14 ms |
15992 KB |
Output is correct |
16 |
Correct |
14 ms |
15992 KB |
Output is correct |
17 |
Correct |
15 ms |
15992 KB |
Output is correct |
18 |
Correct |
14 ms |
15992 KB |
Output is correct |
19 |
Correct |
16 ms |
15992 KB |
Output is correct |
20 |
Correct |
14 ms |
15964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
15992 KB |
Output is correct |
2 |
Correct |
13 ms |
16048 KB |
Output is correct |
3 |
Correct |
16 ms |
15992 KB |
Output is correct |
4 |
Correct |
14 ms |
15996 KB |
Output is correct |
5 |
Correct |
18 ms |
15992 KB |
Output is correct |
6 |
Correct |
18 ms |
15992 KB |
Output is correct |
7 |
Correct |
14 ms |
15992 KB |
Output is correct |
8 |
Correct |
13 ms |
15992 KB |
Output is correct |
9 |
Correct |
12 ms |
15992 KB |
Output is correct |
10 |
Correct |
14 ms |
15992 KB |
Output is correct |
11 |
Correct |
12 ms |
15992 KB |
Output is correct |
12 |
Correct |
14 ms |
16120 KB |
Output is correct |
13 |
Correct |
14 ms |
15992 KB |
Output is correct |
14 |
Correct |
14 ms |
15992 KB |
Output is correct |
15 |
Correct |
14 ms |
15992 KB |
Output is correct |
16 |
Correct |
14 ms |
15992 KB |
Output is correct |
17 |
Correct |
15 ms |
16068 KB |
Output is correct |
18 |
Correct |
13 ms |
15992 KB |
Output is correct |
19 |
Correct |
13 ms |
15996 KB |
Output is correct |
20 |
Correct |
14 ms |
15992 KB |
Output is correct |
21 |
Correct |
14 ms |
15992 KB |
Output is correct |
22 |
Correct |
14 ms |
15996 KB |
Output is correct |
23 |
Correct |
20 ms |
16120 KB |
Output is correct |
24 |
Correct |
14 ms |
15992 KB |
Output is correct |
25 |
Correct |
16 ms |
16124 KB |
Output is correct |
26 |
Correct |
15 ms |
16092 KB |
Output is correct |
27 |
Correct |
21 ms |
16120 KB |
Output is correct |
28 |
Correct |
16 ms |
16120 KB |
Output is correct |
29 |
Correct |
16 ms |
15992 KB |
Output is correct |
30 |
Correct |
29 ms |
16120 KB |
Output is correct |
31 |
Correct |
24 ms |
16120 KB |
Output is correct |
32 |
Correct |
18 ms |
16092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
616 ms |
48364 KB |
Output is correct |
2 |
Correct |
503 ms |
60892 KB |
Output is correct |
3 |
Correct |
595 ms |
51984 KB |
Output is correct |
4 |
Correct |
556 ms |
55856 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
15996 KB |
Output is correct |
2 |
Correct |
12 ms |
15992 KB |
Output is correct |
3 |
Correct |
12 ms |
16040 KB |
Output is correct |
4 |
Correct |
14 ms |
15992 KB |
Output is correct |
5 |
Correct |
13 ms |
15992 KB |
Output is correct |
6 |
Correct |
13 ms |
15996 KB |
Output is correct |
7 |
Correct |
13 ms |
15992 KB |
Output is correct |
8 |
Correct |
12 ms |
15992 KB |
Output is correct |
9 |
Correct |
13 ms |
15992 KB |
Output is correct |
10 |
Correct |
14 ms |
15992 KB |
Output is correct |
11 |
Correct |
13 ms |
15992 KB |
Output is correct |
12 |
Correct |
13 ms |
15992 KB |
Output is correct |
13 |
Correct |
14 ms |
15992 KB |
Output is correct |
14 |
Correct |
14 ms |
15992 KB |
Output is correct |
15 |
Correct |
14 ms |
15992 KB |
Output is correct |
16 |
Correct |
14 ms |
15964 KB |
Output is correct |
17 |
Correct |
14 ms |
15992 KB |
Output is correct |
18 |
Correct |
15 ms |
15992 KB |
Output is correct |
19 |
Correct |
17 ms |
15992 KB |
Output is correct |
20 |
Correct |
13 ms |
15992 KB |
Output is correct |
21 |
Correct |
14 ms |
15992 KB |
Output is correct |
22 |
Correct |
14 ms |
15996 KB |
Output is correct |
23 |
Correct |
15 ms |
16120 KB |
Output is correct |
24 |
Correct |
15 ms |
16120 KB |
Output is correct |
25 |
Correct |
15 ms |
16124 KB |
Output is correct |
26 |
Correct |
14 ms |
16120 KB |
Output is correct |
27 |
Correct |
19 ms |
16120 KB |
Output is correct |
28 |
Correct |
15 ms |
16120 KB |
Output is correct |
29 |
Correct |
14 ms |
16072 KB |
Output is correct |
30 |
Correct |
14 ms |
16120 KB |
Output is correct |
31 |
Correct |
16 ms |
16120 KB |
Output is correct |
32 |
Correct |
25 ms |
16064 KB |
Output is correct |
33 |
Correct |
183 ms |
28044 KB |
Output is correct |
34 |
Correct |
184 ms |
28136 KB |
Output is correct |
35 |
Correct |
370 ms |
58252 KB |
Output is correct |
36 |
Correct |
365 ms |
58400 KB |
Output is correct |
37 |
Correct |
203 ms |
26048 KB |
Output is correct |
38 |
Correct |
272 ms |
38944 KB |
Output is correct |
39 |
Correct |
192 ms |
26008 KB |
Output is correct |
40 |
Correct |
356 ms |
53344 KB |
Output is correct |
41 |
Correct |
186 ms |
26108 KB |
Output is correct |
42 |
Correct |
206 ms |
26060 KB |
Output is correct |
43 |
Correct |
350 ms |
53688 KB |
Output is correct |
44 |
Correct |
344 ms |
53824 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
15916 KB |
Output is correct |
2 |
Correct |
12 ms |
15992 KB |
Output is correct |
3 |
Correct |
13 ms |
15992 KB |
Output is correct |
4 |
Correct |
13 ms |
15992 KB |
Output is correct |
5 |
Correct |
16 ms |
15992 KB |
Output is correct |
6 |
Correct |
13 ms |
15996 KB |
Output is correct |
7 |
Correct |
17 ms |
15992 KB |
Output is correct |
8 |
Correct |
13 ms |
15992 KB |
Output is correct |
9 |
Correct |
13 ms |
15992 KB |
Output is correct |
10 |
Correct |
12 ms |
15992 KB |
Output is correct |
11 |
Correct |
12 ms |
15992 KB |
Output is correct |
12 |
Correct |
12 ms |
15964 KB |
Output is correct |
13 |
Correct |
13 ms |
15992 KB |
Output is correct |
14 |
Correct |
13 ms |
15992 KB |
Output is correct |
15 |
Correct |
13 ms |
15964 KB |
Output is correct |
16 |
Correct |
15 ms |
15992 KB |
Output is correct |
17 |
Correct |
13 ms |
15964 KB |
Output is correct |
18 |
Correct |
15 ms |
15992 KB |
Output is correct |
19 |
Correct |
14 ms |
15992 KB |
Output is correct |
20 |
Correct |
15 ms |
15996 KB |
Output is correct |
21 |
Correct |
12 ms |
15992 KB |
Output is correct |
22 |
Correct |
13 ms |
15992 KB |
Output is correct |
23 |
Correct |
14 ms |
16120 KB |
Output is correct |
24 |
Correct |
14 ms |
16120 KB |
Output is correct |
25 |
Correct |
15 ms |
16204 KB |
Output is correct |
26 |
Correct |
14 ms |
16120 KB |
Output is correct |
27 |
Correct |
19 ms |
16120 KB |
Output is correct |
28 |
Correct |
14 ms |
16120 KB |
Output is correct |
29 |
Correct |
14 ms |
16120 KB |
Output is correct |
30 |
Correct |
14 ms |
16120 KB |
Output is correct |
31 |
Correct |
15 ms |
16120 KB |
Output is correct |
32 |
Correct |
17 ms |
16120 KB |
Output is correct |
33 |
Correct |
637 ms |
52216 KB |
Output is correct |
34 |
Correct |
478 ms |
61020 KB |
Output is correct |
35 |
Correct |
496 ms |
52088 KB |
Output is correct |
36 |
Correct |
588 ms |
55932 KB |
Output is correct |
37 |
Correct |
186 ms |
28028 KB |
Output is correct |
38 |
Correct |
178 ms |
28000 KB |
Output is correct |
39 |
Correct |
383 ms |
58440 KB |
Output is correct |
40 |
Correct |
359 ms |
58332 KB |
Output is correct |
41 |
Correct |
206 ms |
26304 KB |
Output is correct |
42 |
Correct |
305 ms |
38940 KB |
Output is correct |
43 |
Correct |
171 ms |
26040 KB |
Output is correct |
44 |
Correct |
356 ms |
53476 KB |
Output is correct |
45 |
Correct |
211 ms |
25904 KB |
Output is correct |
46 |
Correct |
198 ms |
26104 KB |
Output is correct |
47 |
Correct |
348 ms |
53884 KB |
Output is correct |
48 |
Correct |
350 ms |
53624 KB |
Output is correct |
49 |
Correct |
290 ms |
30956 KB |
Output is correct |
50 |
Correct |
275 ms |
30968 KB |
Output is correct |
51 |
Correct |
532 ms |
60264 KB |
Output is correct |
52 |
Correct |
419 ms |
59748 KB |
Output is correct |
53 |
Correct |
543 ms |
29304 KB |
Output is correct |
54 |
Correct |
394 ms |
42876 KB |
Output is correct |
55 |
Correct |
245 ms |
27000 KB |
Output is correct |
56 |
Correct |
445 ms |
55288 KB |
Output is correct |
57 |
Correct |
449 ms |
27592 KB |
Output is correct |
58 |
Correct |
503 ms |
28080 KB |
Output is correct |
59 |
Correct |
375 ms |
53632 KB |
Output is correct |