# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
288249 |
2020-09-01T10:51:25 Z |
DystoriaX |
Horses (IOI15_horses) |
C++14 |
|
1500 ms |
38776 KB |
#include "horses.h"
#include <algorithm>
#include <vector>
#include <iostream>
#include <assert.h>
#define lc (i << 1)
#define rc (1 | (i << 1))
using namespace std;
const int MOD = 1e9 + 7;
int add(long long a, long long b){
return (a + b) % MOD;
}
int mul(long long a, long long b){
return (a * b) % MOD;
}
struct Node{
int val, mx;
Node(){
val = mx = 0;
}
};
Node st[4 * 500010];
long long bit[500010];
int n;
vector<int> x, y;
const int MAX = 1e9;
void updateBIT(int x, int val){
for(; x <= n; x += x & (-x)) bit[x] += val;
}
long long qs(int x){
long long ret = 0;
for(; x; x -= x & (-x)) ret += bit[x];
return ret;
}
long long qs(int l, int r){
if(r < l) return 0;
return qs(r) - qs(l - 1);
}
void update(int l, int r, int pt, int val, int type, int i){
if(r < pt || pt < l) return;
if(l == r && l == pt){
if(type == 0) st[i].val = val;
else st[i].mx = val;
return;
}
int m = (l + r) >> 1;
update(l, m, pt, val, type, lc);
update(m + 1, r, pt, val, type, rc);
st[i].val = mul(st[lc].val, st[rc].val);
st[i].mx = max(st[lc].mx, st[rc].mx);
}
int query(int l, int r, int ls, int rs, int i){
if(r < ls || rs < l) return 1;
if(ls <= l && r <= rs) return st[i].val;
int m = (l + r) >> 1;
return mul(query(l, m, ls, rs, lc), query(m + 1, r, ls, rs, rc));
}
long long queryMax(int l, int r, int ls, int rs, int i){
if(r < ls || rs < l) return 0;
if(ls <= l && r <= rs) return st[i].mx;
int m = (l + r) >> 1;
return max(queryMax(l, m, ls, rs, lc), queryMax(m + 1, r, ls, rs, rc));
}
int GetPrev(int idx){
int l = 0, r = idx;
while(l <= r){
int m = (l + r) >> 1;
// We find at interval [m, idx - 1], the sum should be equal to idx - m
if(qs(m + 1, idx) == idx - m) r = m - 1;
else l = m + 1;
}
return l;
}
int GetValue(){
int idx = 0;
long long pr = 1;
vector<int> path;
path.emplace_back(n);
for(idx = n - 1; idx >= 0; idx = GetPrev(idx) - 1){
pr *= x[idx];
if(pr > MAX) break;
if(x[idx] != 1) path.emplace_back(idx);
}
idx = max(idx, 0);
pr = 1;
int optVal = 0, opt = 0;
int counter = 0;
while(true){
counter++;
assert(counter < 100);
int nxt = path.back() - 1; path.pop_back();
pr *= x[idx];
int yval = queryMax(0, n - 1, idx, nxt, 1);
if(optVal < pr * yval){
opt = idx;
optVal = yval;
pr = 1;
}
idx = nxt + 1;
if(idx == n) break;
}
return mul(query(0, n - 1, 0, opt, 1), optVal);
}
int init(int N, int X[], int Y[]) {
n = N;
x.insert(x.begin(), X, X + N);
y.insert(y.begin(), Y, Y + N);
for(int i = 0; i < n; i++) update(0, n - 1, i, x[i], 0, 1), updateBIT(i + 1, x[i]);
for(int i = 0; i < n; i++) update(0, n - 1, i, y[i], 1, 1);
// for(int i = 0; i < n; i++){
// cerr << i << " with previous: " << GetPrev(i) << "\n";
// }
return GetValue();
}
int updateX(int pos, int val) {
updateBIT(pos + 1, -x[pos]);
x[pos] = val;
updateBIT(pos + 1, val);
update(0, n - 1, pos, val, 0, 1);
return GetValue();
}
int updateY(int pos, int val) {
y[pos] = val;
update(0, n - 1, pos, val, 1, 1);
return GetValue();
}
Compilation message
horses.cpp: In function 'int add(long long int, long long int)':
horses.cpp:15:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
15 | return (a + b) % MOD;
| ~~~~~~~~^~~~~
horses.cpp: In function 'int mul(long long int, long long int)':
horses.cpp:19:17: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
19 | return (a * b) % MOD;
| ~~~~~~~~^~~~~
horses.cpp: In function 'void updateBIT(int, int)':
horses.cpp:37:30: warning: declaration of 'x' shadows a global declaration [-Wshadow]
37 | void updateBIT(int x, int val){
| ^
horses.cpp:34:13: note: shadowed declaration is here
34 | vector<int> x, y;
| ^
horses.cpp: In function 'long long int qs(int)':
horses.cpp:41:19: warning: declaration of 'x' shadows a global declaration [-Wshadow]
41 | long long qs(int x){
| ^
horses.cpp:34:13: note: shadowed declaration is here
34 | vector<int> x, y;
| ^
horses.cpp: In function 'int GetValue()':
horses.cpp:133:22: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
133 | int yval = queryMax(0, n - 1, idx, nxt, 1);
| ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
16000 KB |
Output is correct |
2 |
Correct |
13 ms |
16000 KB |
Output is correct |
3 |
Correct |
10 ms |
16000 KB |
Output is correct |
4 |
Correct |
10 ms |
16000 KB |
Output is correct |
5 |
Correct |
11 ms |
16000 KB |
Output is correct |
6 |
Correct |
10 ms |
16000 KB |
Output is correct |
7 |
Correct |
10 ms |
16000 KB |
Output is correct |
8 |
Correct |
10 ms |
16000 KB |
Output is correct |
9 |
Correct |
10 ms |
16000 KB |
Output is correct |
10 |
Correct |
10 ms |
16000 KB |
Output is correct |
11 |
Correct |
10 ms |
16000 KB |
Output is correct |
12 |
Correct |
10 ms |
16000 KB |
Output is correct |
13 |
Correct |
10 ms |
16000 KB |
Output is correct |
14 |
Correct |
13 ms |
16000 KB |
Output is correct |
15 |
Correct |
10 ms |
16000 KB |
Output is correct |
16 |
Correct |
11 ms |
16000 KB |
Output is correct |
17 |
Correct |
10 ms |
16000 KB |
Output is correct |
18 |
Correct |
10 ms |
16032 KB |
Output is correct |
19 |
Correct |
10 ms |
16000 KB |
Output is correct |
20 |
Correct |
10 ms |
16000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
16000 KB |
Output is correct |
2 |
Correct |
10 ms |
16000 KB |
Output is correct |
3 |
Correct |
10 ms |
16000 KB |
Output is correct |
4 |
Correct |
10 ms |
16000 KB |
Output is correct |
5 |
Correct |
10 ms |
16000 KB |
Output is correct |
6 |
Correct |
10 ms |
16000 KB |
Output is correct |
7 |
Correct |
10 ms |
16000 KB |
Output is correct |
8 |
Correct |
10 ms |
16000 KB |
Output is correct |
9 |
Correct |
11 ms |
16128 KB |
Output is correct |
10 |
Correct |
10 ms |
16000 KB |
Output is correct |
11 |
Correct |
10 ms |
16036 KB |
Output is correct |
12 |
Correct |
10 ms |
15924 KB |
Output is correct |
13 |
Correct |
10 ms |
16000 KB |
Output is correct |
14 |
Correct |
10 ms |
16000 KB |
Output is correct |
15 |
Correct |
10 ms |
16000 KB |
Output is correct |
16 |
Correct |
10 ms |
16000 KB |
Output is correct |
17 |
Correct |
10 ms |
16000 KB |
Output is correct |
18 |
Correct |
10 ms |
16000 KB |
Output is correct |
19 |
Correct |
10 ms |
16000 KB |
Output is correct |
20 |
Correct |
10 ms |
16000 KB |
Output is correct |
21 |
Correct |
11 ms |
16000 KB |
Output is correct |
22 |
Correct |
10 ms |
16000 KB |
Output is correct |
23 |
Correct |
12 ms |
16000 KB |
Output is correct |
24 |
Correct |
11 ms |
16000 KB |
Output is correct |
25 |
Correct |
13 ms |
16000 KB |
Output is correct |
26 |
Correct |
12 ms |
16000 KB |
Output is correct |
27 |
Correct |
20 ms |
16000 KB |
Output is correct |
28 |
Correct |
14 ms |
16000 KB |
Output is correct |
29 |
Correct |
12 ms |
16000 KB |
Output is correct |
30 |
Correct |
12 ms |
16000 KB |
Output is correct |
31 |
Correct |
17 ms |
16000 KB |
Output is correct |
32 |
Correct |
20 ms |
16000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1579 ms |
31792 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
16000 KB |
Output is correct |
2 |
Correct |
10 ms |
16000 KB |
Output is correct |
3 |
Correct |
11 ms |
16000 KB |
Output is correct |
4 |
Correct |
10 ms |
16000 KB |
Output is correct |
5 |
Correct |
10 ms |
16128 KB |
Output is correct |
6 |
Correct |
10 ms |
16000 KB |
Output is correct |
7 |
Correct |
10 ms |
16000 KB |
Output is correct |
8 |
Correct |
10 ms |
16000 KB |
Output is correct |
9 |
Correct |
10 ms |
16000 KB |
Output is correct |
10 |
Correct |
10 ms |
16000 KB |
Output is correct |
11 |
Correct |
11 ms |
16000 KB |
Output is correct |
12 |
Correct |
10 ms |
16000 KB |
Output is correct |
13 |
Correct |
10 ms |
16000 KB |
Output is correct |
14 |
Correct |
10 ms |
16000 KB |
Output is correct |
15 |
Correct |
10 ms |
16000 KB |
Output is correct |
16 |
Correct |
10 ms |
16000 KB |
Output is correct |
17 |
Correct |
10 ms |
16000 KB |
Output is correct |
18 |
Correct |
10 ms |
16000 KB |
Output is correct |
19 |
Correct |
10 ms |
16000 KB |
Output is correct |
20 |
Correct |
10 ms |
16000 KB |
Output is correct |
21 |
Correct |
11 ms |
16000 KB |
Output is correct |
22 |
Correct |
10 ms |
16000 KB |
Output is correct |
23 |
Correct |
12 ms |
16000 KB |
Output is correct |
24 |
Correct |
12 ms |
16000 KB |
Output is correct |
25 |
Correct |
13 ms |
16000 KB |
Output is correct |
26 |
Correct |
11 ms |
16000 KB |
Output is correct |
27 |
Correct |
20 ms |
16000 KB |
Output is correct |
28 |
Correct |
14 ms |
16000 KB |
Output is correct |
29 |
Correct |
12 ms |
16000 KB |
Output is correct |
30 |
Correct |
12 ms |
16000 KB |
Output is correct |
31 |
Correct |
19 ms |
16000 KB |
Output is correct |
32 |
Correct |
20 ms |
16032 KB |
Output is correct |
33 |
Correct |
388 ms |
31720 KB |
Output is correct |
34 |
Correct |
363 ms |
31736 KB |
Output is correct |
35 |
Correct |
434 ms |
38776 KB |
Output is correct |
36 |
Correct |
390 ms |
38648 KB |
Output is correct |
37 |
Correct |
635 ms |
29944 KB |
Output is correct |
38 |
Correct |
436 ms |
30888 KB |
Output is correct |
39 |
Correct |
378 ms |
29816 KB |
Output is correct |
40 |
Correct |
381 ms |
33784 KB |
Output is correct |
41 |
Correct |
482 ms |
29816 KB |
Output is correct |
42 |
Correct |
560 ms |
29944 KB |
Output is correct |
43 |
Correct |
361 ms |
34148 KB |
Output is correct |
44 |
Correct |
358 ms |
34168 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
16000 KB |
Output is correct |
2 |
Correct |
9 ms |
16000 KB |
Output is correct |
3 |
Correct |
10 ms |
16000 KB |
Output is correct |
4 |
Correct |
10 ms |
16000 KB |
Output is correct |
5 |
Correct |
10 ms |
16000 KB |
Output is correct |
6 |
Correct |
10 ms |
16000 KB |
Output is correct |
7 |
Correct |
11 ms |
16000 KB |
Output is correct |
8 |
Correct |
10 ms |
16000 KB |
Output is correct |
9 |
Correct |
10 ms |
16000 KB |
Output is correct |
10 |
Correct |
11 ms |
15952 KB |
Output is correct |
11 |
Correct |
10 ms |
16000 KB |
Output is correct |
12 |
Correct |
10 ms |
16000 KB |
Output is correct |
13 |
Correct |
10 ms |
16000 KB |
Output is correct |
14 |
Correct |
10 ms |
16000 KB |
Output is correct |
15 |
Correct |
11 ms |
16000 KB |
Output is correct |
16 |
Correct |
10 ms |
16000 KB |
Output is correct |
17 |
Correct |
12 ms |
16000 KB |
Output is correct |
18 |
Correct |
10 ms |
16000 KB |
Output is correct |
19 |
Correct |
12 ms |
16000 KB |
Output is correct |
20 |
Correct |
10 ms |
16000 KB |
Output is correct |
21 |
Correct |
10 ms |
16000 KB |
Output is correct |
22 |
Correct |
10 ms |
16000 KB |
Output is correct |
23 |
Correct |
11 ms |
16000 KB |
Output is correct |
24 |
Correct |
11 ms |
16000 KB |
Output is correct |
25 |
Correct |
13 ms |
16000 KB |
Output is correct |
26 |
Correct |
11 ms |
16000 KB |
Output is correct |
27 |
Correct |
20 ms |
16000 KB |
Output is correct |
28 |
Correct |
14 ms |
16036 KB |
Output is correct |
29 |
Correct |
13 ms |
16000 KB |
Output is correct |
30 |
Correct |
12 ms |
16000 KB |
Output is correct |
31 |
Correct |
17 ms |
16000 KB |
Output is correct |
32 |
Correct |
21 ms |
16000 KB |
Output is correct |
33 |
Execution timed out |
1569 ms |
31588 KB |
Time limit exceeded |
34 |
Halted |
0 ms |
0 KB |
- |