# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
252040 |
2020-07-23T21:18:59 Z |
DS007 |
Horses (IOI15_horses) |
C++14 |
|
1306 ms |
64084 KB |
#include <bits/stdc++.h>
using namespace std;
const long long N = 5e5, mod = 1e9 + 7;
int n, *x, *y;
set<int> s;
class SegmentTree1 {
int t[N * 4];
public:
SegmentTree1() {
fill(t, t + N * 4, 0);
}
void update(int v, int l, int r, int tl, int k) {
if (l == r && l == tl) {
t[v] = k;
return;
}
int mid = (l + r) / 2;
if (tl <= mid)
update(v * 2, l, mid, tl, k);
else
update(v * 2 + 1, mid + 1, r, tl, k);
t[v] = max(t[v * 2], t[v * 2 + 1]);
}
long long query(int v, int l, int r, int tl, int tr) {
if (tl > tr)
return -1;
else if (l == tl && r == tr)
return t[v];
int mid = (l + r) / 2;
return max(query(v * 2, l, mid, tl, min(mid, tr)), query(v * 2 + 1, mid + 1, r, max(tl, mid + 1), tr));
}
};
class SegmentTree2 {
long long t[N * 4];
public:
SegmentTree2() {
fill(t, t + N * 4, 1);
}
void update(int v, int l, int r, int tl, int k) {
if (l == r && l == tl) {
t[v] = k;
return;
}
int mid = (l + r) / 2;
if (tl <= mid)
update(v * 2, l, mid, tl, k);
else
update(v * 2 + 1, mid + 1, r, tl, k);
t[v] = t[v * 2] * t[v * 2 + 1] % mod;
}
long long query(int v, int l, int r, int tl, int tr) {
if (tl > tr)
return 1;
else if (l == tl && r == tr)
return t[v];
int mid = (l + r) / 2;
return query(v * 2, l, mid, tl, min(mid, tr)) * query(v * 2 + 1, mid + 1, r, max(tl, mid + 1), tr) % mod;
}
};
SegmentTree1 st1;
SegmentTree2 st2;
int query() {
auto itr = s.rbegin();
long long temp = 1;
vector<int> v;
while (itr != s.rend() && temp < mod) {
temp *= x[*itr];
assert(x[*itr] >= 2);
v.push_back(*itr);
itr++;
}
//for (int i : v)
// cerr << i << " ";
//cerr << endl;
assert(v.size() <= 32);
long long ans = 1;
for (int i = 0; i < v.size(); i++) {
long long cv = st2.query(1, 0, n - 1, v.back() + 1, v[i]);
assert(cv < mod);
ans = max(ans, cv * st1.query(1, 0, n - 1, v[i], n - 1));
//cerr << cv << " " << ans << endl;
}
if (ans < mod && temp < mod)
return int(max(st1.query(1, 0, n - 1, 0, n - 1), st2.query(1, 0, n - 1, 0, v.empty() ? 0 : v.back()) * ans) % mod);
ans %= mod;
return int(st2.query(1, 0, n - 1, 0, v.empty() ? 0 : v.back()) * ans % mod);
}
int init(int N, int X[], int Y[]) {
n = N;
x = X;
y = Y;
for (int i = 0; i < n; i++) {
st2.update(1, 0, n - 1, i, x[i]);
if (x[i] > 1)
s.insert(i);
st1.update(1, 0, n - 1, i, y[i]);
}
return query();
}
int updateX(int pos, int val) {
s.erase(pos);
st2.update(1, 0, n - 1, pos, val);
x[pos] = val;
if (val > 1)
s.insert(pos);
return query();
}
int updateY(int pos, int val) {
y[pos] = val;
st1.update(1, 0, n - 1, pos, val);
return query();
}
Compilation message
horses.cpp: In function 'int query()':
horses.cpp:97:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < v.size(); i++) {
~~^~~~~~~~~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:111:33: warning: declaration of 'N' shadows a global declaration [-Wshadow]
int init(int N, int X[], int Y[]) {
^
horses.cpp:4:17: note: shadowed declaration is here
const long long N = 5e5, mod = 1e9 + 7;
^
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:130:5: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
if (val > 1)
^~
horses.cpp:132:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
return query();
^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23808 KB |
Output is correct |
2 |
Correct |
12 ms |
23812 KB |
Output is correct |
3 |
Correct |
14 ms |
23808 KB |
Output is correct |
4 |
Correct |
12 ms |
23808 KB |
Output is correct |
5 |
Correct |
14 ms |
23808 KB |
Output is correct |
6 |
Correct |
13 ms |
23808 KB |
Output is correct |
7 |
Correct |
11 ms |
23808 KB |
Output is correct |
8 |
Correct |
13 ms |
23808 KB |
Output is correct |
9 |
Correct |
12 ms |
23808 KB |
Output is correct |
10 |
Correct |
12 ms |
23808 KB |
Output is correct |
11 |
Correct |
12 ms |
23808 KB |
Output is correct |
12 |
Correct |
12 ms |
23808 KB |
Output is correct |
13 |
Correct |
13 ms |
23808 KB |
Output is correct |
14 |
Correct |
12 ms |
23808 KB |
Output is correct |
15 |
Correct |
13 ms |
23808 KB |
Output is correct |
16 |
Correct |
12 ms |
23808 KB |
Output is correct |
17 |
Correct |
16 ms |
23808 KB |
Output is correct |
18 |
Correct |
11 ms |
23808 KB |
Output is correct |
19 |
Correct |
12 ms |
23808 KB |
Output is correct |
20 |
Correct |
14 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23808 KB |
Output is correct |
2 |
Correct |
12 ms |
23808 KB |
Output is correct |
3 |
Correct |
12 ms |
23808 KB |
Output is correct |
4 |
Correct |
12 ms |
23808 KB |
Output is correct |
5 |
Correct |
12 ms |
23808 KB |
Output is correct |
6 |
Correct |
13 ms |
23808 KB |
Output is correct |
7 |
Correct |
12 ms |
23808 KB |
Output is correct |
8 |
Correct |
12 ms |
23808 KB |
Output is correct |
9 |
Correct |
12 ms |
23808 KB |
Output is correct |
10 |
Correct |
12 ms |
23808 KB |
Output is correct |
11 |
Correct |
13 ms |
23936 KB |
Output is correct |
12 |
Correct |
12 ms |
23808 KB |
Output is correct |
13 |
Correct |
11 ms |
23808 KB |
Output is correct |
14 |
Correct |
11 ms |
23808 KB |
Output is correct |
15 |
Correct |
13 ms |
23808 KB |
Output is correct |
16 |
Correct |
13 ms |
23808 KB |
Output is correct |
17 |
Correct |
11 ms |
23808 KB |
Output is correct |
18 |
Correct |
11 ms |
23808 KB |
Output is correct |
19 |
Correct |
12 ms |
23808 KB |
Output is correct |
20 |
Correct |
12 ms |
23808 KB |
Output is correct |
21 |
Correct |
12 ms |
23808 KB |
Output is correct |
22 |
Correct |
11 ms |
23808 KB |
Output is correct |
23 |
Correct |
13 ms |
23808 KB |
Output is correct |
24 |
Correct |
13 ms |
23896 KB |
Output is correct |
25 |
Correct |
14 ms |
23936 KB |
Output is correct |
26 |
Correct |
13 ms |
23936 KB |
Output is correct |
27 |
Correct |
19 ms |
23808 KB |
Output is correct |
28 |
Correct |
15 ms |
23936 KB |
Output is correct |
29 |
Correct |
20 ms |
23808 KB |
Output is correct |
30 |
Correct |
15 ms |
23868 KB |
Output is correct |
31 |
Correct |
18 ms |
23808 KB |
Output is correct |
32 |
Correct |
17 ms |
23808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1220 ms |
52344 KB |
Output is correct |
2 |
Correct |
516 ms |
52424 KB |
Output is correct |
3 |
Correct |
590 ms |
53300 KB |
Output is correct |
4 |
Correct |
715 ms |
59900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
23808 KB |
Output is correct |
2 |
Correct |
11 ms |
23808 KB |
Output is correct |
3 |
Correct |
12 ms |
23808 KB |
Output is correct |
4 |
Correct |
12 ms |
23808 KB |
Output is correct |
5 |
Correct |
12 ms |
23808 KB |
Output is correct |
6 |
Correct |
13 ms |
23808 KB |
Output is correct |
7 |
Correct |
11 ms |
23808 KB |
Output is correct |
8 |
Correct |
12 ms |
23808 KB |
Output is correct |
9 |
Correct |
12 ms |
23808 KB |
Output is correct |
10 |
Correct |
12 ms |
23808 KB |
Output is correct |
11 |
Correct |
13 ms |
23808 KB |
Output is correct |
12 |
Correct |
12 ms |
23808 KB |
Output is correct |
13 |
Correct |
12 ms |
23760 KB |
Output is correct |
14 |
Correct |
12 ms |
23808 KB |
Output is correct |
15 |
Correct |
11 ms |
23808 KB |
Output is correct |
16 |
Correct |
13 ms |
23808 KB |
Output is correct |
17 |
Correct |
12 ms |
23808 KB |
Output is correct |
18 |
Correct |
12 ms |
23808 KB |
Output is correct |
19 |
Correct |
13 ms |
23808 KB |
Output is correct |
20 |
Correct |
12 ms |
23808 KB |
Output is correct |
21 |
Correct |
11 ms |
23808 KB |
Output is correct |
22 |
Correct |
12 ms |
23808 KB |
Output is correct |
23 |
Correct |
13 ms |
23808 KB |
Output is correct |
24 |
Correct |
14 ms |
23808 KB |
Output is correct |
25 |
Correct |
14 ms |
23936 KB |
Output is correct |
26 |
Correct |
14 ms |
23936 KB |
Output is correct |
27 |
Correct |
20 ms |
23808 KB |
Output is correct |
28 |
Correct |
14 ms |
23936 KB |
Output is correct |
29 |
Correct |
14 ms |
23808 KB |
Output is correct |
30 |
Correct |
13 ms |
23936 KB |
Output is correct |
31 |
Correct |
15 ms |
23808 KB |
Output is correct |
32 |
Correct |
18 ms |
23808 KB |
Output is correct |
33 |
Correct |
186 ms |
29060 KB |
Output is correct |
34 |
Correct |
180 ms |
28924 KB |
Output is correct |
35 |
Correct |
334 ms |
52472 KB |
Output is correct |
36 |
Correct |
316 ms |
52216 KB |
Output is correct |
37 |
Correct |
273 ms |
28920 KB |
Output is correct |
38 |
Correct |
266 ms |
40768 KB |
Output is correct |
39 |
Correct |
170 ms |
28800 KB |
Output is correct |
40 |
Correct |
308 ms |
52476 KB |
Output is correct |
41 |
Correct |
234 ms |
28800 KB |
Output is correct |
42 |
Correct |
270 ms |
28800 KB |
Output is correct |
43 |
Correct |
287 ms |
52192 KB |
Output is correct |
44 |
Correct |
295 ms |
52216 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
23808 KB |
Output is correct |
2 |
Correct |
13 ms |
23808 KB |
Output is correct |
3 |
Correct |
11 ms |
23808 KB |
Output is correct |
4 |
Correct |
11 ms |
23808 KB |
Output is correct |
5 |
Correct |
11 ms |
23808 KB |
Output is correct |
6 |
Correct |
12 ms |
23808 KB |
Output is correct |
7 |
Correct |
12 ms |
23808 KB |
Output is correct |
8 |
Correct |
13 ms |
23808 KB |
Output is correct |
9 |
Correct |
12 ms |
23808 KB |
Output is correct |
10 |
Correct |
13 ms |
23808 KB |
Output is correct |
11 |
Correct |
12 ms |
23808 KB |
Output is correct |
12 |
Correct |
12 ms |
23808 KB |
Output is correct |
13 |
Correct |
12 ms |
23808 KB |
Output is correct |
14 |
Correct |
11 ms |
23808 KB |
Output is correct |
15 |
Correct |
11 ms |
23808 KB |
Output is correct |
16 |
Correct |
13 ms |
23808 KB |
Output is correct |
17 |
Correct |
12 ms |
23808 KB |
Output is correct |
18 |
Correct |
12 ms |
23808 KB |
Output is correct |
19 |
Correct |
11 ms |
23808 KB |
Output is correct |
20 |
Correct |
12 ms |
23808 KB |
Output is correct |
21 |
Correct |
12 ms |
23936 KB |
Output is correct |
22 |
Correct |
13 ms |
23808 KB |
Output is correct |
23 |
Correct |
13 ms |
23876 KB |
Output is correct |
24 |
Correct |
13 ms |
23808 KB |
Output is correct |
25 |
Correct |
13 ms |
23936 KB |
Output is correct |
26 |
Correct |
13 ms |
23936 KB |
Output is correct |
27 |
Correct |
18 ms |
23808 KB |
Output is correct |
28 |
Correct |
14 ms |
23936 KB |
Output is correct |
29 |
Correct |
14 ms |
23808 KB |
Output is correct |
30 |
Correct |
15 ms |
23936 KB |
Output is correct |
31 |
Correct |
16 ms |
23808 KB |
Output is correct |
32 |
Correct |
16 ms |
23808 KB |
Output is correct |
33 |
Correct |
1226 ms |
53288 KB |
Output is correct |
34 |
Correct |
521 ms |
53356 KB |
Output is correct |
35 |
Correct |
565 ms |
53260 KB |
Output is correct |
36 |
Correct |
687 ms |
59896 KB |
Output is correct |
37 |
Correct |
181 ms |
31864 KB |
Output is correct |
38 |
Correct |
177 ms |
31864 KB |
Output is correct |
39 |
Correct |
347 ms |
62328 KB |
Output is correct |
40 |
Correct |
353 ms |
62200 KB |
Output is correct |
41 |
Correct |
286 ms |
30072 KB |
Output is correct |
42 |
Correct |
263 ms |
42872 KB |
Output is correct |
43 |
Correct |
174 ms |
29816 KB |
Output is correct |
44 |
Correct |
311 ms |
57228 KB |
Output is correct |
45 |
Correct |
219 ms |
29944 KB |
Output is correct |
46 |
Correct |
251 ms |
29944 KB |
Output is correct |
47 |
Correct |
296 ms |
57720 KB |
Output is correct |
48 |
Correct |
315 ms |
57592 KB |
Output is correct |
49 |
Correct |
360 ms |
34936 KB |
Output is correct |
50 |
Correct |
341 ms |
34936 KB |
Output is correct |
51 |
Correct |
561 ms |
64084 KB |
Output is correct |
52 |
Correct |
427 ms |
63608 KB |
Output is correct |
53 |
Correct |
1306 ms |
33404 KB |
Output is correct |
54 |
Correct |
599 ms |
46876 KB |
Output is correct |
55 |
Correct |
305 ms |
30840 KB |
Output is correct |
56 |
Correct |
448 ms |
59128 KB |
Output is correct |
57 |
Correct |
813 ms |
31480 KB |
Output is correct |
58 |
Correct |
1136 ms |
32172 KB |
Output is correct |
59 |
Correct |
312 ms |
57592 KB |
Output is correct |