# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
835302 |
2023-08-23T12:05:58 Z |
Valaki2 |
Horses (IOI15_horses) |
C++14 |
|
524 ms |
60532 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define pii pair<int, int>
#define fi first
#define se second
const int mod = 1e9 + 7;
const int maxn = 5e5;
const int maxy = 1e9;
int add(int a, int b) {
return (a + b) % mod;
}
int subt(int a, int b) {
return (a - b + mod) % mod;
}
int mult(int a, int b) {
return (a * b) % mod;
}
int power(int a, int b) {
if(b == 0) {
return 1ll;
}
if(b % 2 == 0) {
int part = power(a, b / 2);
return mult(part, part);
} else {
return mult(a, power(a, b - 1));
}
}
int inv(int a) {
return power(a, mod - 2);
}
int divi(int a, int b) {
return mult(a, inv(b));
}
int n;
int x[1 + maxn], y[1 + maxn];
set<int> big/*s*/;
int tree[1 + maxn];
int segtree[1 + 4 * maxn];
void upd(int pos, int val) {
while(pos <= n) {
tree[pos] = mult(tree[pos], val);
pos += pos & (-pos);
}
}
int qry(int pos) {
int res = 1;
while(pos > 0) {
res = mult(res, tree[pos]);
pos -= pos & (-pos);
}
return res;
}
void upd_maxi(int v, int vl, int vr, int pos, int val) {
if(vl == vr) {
segtree[v] = val;
} else {
int mid = (vl + vr) / 2;
if(pos <= mid) {
upd_maxi(2 * v, vl, mid, pos, val);
} else {
upd_maxi(2 * v + 1, mid + 1, vr, pos, val);
}
segtree[v] = max(segtree[2 * v], segtree[2 * v + 1]);
}
}
int qry_maxi(int v, int vl, int vr, int ql, int qr) {
if(ql > vr || qr < vl) {
return 1;
}
if(ql == vl && qr == vr) {
return segtree[v];
}
int mid = (vl + vr) / 2;
return max(qry_maxi(2 * v, vl, mid, ql, min(qr, mid)),
qry_maxi(2 * v + 1, mid + 1, vr, max(ql, mid + 1), qr));
}
signed calc() {
int cur_factor = 1, all_factor = 1;
int prev = n + 1;
int ans = 0, best = 0;
for(auto it = big.rbegin(); it != big.rend(); it++) {
int cur = *it;
//for(int cur = n; cur >= 1; cur--) { //
int cur_best_y = qry_maxi(1, 1, n, cur, prev - 1);
if(cur_best_y > best * cur_factor) {
best = cur_best_y;
int cur_pref_x = qry(cur);
ans = mult(cur_pref_x, cur_best_y);
cur_factor = 1;
}
cur_factor *= x[cur];
all_factor *= x[cur];
if(all_factor > maxy) {
break;
}
prev = cur;
}
return (signed) ans;
}
signed init(signed N, signed X[], signed Y[]) {
n = N;
x[0] = y[0] = 1;
for(int i = 1; i <= n; i++) {
x[i] = X[i - 1];
y[i] = Y[i - 1];
}
tree[0] = 1;
for(int i = 1; i <= n; i++) {
tree[i] = 1;
}
for(int i = 1; i <= n; i++) {
upd(i, x[i]);
upd_maxi(1, 1, n, i, y[i]);
}
for(int i = 1; i <= n; i++) {
if(x[i] > 1) {
big.insert(i);
}
}
big.insert(1);
return calc();
}
signed updateX(signed pos, signed val) {
pos++;
int where = pos, newval = val;
upd(where, divi(newval, x[where]));
if(x[where] == 1 && newval > 1) {
big.insert(where);
}
if(x[where] > 1 && newval == 1) {
big.erase(where);
}
big.insert(1);
x[where] = newval;
return calc();
}
signed updateY(signed pos, signed val) {
pos++;
int where = pos, newval = val;
y[where] = newval;
upd_maxi(1, 1, n, where, newval);
return calc();
}
# |
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 |
212 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 |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
1 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 |
0 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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 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 |
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 |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
2 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 |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
493 ms |
48552 KB |
Output is correct |
2 |
Correct |
279 ms |
48524 KB |
Output is correct |
3 |
Correct |
283 ms |
48692 KB |
Output is correct |
4 |
Correct |
302 ms |
48564 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 |
212 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 |
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 |
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 |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 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 |
2 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
2 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 |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
384 KB |
Output is correct |
33 |
Correct |
96 ms |
24344 KB |
Output is correct |
34 |
Correct |
97 ms |
28296 KB |
Output is correct |
35 |
Correct |
220 ms |
58572 KB |
Output is correct |
36 |
Correct |
221 ms |
58564 KB |
Output is correct |
37 |
Correct |
140 ms |
26472 KB |
Output is correct |
38 |
Correct |
145 ms |
39172 KB |
Output is correct |
39 |
Correct |
101 ms |
26192 KB |
Output is correct |
40 |
Correct |
207 ms |
53540 KB |
Output is correct |
41 |
Correct |
102 ms |
26188 KB |
Output is correct |
42 |
Correct |
122 ms |
26392 KB |
Output is correct |
43 |
Correct |
209 ms |
53984 KB |
Output is correct |
44 |
Correct |
208 ms |
53964 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 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 |
1 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 |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 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 |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 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 |
3 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
2 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 |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
492 ms |
48588 KB |
Output is correct |
34 |
Correct |
283 ms |
48592 KB |
Output is correct |
35 |
Correct |
264 ms |
48572 KB |
Output is correct |
36 |
Correct |
323 ms |
48676 KB |
Output is correct |
37 |
Correct |
96 ms |
24332 KB |
Output is correct |
38 |
Correct |
112 ms |
28236 KB |
Output is correct |
39 |
Correct |
232 ms |
58724 KB |
Output is correct |
40 |
Correct |
222 ms |
58548 KB |
Output is correct |
41 |
Correct |
127 ms |
26400 KB |
Output is correct |
42 |
Correct |
154 ms |
39216 KB |
Output is correct |
43 |
Correct |
88 ms |
26124 KB |
Output is correct |
44 |
Correct |
191 ms |
53636 KB |
Output is correct |
45 |
Correct |
103 ms |
26304 KB |
Output is correct |
46 |
Correct |
131 ms |
26328 KB |
Output is correct |
47 |
Correct |
197 ms |
53952 KB |
Output is correct |
48 |
Correct |
208 ms |
53992 KB |
Output is correct |
49 |
Correct |
196 ms |
31320 KB |
Output is correct |
50 |
Correct |
173 ms |
31208 KB |
Output is correct |
51 |
Correct |
341 ms |
60532 KB |
Output is correct |
52 |
Correct |
272 ms |
59980 KB |
Output is correct |
53 |
Correct |
524 ms |
29612 KB |
Output is correct |
54 |
Correct |
293 ms |
43104 KB |
Output is correct |
55 |
Correct |
169 ms |
27200 KB |
Output is correct |
56 |
Correct |
280 ms |
55380 KB |
Output is correct |
57 |
Correct |
307 ms |
27828 KB |
Output is correct |
58 |
Correct |
467 ms |
28388 KB |
Output is correct |
59 |
Correct |
211 ms |
54008 KB |
Output is correct |