# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
599167 |
2022-07-19T11:13:43 Z |
Temmie |
Horses (IOI15_horses) |
C++17 |
|
191 ms |
59088 KB |
#include <bits/stdc++.h>
constexpr const int mod = 1e9 + 7;
int n;
std::vector <int> gr, pr;
struct Seg {
struct Item {
long long ans = 0;
long long ans_mod = 0;
long long suf = 0, sum = 0, sum_mod = 0;
int ind = 0;
};
int size;
std::vector <Item> v;
Seg(int s) {
size = 1;
while (size < s) {
size <<= 1;
}
v.resize(size << 1);
}
Item merge(Item l, Item r) {
Item res;
res.sum = std::min((long long) mod - 5, l.sum * r.sum);
res.sum_mod = l.sum_mod * r.sum_mod % mod;
if (pr[l.ind] > l.suf * r.ans){
res.ans = l.ans;
res.ans_mod = l.ans_mod;
res.suf = std::min((long long) mod - 5, l.suf * r.sum);
res.ind = l.ind;
return res;
} else {
res.ans = std::min((long long) mod - 5, l.sum * r.ans);
res.ans_mod = l.sum_mod * r.ans_mod % mod;
res.suf = r.suf;
res.ind = r.ind;
}
return res;
}
void make() {
make(0, 0, n);
}
void make(int now, int l, int r){
if (!(r - l - 1)) {
v[now].ans = std::min((long long) mod - 5, (long long) gr[l] * pr[l]);
v[now].ans_mod = (long long) gr[l] * pr[l] % mod;
v[now].suf = 1;
v[now].sum = v[now].sum_mod = gr[l];
v[now].ind = l;
return;
}
int mid = (l + r) >> 1;
make(now * 2 + 1, l, mid);
make(now * 2 + 2, mid, r);
v[now] = merge(v[now * 2 + 1], v[now * 2 + 2]);
}
void update(int ind, long long val, bool which) {
update(ind, val, which, 0, 0, n);
}
void update(int ind, long long val, bool which, int now, int l, int r) {
if (!(r - l - 1)) {
if (which) {
gr[l] = val;
} else {
pr[l] = val;
}
v[now].ans = std::min((long long) mod - 5, (long long) gr[l] * pr[l]);
v[now].ans_mod = (long long) gr[l] * pr[l] % mod;
v[now].suf = 1;
v[now].sum = v[now].sum_mod = gr[l];
v[now].ind = l;
return;
}
int mid = (l + r) >> 1;
if (ind < mid) {
update(ind, val, which, now * 2 + 1, l, mid);
} else {
update(ind, val, which, now * 2 + 2, mid, r);
}
v[now] = merge(v[now * 2 + 1], v[now * 2 + 2]);
}
};
Seg seg(0);
int init(int _n, int _gr[], int _pr[]) {
n = _n;
gr.resize(n);
pr.resize(n);
for (int i = 0; i < n; i++) {
gr[i] = _gr[i];
pr[i] = _pr[i];
}
seg = Seg(n);
seg.make();
return seg.v[0].ans_mod;
}
// gr
int updateX(int pos, int val) {
seg.update(pos, val, true);
return seg.v[0].ans_mod;
}
// pr
int updateY(int pos, int val) {
seg.update(pos, val, false);
return seg.v[0].ans_mod;
}
Compilation message
horses.cpp: In member function 'void Seg::update(int, long long int, bool, int, int, int)':
horses.cpp:75:13: warning: conversion from 'long long int' to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
75 | gr[l] = val;
| ^~~
horses.cpp:77:13: warning: conversion from 'long long int' to '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} may change value [-Wconversion]
77 | pr[l] = val;
| ^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:109:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
109 | return seg.v[0].ans_mod;
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:115:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
115 | return seg.v[0].ans_mod;
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:121:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
121 | return seg.v[0].ans_mod;
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
296 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
300 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
296 KB |
Output is correct |
14 |
Correct |
0 ms |
296 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
300 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
300 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
300 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
296 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
440 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
304 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
84 ms |
58824 KB |
Output is correct |
2 |
Correct |
187 ms |
58572 KB |
Output is correct |
3 |
Correct |
129 ms |
58572 KB |
Output is correct |
4 |
Correct |
180 ms |
58560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
304 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
300 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
324 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
308 KB |
Output is correct |
30 |
Correct |
1 ms |
428 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
59 ms |
57636 KB |
Output is correct |
34 |
Correct |
69 ms |
57644 KB |
Output is correct |
35 |
Correct |
76 ms |
58020 KB |
Output is correct |
36 |
Correct |
73 ms |
58020 KB |
Output is correct |
37 |
Correct |
48 ms |
57728 KB |
Output is correct |
38 |
Correct |
48 ms |
57632 KB |
Output is correct |
39 |
Correct |
44 ms |
57624 KB |
Output is correct |
40 |
Correct |
55 ms |
58040 KB |
Output is correct |
41 |
Correct |
42 ms |
57628 KB |
Output is correct |
42 |
Correct |
52 ms |
57676 KB |
Output is correct |
43 |
Correct |
54 ms |
58000 KB |
Output is correct |
44 |
Correct |
56 ms |
57992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
300 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
300 KB |
Output is correct |
11 |
Correct |
1 ms |
300 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
440 KB |
Output is correct |
25 |
Correct |
2 ms |
444 KB |
Output is correct |
26 |
Correct |
1 ms |
436 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
312 KB |
Output is correct |
33 |
Correct |
84 ms |
58640 KB |
Output is correct |
34 |
Correct |
191 ms |
59016 KB |
Output is correct |
35 |
Correct |
131 ms |
58956 KB |
Output is correct |
36 |
Correct |
151 ms |
59008 KB |
Output is correct |
37 |
Correct |
62 ms |
58112 KB |
Output is correct |
38 |
Correct |
62 ms |
58068 KB |
Output is correct |
39 |
Correct |
72 ms |
58096 KB |
Output is correct |
40 |
Correct |
72 ms |
58100 KB |
Output is correct |
41 |
Correct |
48 ms |
58020 KB |
Output is correct |
42 |
Correct |
51 ms |
58008 KB |
Output is correct |
43 |
Correct |
45 ms |
57988 KB |
Output is correct |
44 |
Correct |
60 ms |
58108 KB |
Output is correct |
45 |
Correct |
47 ms |
58104 KB |
Output is correct |
46 |
Correct |
43 ms |
58040 KB |
Output is correct |
47 |
Correct |
58 ms |
57968 KB |
Output is correct |
48 |
Correct |
67 ms |
58112 KB |
Output is correct |
49 |
Correct |
172 ms |
58924 KB |
Output is correct |
50 |
Correct |
137 ms |
58956 KB |
Output is correct |
51 |
Correct |
123 ms |
58992 KB |
Output is correct |
52 |
Correct |
125 ms |
58936 KB |
Output is correct |
53 |
Correct |
132 ms |
59012 KB |
Output is correct |
54 |
Correct |
89 ms |
58884 KB |
Output is correct |
55 |
Correct |
87 ms |
58136 KB |
Output is correct |
56 |
Correct |
93 ms |
58956 KB |
Output is correct |
57 |
Correct |
77 ms |
58912 KB |
Output is correct |
58 |
Correct |
85 ms |
59088 KB |
Output is correct |
59 |
Correct |
64 ms |
58120 KB |
Output is correct |