# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
16557 |
2015-08-27T16:20:25 Z |
gs14004 |
Horses (IOI15_horses) |
C++14 |
|
491 ms |
48808 KB |
#include "horses.h"
#include <algorithm>
#include <set>
using namespace std;
const int mod = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> pi;
struct rmq{
pi tree[1050000];
int lim;
void init(int n, int *a){
for(lim = 1; lim <= n; lim <<= 1);
for(int i=0; i<n; i++){
tree[i + lim] = pi(a[i], i);
}
for(int i=lim-1; i; i--){
tree[i] = max(tree[2*i], tree[2*i+1]);
}
}
void upd(int x, int v){
x += lim;
tree[x] = pi(v, x - lim);
while(x > 1){
x >>= 1;
tree[x] = max(tree[2*x], tree[2*x+1]);
}
}
pi q(int s, int e){
s += lim;
e += lim;
pi ret(0,0);
while(s < e){
if(s%2 == 1) ret = max(ret,tree[s++]);
if(e%2 == 0) ret = max(ret,tree[e--]);
s >>= 1;
e >>= 1;
}
if(s == e) ret = max(ret,tree[s]);
return ret;
}
}rmq;
struct gob{
lint tree[1050000], lim;
void init(int n, int *a){
for(lim = 1; lim <= n; lim <<= 1);
fill(tree, tree + 2 * lim + 1, 1);
for(int i=0; i<n; i++){
tree[i + lim] = a[i];
}
for(int i=lim-1; i; i--){
tree[i] = tree[2*i] * tree[2*i+1] % mod;
}
}
void upd(int x, int v){
x += lim;
tree[x] = v;
while(x > 1){
x >>= 1;
tree[x] = tree[2*x] * tree[2*x+1] % mod;
}
}
int q(int s, int e){
s += lim;
e += lim;
lint ret = 1;
while(s < e){
if(s%2 == 1) ret *= tree[s++], ret %= mod;
if(e%2 == 0) ret *= tree[e--], ret %= mod;
s >>= 1;
e >>= 1;
}
if(s == e) ret *= tree[s], ret %= mod;
return ret;
}
}gob;
int n, x[500005], y[500005];
set<int> s;
int solve(){
auto ite = --s.end();
auto its = --s.end();
its--;
lint ret = -1;
int retp = n;
for(int i=0; i<32 && ite != s.begin(); i++){
pi t = rmq.q(*its, *ite - 1);
if(ret < t.first){
retp = t.second;
ret = t.first;
}
ret *= x[*its];
if(ret > 2e9 || its == s.begin()) break;
its--;
ite--;
}
return 1ll * gob.q(0, retp) * y[retp] % mod;
}
int init(int N, int X[], int Y[]) {
n = N;
gob.init(N, X);
rmq.init(N, Y);
for(int i=0; i<N; i++){
x[i] = X[i], y[i] = Y[i];
if(X[i] != 1) s.insert(i);
}
s.insert(0);
s.insert(N);
return solve();
}
int updateX(int pos, int val) {
if(x[pos] != 1){
s.erase(pos);
s.insert(0);
}
x[pos] = val;
gob.upd(pos, val);
if(x[pos] != 1){
s.insert(pos);
}
return solve();
}
int updateY(int pos, int val) {
rmq.upd(pos, val);
y[pos] = val;
return solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
21532 KB |
Output is correct |
2 |
Correct |
0 ms |
21532 KB |
Output is correct |
3 |
Correct |
0 ms |
21532 KB |
Output is correct |
4 |
Correct |
0 ms |
21532 KB |
Output is correct |
5 |
Correct |
0 ms |
21532 KB |
Output is correct |
6 |
Correct |
0 ms |
21532 KB |
Output is correct |
7 |
Correct |
0 ms |
21532 KB |
Output is correct |
8 |
Correct |
0 ms |
21532 KB |
Output is correct |
9 |
Correct |
0 ms |
21532 KB |
Output is correct |
10 |
Correct |
0 ms |
21532 KB |
Output is correct |
11 |
Correct |
0 ms |
21532 KB |
Output is correct |
12 |
Correct |
0 ms |
21532 KB |
Output is correct |
13 |
Correct |
0 ms |
21532 KB |
Output is correct |
14 |
Correct |
0 ms |
21532 KB |
Output is correct |
15 |
Correct |
3 ms |
21532 KB |
Output is correct |
16 |
Correct |
0 ms |
21532 KB |
Output is correct |
17 |
Correct |
3 ms |
21532 KB |
Output is correct |
18 |
Correct |
0 ms |
21532 KB |
Output is correct |
19 |
Correct |
0 ms |
21532 KB |
Output is correct |
20 |
Correct |
0 ms |
21532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
21532 KB |
Output is correct |
2 |
Correct |
0 ms |
21532 KB |
Output is correct |
3 |
Correct |
3 ms |
21532 KB |
Output is correct |
4 |
Correct |
0 ms |
21532 KB |
Output is correct |
5 |
Correct |
0 ms |
21532 KB |
Output is correct |
6 |
Correct |
0 ms |
21532 KB |
Output is correct |
7 |
Correct |
0 ms |
21532 KB |
Output is correct |
8 |
Correct |
0 ms |
21532 KB |
Output is correct |
9 |
Correct |
0 ms |
21532 KB |
Output is correct |
10 |
Correct |
3 ms |
21532 KB |
Output is correct |
11 |
Correct |
0 ms |
21532 KB |
Output is correct |
12 |
Correct |
0 ms |
21532 KB |
Output is correct |
13 |
Correct |
0 ms |
21532 KB |
Output is correct |
14 |
Correct |
3 ms |
21532 KB |
Output is correct |
15 |
Correct |
0 ms |
21532 KB |
Output is correct |
16 |
Correct |
3 ms |
21532 KB |
Output is correct |
17 |
Correct |
0 ms |
21532 KB |
Output is correct |
18 |
Correct |
0 ms |
21532 KB |
Output is correct |
19 |
Correct |
3 ms |
21532 KB |
Output is correct |
20 |
Correct |
3 ms |
21532 KB |
Output is correct |
21 |
Correct |
0 ms |
21532 KB |
Output is correct |
22 |
Correct |
4 ms |
21532 KB |
Output is correct |
23 |
Correct |
0 ms |
21532 KB |
Output is correct |
24 |
Correct |
0 ms |
21532 KB |
Output is correct |
25 |
Correct |
2 ms |
21532 KB |
Output is correct |
26 |
Correct |
4 ms |
21532 KB |
Output is correct |
27 |
Correct |
0 ms |
21532 KB |
Output is correct |
28 |
Correct |
0 ms |
21532 KB |
Output is correct |
29 |
Correct |
0 ms |
21532 KB |
Output is correct |
30 |
Correct |
0 ms |
21532 KB |
Output is correct |
31 |
Correct |
4 ms |
21532 KB |
Output is correct |
32 |
Correct |
5 ms |
21532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
308 ms |
48808 KB |
Output is correct |
2 |
Correct |
476 ms |
48808 KB |
Output is correct |
3 |
Correct |
402 ms |
48808 KB |
Output is correct |
4 |
Correct |
491 ms |
48808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
21532 KB |
Output is correct |
2 |
Correct |
0 ms |
21532 KB |
Output is correct |
3 |
Correct |
0 ms |
21532 KB |
Output is correct |
4 |
Correct |
0 ms |
21532 KB |
Output is correct |
5 |
Correct |
4 ms |
21532 KB |
Output is correct |
6 |
Correct |
3 ms |
21532 KB |
Output is correct |
7 |
Correct |
0 ms |
21532 KB |
Output is correct |
8 |
Correct |
0 ms |
21532 KB |
Output is correct |
9 |
Correct |
3 ms |
21532 KB |
Output is correct |
10 |
Correct |
0 ms |
21532 KB |
Output is correct |
11 |
Correct |
0 ms |
21532 KB |
Output is correct |
12 |
Correct |
0 ms |
21532 KB |
Output is correct |
13 |
Correct |
0 ms |
21532 KB |
Output is correct |
14 |
Correct |
0 ms |
21532 KB |
Output is correct |
15 |
Correct |
0 ms |
21532 KB |
Output is correct |
16 |
Correct |
0 ms |
21532 KB |
Output is correct |
17 |
Correct |
3 ms |
21532 KB |
Output is correct |
18 |
Correct |
0 ms |
21532 KB |
Output is correct |
19 |
Correct |
4 ms |
21532 KB |
Output is correct |
20 |
Correct |
0 ms |
21532 KB |
Output is correct |
21 |
Correct |
0 ms |
21532 KB |
Output is correct |
22 |
Correct |
0 ms |
21532 KB |
Output is correct |
23 |
Correct |
0 ms |
21532 KB |
Output is correct |
24 |
Correct |
0 ms |
21532 KB |
Output is correct |
25 |
Correct |
4 ms |
21532 KB |
Output is correct |
26 |
Correct |
0 ms |
21532 KB |
Output is correct |
27 |
Correct |
0 ms |
21532 KB |
Output is correct |
28 |
Correct |
0 ms |
21532 KB |
Output is correct |
29 |
Correct |
5 ms |
21532 KB |
Output is correct |
30 |
Correct |
0 ms |
21532 KB |
Output is correct |
31 |
Correct |
0 ms |
21532 KB |
Output is correct |
32 |
Correct |
0 ms |
21532 KB |
Output is correct |
33 |
Correct |
47 ms |
25444 KB |
Output is correct |
34 |
Correct |
40 ms |
25444 KB |
Output is correct |
35 |
Correct |
283 ms |
48808 KB |
Output is correct |
36 |
Correct |
288 ms |
48808 KB |
Output is correct |
37 |
Correct |
33 ms |
25444 KB |
Output is correct |
38 |
Correct |
131 ms |
37324 KB |
Output is correct |
39 |
Correct |
24 ms |
25444 KB |
Output is correct |
40 |
Correct |
260 ms |
48808 KB |
Output is correct |
41 |
Correct |
19 ms |
25444 KB |
Output is correct |
42 |
Correct |
21 ms |
25444 KB |
Output is correct |
43 |
Correct |
252 ms |
48808 KB |
Output is correct |
44 |
Correct |
274 ms |
48808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
21532 KB |
Output is correct |
2 |
Correct |
0 ms |
21532 KB |
Output is correct |
3 |
Correct |
3 ms |
21532 KB |
Output is correct |
4 |
Correct |
3 ms |
21532 KB |
Output is correct |
5 |
Correct |
0 ms |
21532 KB |
Output is correct |
6 |
Correct |
3 ms |
21532 KB |
Output is correct |
7 |
Correct |
0 ms |
21532 KB |
Output is correct |
8 |
Correct |
0 ms |
21532 KB |
Output is correct |
9 |
Correct |
3 ms |
21532 KB |
Output is correct |
10 |
Correct |
0 ms |
21532 KB |
Output is correct |
11 |
Correct |
3 ms |
21532 KB |
Output is correct |
12 |
Correct |
0 ms |
21532 KB |
Output is correct |
13 |
Correct |
0 ms |
21532 KB |
Output is correct |
14 |
Correct |
0 ms |
21532 KB |
Output is correct |
15 |
Correct |
4 ms |
21532 KB |
Output is correct |
16 |
Correct |
3 ms |
21532 KB |
Output is correct |
17 |
Correct |
0 ms |
21532 KB |
Output is correct |
18 |
Correct |
0 ms |
21532 KB |
Output is correct |
19 |
Correct |
3 ms |
21532 KB |
Output is correct |
20 |
Correct |
3 ms |
21532 KB |
Output is correct |
21 |
Correct |
0 ms |
21532 KB |
Output is correct |
22 |
Correct |
0 ms |
21532 KB |
Output is correct |
23 |
Correct |
4 ms |
21532 KB |
Output is correct |
24 |
Correct |
0 ms |
21532 KB |
Output is correct |
25 |
Correct |
4 ms |
21532 KB |
Output is correct |
26 |
Correct |
5 ms |
21532 KB |
Output is correct |
27 |
Correct |
3 ms |
21532 KB |
Output is correct |
28 |
Correct |
2 ms |
21532 KB |
Output is correct |
29 |
Correct |
0 ms |
21532 KB |
Output is correct |
30 |
Correct |
0 ms |
21532 KB |
Output is correct |
31 |
Correct |
0 ms |
21532 KB |
Output is correct |
32 |
Correct |
5 ms |
21532 KB |
Output is correct |
33 |
Correct |
347 ms |
48808 KB |
Output is correct |
34 |
Correct |
383 ms |
48808 KB |
Output is correct |
35 |
Correct |
404 ms |
48808 KB |
Output is correct |
36 |
Correct |
464 ms |
48808 KB |
Output is correct |
37 |
Correct |
35 ms |
25444 KB |
Output is correct |
38 |
Correct |
42 ms |
25444 KB |
Output is correct |
39 |
Correct |
330 ms |
48808 KB |
Output is correct |
40 |
Correct |
283 ms |
48808 KB |
Output is correct |
41 |
Correct |
41 ms |
25444 KB |
Output is correct |
42 |
Correct |
123 ms |
37324 KB |
Output is correct |
43 |
Correct |
30 ms |
25444 KB |
Output is correct |
44 |
Correct |
242 ms |
48808 KB |
Output is correct |
45 |
Correct |
40 ms |
25444 KB |
Output is correct |
46 |
Correct |
36 ms |
25444 KB |
Output is correct |
47 |
Correct |
289 ms |
48808 KB |
Output is correct |
48 |
Correct |
263 ms |
48808 KB |
Output is correct |
49 |
Correct |
107 ms |
26500 KB |
Output is correct |
50 |
Correct |
106 ms |
26500 KB |
Output is correct |
51 |
Correct |
338 ms |
48808 KB |
Output is correct |
52 |
Correct |
311 ms |
48808 KB |
Output is correct |
53 |
Correct |
206 ms |
26500 KB |
Output is correct |
54 |
Correct |
214 ms |
39436 KB |
Output is correct |
55 |
Correct |
88 ms |
25444 KB |
Output is correct |
56 |
Correct |
392 ms |
48808 KB |
Output is correct |
57 |
Correct |
101 ms |
25444 KB |
Output is correct |
58 |
Correct |
151 ms |
25444 KB |
Output is correct |
59 |
Correct |
249 ms |
48808 KB |
Output is correct |