# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
823427 |
2023-08-12T14:00:25 Z |
_martynas |
Horses (IOI15_horses) |
C++11 |
|
399 ms |
49252 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#warning change mxn
const int mxn = 5e5+5;
const int mxval = 1e9;
const int mod = 1e9+7;
struct Seg {
int mx[4*mxn];
int get(int u, int l, int r, int ql, int qr) {
if(qr < l || r < ql) return 0;
if(ql <= l && r <= qr) return mx[u];
int m = (l+r)/2;
return max(get(2*u, l, m, ql, qr), get(2*u+1, m+1, r, ql, qr));
}
void set(int u, int l, int r, int i, int x) {
if(l == r) {
mx[u] = x; return;
}
int m = (l+r)/2;
if(i <= m) set(2*u, l, m, i, x);
else set(2*u+1, m+1, r, i, x);
mx[u] = max(mx[2*u], mx[2*u+1]);
}
} seg;
int n;
int x[mxn], y[mxn];
set<int> st;
ll tot = 1;
ll mod_pow(ll a, ll b) {
ll ans = 1;
while(b) {
if(b & 1) ans = ans*a%mod;
a = a*a%mod;
b >>= 1;
}
return ans;
}
int get();
int init(int N, int X[], int Y[]) {
n = N;
copy(X, X+n, x); copy(Y, Y+n, y);
for(int i = 0; i < N; i++) seg.set(1, 0, n-1, i, Y[i]);
st.insert(0);
st.insert(n);
for(int i = n-1; i >= 0; i--) {
if(X[i] > 1) {
tot = tot*X[i]%mod;
st.insert(i);
}
}
return get();
}
int get() {
ll acc = 1;
int last = -1;
auto rit = next(st.rbegin());
while(rit != st.rend()) {
acc *= x[*rit];
last = *rit;
if(acc > mxval) break;
rit = next(rit);
}
auto it = st.lower_bound(last);
ll mx = 0; acc = 1;
while(next(it) != st.end()) {
int i = *it;
int j = *next(it);
if(i != last) acc = acc*x[i];
ll best_y = seg.get(1, 0, n-1, i, j-1);
mx = max(mx, acc*best_y);
it = next(it);
}
//printf("mx = %lld\n", mx);
mx %= mod;
return tot*mod_pow(acc, mod-2)%mod*mx%mod;
}
int updateX(int pos, int val) {
tot = tot*mod_pow(x[pos], mod-2)%mod;
x[pos] = val;
tot = tot*val%mod;
if(val > 1 || pos == 0) st.insert(pos);
else (st.erase(pos));
return get();
}
int updateY(int pos, int val) {
seg.set(1, 0, n-1, pos, val);
return get();
}
// int main(int argc, char const *argv[])
// {
// int N;
// cin >> N;
// int X[N], Y[N];
// for(int i = 0; i < N; i++) cin >> X[i];
// for(int i = 0; i < N; i++) cin >> Y[i];
// cout << "init: " << init(N, X, Y) << "\n";
// int M;
// cin >> M;
// for(int i = 0; i < M; i++) {
// int type; cin >> type;
// int pos, val; cin >> pos >> val;
// if(type == 1) {
// cout << "resp: " << updateX(pos, val) << "\n";
// }
// else {
// cout << "resp: " << updateY(pos, val) << "\n";
// }
// }
// return 0;
// }
Compilation message
horses.cpp:8:2: warning: #warning change mxn [-Wcpp]
8 | #warning change mxn
| ^~~~~~~
horses.cpp: In function 'int get()':
horses.cpp:84:39: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
84 | return tot*mod_pow(acc, mod-2)%mod*mx%mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~
# |
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 |
1 ms |
304 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
308 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
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 |
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 |
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 |
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 |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 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 |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
308 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 |
320 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
396 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 |
420 KB |
Output is correct |
31 |
Correct |
2 ms |
324 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
399 ms |
36604 KB |
Output is correct |
2 |
Correct |
366 ms |
36688 KB |
Output is correct |
3 |
Correct |
330 ms |
36660 KB |
Output is correct |
4 |
Correct |
313 ms |
36636 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 |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
304 KB |
Output is correct |
8 |
Correct |
0 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 |
304 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 |
1 ms |
340 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 |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
2 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
312 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 |
71 ms |
16376 KB |
Output is correct |
34 |
Correct |
64 ms |
16392 KB |
Output is correct |
35 |
Correct |
179 ms |
46612 KB |
Output is correct |
36 |
Correct |
179 ms |
46756 KB |
Output is correct |
37 |
Correct |
87 ms |
14472 KB |
Output is correct |
38 |
Correct |
109 ms |
27220 KB |
Output is correct |
39 |
Correct |
57 ms |
14216 KB |
Output is correct |
40 |
Correct |
166 ms |
41676 KB |
Output is correct |
41 |
Correct |
69 ms |
14356 KB |
Output is correct |
42 |
Correct |
76 ms |
14312 KB |
Output is correct |
43 |
Correct |
156 ms |
42060 KB |
Output is correct |
44 |
Correct |
158 ms |
42092 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 |
308 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
308 KB |
Output is correct |
10 |
Correct |
0 ms |
312 KB |
Output is correct |
11 |
Correct |
0 ms |
212 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 |
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 |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
3 ms |
324 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 |
2 ms |
340 KB |
Output is correct |
32 |
Correct |
2 ms |
340 KB |
Output is correct |
33 |
Correct |
387 ms |
40500 KB |
Output is correct |
34 |
Correct |
280 ms |
49252 KB |
Output is correct |
35 |
Correct |
276 ms |
40436 KB |
Output is correct |
36 |
Correct |
354 ms |
44308 KB |
Output is correct |
37 |
Correct |
66 ms |
16348 KB |
Output is correct |
38 |
Correct |
65 ms |
16328 KB |
Output is correct |
39 |
Correct |
182 ms |
46692 KB |
Output is correct |
40 |
Correct |
180 ms |
46528 KB |
Output is correct |
41 |
Correct |
90 ms |
14468 KB |
Output is correct |
42 |
Correct |
108 ms |
27264 KB |
Output is correct |
43 |
Correct |
57 ms |
14308 KB |
Output is correct |
44 |
Correct |
164 ms |
41816 KB |
Output is correct |
45 |
Correct |
71 ms |
14312 KB |
Output is correct |
46 |
Correct |
76 ms |
14328 KB |
Output is correct |
47 |
Correct |
157 ms |
42060 KB |
Output is correct |
48 |
Correct |
161 ms |
42128 KB |
Output is correct |
49 |
Correct |
136 ms |
19368 KB |
Output is correct |
50 |
Correct |
131 ms |
19392 KB |
Output is correct |
51 |
Correct |
274 ms |
48548 KB |
Output is correct |
52 |
Correct |
238 ms |
48116 KB |
Output is correct |
53 |
Correct |
371 ms |
17676 KB |
Output is correct |
54 |
Correct |
222 ms |
31164 KB |
Output is correct |
55 |
Correct |
142 ms |
15364 KB |
Output is correct |
56 |
Correct |
236 ms |
43608 KB |
Output is correct |
57 |
Correct |
225 ms |
16000 KB |
Output is correct |
58 |
Correct |
310 ms |
16412 KB |
Output is correct |
59 |
Correct |
164 ms |
41996 KB |
Output is correct |