# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
387334 |
2021-04-08T09:19:37 Z |
aarr |
Horses (IOI15_horses) |
C++14 |
|
1014 ms |
63980 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
const int N = 500 * 1000 + 5, mod = 1000 * 1000 * 1000 + 7;
int n;
long long seg1[N * 4];
int seg2[N * 4];
set <int, greater<int> > s;
long long a[N], b[N];
void update1(int p, int val, int id = 1, int s = 0, int e = n) {
if (e - s == 1) {
seg1[id] = val;
return;
}
int md = (s + e) / 2;
if (p < md) {
update1(p, val, id * 2, s, md);
}
else {
update1(p, val, id * 2 + 1, md, e);
}
seg1[id] = (seg1[id * 2] * seg1[id * 2 + 1]) % mod;
}
void update2(int p, int val, int id = 1, int s = 0, int e = n) {
if (e - s == 1) {
seg2[id] = val;
return;
}
int md = (s + e) / 2;
if (p < md) {
update2(p, val, id * 2, s, md);
}
else {
update2(p, val, id * 2 + 1, md, e);
}
seg2[id] = max(seg2[id * 2], seg2[id * 2 + 1]);
}
long long get1(int l, int r, int id = 1, int s = 0, int e = n) {
if (r <= s || e <= l) {
return 1;
}
if (l <= s && e <= r) {
return seg1[id];
}
int md = (s + e) / 2;
return (get1(l, r, id * 2, s, md) * get1(l, r, id * 2 + 1, md, e)) % mod;
}
int get2(int l, int r, int id = 1, int s = 0, int e = n) {
if (r <= s || e <= l) {
return 0;
}
if (l <= s && e <= r) {
return seg2[id];
}
int md = (s + e) / 2;
return max(get2(l, r, id * 2, s, md), get2(l, r, id * 2 + 1, md, e));
}
int getans() {
long long mp = 1;
long long ans = 0;
int mx = 0, mfor = 0;
long long mmp = 1;
set <int, greater <int> > :: iterator it = s.begin();
while (true) {
int k = *it;
if (k == -1) {
// ans = max(ans, get2(0, n));
break;
}
else {
// cout << "75 " << k << endl;
int t = get2(k, n);
// cout << "78 " << k << " " << t << " " << s << " " << mp << endl;
if (1ll * mp * mx < 1ll * mmp * t) {
mmp = mp;
mx = t;
mfor = k;
}
mp *= a[k];
}
if (mp > mod) {
break;
}
it++;
}
ans = 1ll * get1(0, mfor + 1) * mx;
ans %= mod;
// cout << "74 " << mfor << " " << mx << " " << ans << endl;
return ans;
}
int init(int nn, int X[], int Y[]) {
n = nn;
fill(seg1, seg1 + n * 4, 1);
for (int i = 0; i < n; i++) {
a[i] = X[i];
b[i] = Y[i];
update1(i, a[i]);
update2(i, b[i]);
if (a[i] > 1) {
s.insert(i);
}
}
s.insert(-1);
s.insert(0);
// cout << "72 " << get1(0, 3) << " " << get2(0, 3) << endl;
return getans();
}
int updateX(int pos, int val) {
update1(pos, val);
if (val > 1) {
s.insert(pos);
}
else if(pos != 0) {
s.erase(pos);
}
a[pos] = val;
return getans();
}
int updateY(int pos, int val) {
update2(pos, val);
b[pos] = val;
return getans();
}
Compilation message
horses.cpp: In function 'void update1(int, int, int, int, int)':
horses.cpp:13:62: warning: declaration of 's' shadows a global declaration [-Wshadow]
13 | void update1(int p, int val, int id = 1, int s = 0, int e = n) {
| ^
horses.cpp:10:26: note: shadowed declaration is here
10 | set <int, greater<int> > s;
| ^
horses.cpp: In function 'void update2(int, int, int, int, int)':
horses.cpp:28:62: warning: declaration of 's' shadows a global declaration [-Wshadow]
28 | void update2(int p, int val, int id = 1, int s = 0, int e = n) {
| ^
horses.cpp:10:26: note: shadowed declaration is here
10 | set <int, greater<int> > s;
| ^
horses.cpp: In function 'long long int get1(int, int, int, int, int)':
horses.cpp:43:62: warning: declaration of 's' shadows a global declaration [-Wshadow]
43 | long long get1(int l, int r, int id = 1, int s = 0, int e = n) {
| ^
horses.cpp:10:26: note: shadowed declaration is here
10 | set <int, greater<int> > s;
| ^
horses.cpp: In function 'int get2(int, int, int, int, int)':
horses.cpp:54:56: warning: declaration of 's' shadows a global declaration [-Wshadow]
54 | int get2(int l, int r, int id = 1, int s = 0, int e = n) {
| ^
horses.cpp:10:26: note: shadowed declaration is here
10 | set <int, greater<int> > s;
| ^
horses.cpp: In function 'int getans()':
horses.cpp:96:9: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
96 | return ans;
| ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:105:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
105 | update1(i, a[i]);
| ~~~^
horses.cpp:106:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
106 | update2(i, b[i]);
| ~~~^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
2 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
2 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
2 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
512 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
2 ms |
492 KB |
Output is correct |
27 |
Correct |
4 ms |
492 KB |
Output is correct |
28 |
Correct |
3 ms |
492 KB |
Output is correct |
29 |
Correct |
2 ms |
380 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
31 |
Correct |
5 ms |
492 KB |
Output is correct |
32 |
Correct |
4 ms |
492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1014 ms |
60140 KB |
Output is correct |
2 |
Correct |
555 ms |
61028 KB |
Output is correct |
3 |
Correct |
569 ms |
60268 KB |
Output is correct |
4 |
Correct |
668 ms |
63980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
2 ms |
364 KB |
Output is correct |
4 |
Correct |
2 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
2 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
2 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
1 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
492 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
2 ms |
492 KB |
Output is correct |
27 |
Correct |
4 ms |
492 KB |
Output is correct |
28 |
Correct |
3 ms |
528 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
512 KB |
Output is correct |
31 |
Correct |
4 ms |
492 KB |
Output is correct |
32 |
Correct |
4 ms |
492 KB |
Output is correct |
33 |
Correct |
241 ms |
36204 KB |
Output is correct |
34 |
Correct |
239 ms |
36076 KB |
Output is correct |
35 |
Correct |
404 ms |
60652 KB |
Output is correct |
36 |
Correct |
395 ms |
60780 KB |
Output is correct |
37 |
Correct |
297 ms |
34156 KB |
Output is correct |
38 |
Correct |
319 ms |
46956 KB |
Output is correct |
39 |
Correct |
226 ms |
33900 KB |
Output is correct |
40 |
Correct |
438 ms |
61356 KB |
Output is correct |
41 |
Correct |
258 ms |
34028 KB |
Output is correct |
42 |
Correct |
283 ms |
34156 KB |
Output is correct |
43 |
Correct |
367 ms |
61676 KB |
Output is correct |
44 |
Correct |
390 ms |
61932 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
364 KB |
Output is correct |
11 |
Correct |
1 ms |
364 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
1 ms |
364 KB |
Output is correct |
16 |
Correct |
1 ms |
364 KB |
Output is correct |
17 |
Correct |
1 ms |
364 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
1 ms |
364 KB |
Output is correct |
20 |
Correct |
1 ms |
364 KB |
Output is correct |
21 |
Correct |
1 ms |
364 KB |
Output is correct |
22 |
Correct |
2 ms |
364 KB |
Output is correct |
23 |
Correct |
2 ms |
492 KB |
Output is correct |
24 |
Correct |
2 ms |
492 KB |
Output is correct |
25 |
Correct |
3 ms |
492 KB |
Output is correct |
26 |
Correct |
2 ms |
492 KB |
Output is correct |
27 |
Correct |
4 ms |
492 KB |
Output is correct |
28 |
Correct |
3 ms |
492 KB |
Output is correct |
29 |
Correct |
2 ms |
364 KB |
Output is correct |
30 |
Correct |
2 ms |
492 KB |
Output is correct |
31 |
Correct |
4 ms |
492 KB |
Output is correct |
32 |
Correct |
4 ms |
492 KB |
Output is correct |
33 |
Correct |
986 ms |
60140 KB |
Output is correct |
34 |
Correct |
557 ms |
61276 KB |
Output is correct |
35 |
Correct |
598 ms |
60140 KB |
Output is correct |
36 |
Correct |
667 ms |
63980 KB |
Output is correct |
37 |
Correct |
241 ms |
36076 KB |
Output is correct |
38 |
Correct |
242 ms |
35948 KB |
Output is correct |
39 |
Correct |
411 ms |
60780 KB |
Output is correct |
40 |
Correct |
396 ms |
60908 KB |
Output is correct |
41 |
Correct |
295 ms |
34156 KB |
Output is correct |
42 |
Correct |
319 ms |
46956 KB |
Output is correct |
43 |
Correct |
226 ms |
33900 KB |
Output is correct |
44 |
Correct |
380 ms |
61292 KB |
Output is correct |
45 |
Correct |
264 ms |
33932 KB |
Output is correct |
46 |
Correct |
280 ms |
34028 KB |
Output is correct |
47 |
Correct |
375 ms |
61696 KB |
Output is correct |
48 |
Correct |
373 ms |
61756 KB |
Output is correct |
49 |
Correct |
391 ms |
39020 KB |
Output is correct |
50 |
Correct |
350 ms |
39124 KB |
Output is correct |
51 |
Correct |
580 ms |
61460 KB |
Output is correct |
52 |
Correct |
468 ms |
61548 KB |
Output is correct |
53 |
Correct |
960 ms |
37228 KB |
Output is correct |
54 |
Correct |
557 ms |
50868 KB |
Output is correct |
55 |
Correct |
330 ms |
34948 KB |
Output is correct |
56 |
Correct |
499 ms |
63124 KB |
Output is correct |
57 |
Correct |
637 ms |
35692 KB |
Output is correct |
58 |
Correct |
873 ms |
36296 KB |
Output is correct |
59 |
Correct |
375 ms |
61812 KB |
Output is correct |