# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
795429 |
2023-07-27T09:32:21 Z |
Josia |
Horses (IOI15_horses) |
C++17 |
|
823 ms |
84128 KB |
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int long long
constexpr ll mod = 1e9+7;
struct seg {
// vector<int> tree;
array<signed, 2000000> tree;
void init(int n) {
// tree.assign(n*4, 0);
}
void update(int v, int rl, int rr, int pos, int x) {
if (rl == rr) {
tree[v] = x;
return;
}
int rm = (rl + rr)/2;
if (pos <= rm) update(v*2, rl, rm, pos, x);
else update(v*2+1, rm+1, rr, pos, x);
tree[v] = max(tree[v*2], tree[v*2+1]);
}
int query(int v, int rl, int rr, int ql, int qr) {
if (ql > qr) return 0;
if (rl == ql && rr == qr) return tree[v];
int rm = (rl + rr)/2;
return max(query(v*2, rl, rm, ql, min(qr, rm)), query(v*2+1, rm+1, rr, max(ql, rm+1), qr));
}
};
struct segY {
vector<pair<int, int>> tree;
void init(int n) {
tree.assign(n*4, {0, 0});
}
void update(int v, int rl, int rr, int pos, int x) {
if (rl == rr) {
tree[v] = {x, pos};
return;
}
int rm = (rl + rr)/2;
if (pos <= rm) update(v*2, rl, rm, pos, x);
else update(v*2+1, rm+1, rr, pos, x);
tree[v] = max(tree[v*2], tree[v*2+1]);
}
pair<int, int> query(int v, int rl, int rr, int ql, int qr) {
if (ql > qr) return {0, -1};
if (rl == ql && rr == qr) return tree[v];
int rm = (rl + rr)/2;
return max(query(v*2, rl, rm, ql, min(qr, rm)), query(v*2+1, rm+1, rr, max(ql, rm+1), qr));
}
};
ll mult(ll a, ll b) {
int res = a*b;
if (res >= mod) res%=mod;
return res;
}
struct seg2 {
vector<ll> tree;
void init(int n) {
tree.assign(n*4, 0);
}
void update(int v, int rl, int rr, int pos, int x) {
if (rl == rr) {
tree[v] = x;
return;
}
int rm = (rl + rr)/2;
if (pos <= rm) update(v*2, rl, rm, pos, x);
else update(v*2+1, rm+1, rr, pos, x);
tree[v] = mult(tree[v*2], tree[v*2+1]);
}
ll query(int v, int rl, int rr, int ql, int qr) {
if (ql > qr) return 1;
if (rl == ql && rr == qr) return tree[v];
int rm = (rl + rr)/2;
return mult(query(v*2, rl, rm, ql, min(qr, rm)), query(v*2+1, rm+1, rr, max(ql, rm+1), qr));
}
};
struct rightestNonZero {
// vector<int> tree;
array<signed, 2000000> tree;
void init(int n) {
// tree.assign(n*4, 0);
}
void update(int v, int rl, int rr, int pos, int x) {
if (rl == rr) {
tree[v] = x?pos:-1;
return;
}
int rm = (rl + rr)/2;
if (pos <= rm) update(v*2, rl, rm, pos, x);
else update(v*2+1, rm+1, rr, pos, x);
tree[v] = max(tree[v*2], tree[v*2+1]);
}
int query(int v, int rl, int rr, int ql, int qr) {
if (ql > qr) return 0;
if (rl == ql && rr == qr) return tree[v];
int rm = (rl + rr)/2;
return max(query(v*2, rl, rm, ql, min(qr, rm)), query(v*2+1, rm+1, rr, max(ql, rm+1), qr));
}
};
struct leftestNonZero {
// vector<int> tree;
array<signed, 2000000> tree;
void init(int n) {
// tree.assign(n*4, 0);
}
void update(int v, int rl, int rr, int pos, int x) {
if (rl == rr) {
tree[v] = x?pos:1e9;
return;
}
int rm = (rl + rr)/2;
if (pos <= rm) update(v*2, rl, rm, pos, x);
else update(v*2+1, rm+1, rr, pos, x);
tree[v] = min(tree[v*2], tree[v*2+1]);
}
int query(int v, int rl, int rr, int ql, int qr) {
if (ql > qr) return 0;
if (rl == ql && rr == qr) return tree[v];
int rm = (rl + rr)/2;
return min(query(v*2, rl, rm, ql, min(qr, rm)), query(v*2+1, rm+1, rr, max(ql, rm+1), qr));
}
};
seg tree;
segY treeY;
seg2 tree2;
leftestNonZero lnz;
rightestNonZero rnz;
int N;
vector<ll> X, Y;
struct getSol {
int sol = 0;
int BS(int pos) {
if (pos == 0) return -1;
int res = rnz.query(1, 0, N-1, 0, pos-1);
if (res==-1) return 0;
return res;
int l = 0, r = pos-1;
while (l<r) {
int m = (l+r+1)/2;
if (tree.query(1, 0, N-1, m, pos-1) > 1) {
l = m;
} else {
r = m-1;
}
}
return l;
}
int BSinv(int pos) {
if (pos == N-1) return N-1;
int res = lnz.query(1, 0, N-1, pos+1, N-1);
return res;
int l = pos+1, r = N-1;
while (l<r) {
int m = (l+r+1)/2;
if (tree.query(1, 0, N-1, pos+1, m) > 1) {
r = m-1;
} else {
l = m;
}
}
return l;
}
int findInd() {
int currInd = N-1;
ll currProd = 1;
for (int i = N-1; i>=0; i = BS(i)) {
auto bestSell = treeY.query(1, 0, N-1, i, N-1);
if (currProd*Y[currInd] <= bestSell.first) {currInd = bestSell.second; currProd=1;}
currProd *= X[i];
if (currProd*Y[currInd] > 1e9) break;
}
return currInd;
}
getSol() {
int ind = findInd();
sol = (tree2.query(1, 0, N-1, 0, ind) * Y[ind])%mod;
}
};
signed init(signed _N, signed _X[], signed _Y[]) {
N = _N;
X.resize(N);
Y.resize(N);
for (int i = 0; i<N; i++) X[i] = _X[i];
for (int i = 0; i<N; i++) Y[i] = _Y[i];
tree.init(N);
treeY.init(N);
tree2.init(N);
for (int i = 0; i<N; i++) {
lnz.update(1, 0, N-1, i, X[i]>1);
rnz.update(1, 0, N-1, i, X[i]>1);
tree.update(1, 0, N-1, i, X[i]);
treeY.update(1, 0, N-1, i, Y[i]);
tree2.update(1, 0, N-1, i, X[i]);
}
return getSol().sol;
}
signed updateX(signed pos, signed val) {
tree.update(1, 0, N-1, pos, val);
tree2.update(1, 0, N-1, pos, val);
lnz.update(1, 0, N-1, pos, val>1);
rnz.update(1, 0, N-1, pos, val>1);
X[pos] = val;
return getSol().sol;
}
signed updateY(signed pos, signed val) {
treeY.update(1, 0, N-1, pos, val);
Y[pos] = val;
return getSol().sol;
}
Compilation message
horses.cpp: In member function 'void seg::init(long long int)':
horses.cpp:15:16: warning: unused parameter 'n' [-Wunused-parameter]
15 | void init(int n) {
| ^
horses.cpp: In member function 'void seg::update(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:21:14: warning: conversion from 'long long int' to 'std::array<int, 2000000>::value_type' {aka 'int'} may change value [-Wconversion]
21 | tree[v] = x;
| ^
horses.cpp: In member function 'void rightestNonZero::init(long long int)':
horses.cpp:120:16: warning: unused parameter 'n' [-Wunused-parameter]
120 | void init(int n) {
| ^
horses.cpp: In member function 'void rightestNonZero::update(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:126:15: warning: conversion from 'long long int' to 'std::array<int, 2000000>::value_type' {aka 'int'} may change value [-Wconversion]
126 | tree[v] = x?pos:-1;
| ~^~~~~~~
horses.cpp: In member function 'void leftestNonZero::init(long long int)':
horses.cpp:153:16: warning: unused parameter 'n' [-Wunused-parameter]
153 | void init(int n) {
| ^
horses.cpp: In member function 'void leftestNonZero::update(long long int, long long int, long long int, long long int, long long int)':
horses.cpp:159:16: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
159 | tree[v] = x?pos:1e9;
| ^~~
horses.cpp:159:15: warning: conversion from 'double' to 'std::array<int, 2000000>::value_type' {aka 'int'} may change value [-Wfloat-conversion]
159 | tree[v] = x?pos:1e9;
| ~^~~~~~~~
horses.cpp: In member function 'long long int getSol::findInd()':
horses.cpp:246:16: warning: conversion from 'long long int' to 'double' may change value [-Wconversion]
246 | if (currProd*Y[currInd] > 1e9) break;
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:280:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
280 | return getSol().sol;
| ~~~~~~~~~^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:292:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
292 | return getSol().sol;
| ~~~~~~~~~^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:299:18: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
299 | return getSol().sol;
| ~~~~~~~~~^~~
# |
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 |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
320 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 |
320 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
224 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 |
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 |
1 ms |
360 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 |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
320 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 |
320 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 |
324 KB |
Output is correct |
11 |
Correct |
1 ms |
316 KB |
Output is correct |
12 |
Correct |
0 ms |
320 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 |
1 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 |
1 ms |
316 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
316 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
456 KB |
Output is correct |
25 |
Correct |
2 ms |
460 KB |
Output is correct |
26 |
Correct |
1 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
480 KB |
Output is correct |
30 |
Correct |
2 ms |
468 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
636 ms |
72228 KB |
Output is correct |
2 |
Correct |
372 ms |
72548 KB |
Output is correct |
3 |
Correct |
414 ms |
72688 KB |
Output is correct |
4 |
Correct |
402 ms |
72704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
312 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 |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
340 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 |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
320 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
468 KB |
Output is correct |
25 |
Correct |
2 ms |
484 KB |
Output is correct |
26 |
Correct |
1 ms |
476 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
3 ms |
468 KB |
Output is correct |
33 |
Correct |
262 ms |
71844 KB |
Output is correct |
34 |
Correct |
254 ms |
71900 KB |
Output is correct |
35 |
Correct |
275 ms |
71856 KB |
Output is correct |
36 |
Correct |
275 ms |
71772 KB |
Output is correct |
37 |
Correct |
283 ms |
71912 KB |
Output is correct |
38 |
Correct |
256 ms |
74360 KB |
Output is correct |
39 |
Correct |
235 ms |
73352 KB |
Output is correct |
40 |
Correct |
264 ms |
77280 KB |
Output is correct |
41 |
Correct |
258 ms |
73460 KB |
Output is correct |
42 |
Correct |
271 ms |
73524 KB |
Output is correct |
43 |
Correct |
246 ms |
77660 KB |
Output is correct |
44 |
Correct |
247 ms |
77668 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 |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
324 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 |
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 |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 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 |
320 KB |
Output is correct |
21 |
Correct |
1 ms |
316 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
468 KB |
Output is correct |
28 |
Correct |
2 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
2 ms |
460 KB |
Output is correct |
31 |
Correct |
2 ms |
468 KB |
Output is correct |
32 |
Correct |
5 ms |
456 KB |
Output is correct |
33 |
Correct |
738 ms |
73068 KB |
Output is correct |
34 |
Correct |
405 ms |
72656 KB |
Output is correct |
35 |
Correct |
427 ms |
72780 KB |
Output is correct |
36 |
Correct |
409 ms |
72800 KB |
Output is correct |
37 |
Correct |
274 ms |
71924 KB |
Output is correct |
38 |
Correct |
320 ms |
75376 KB |
Output is correct |
39 |
Correct |
298 ms |
82192 KB |
Output is correct |
40 |
Correct |
291 ms |
82152 KB |
Output is correct |
41 |
Correct |
302 ms |
73452 KB |
Output is correct |
42 |
Correct |
269 ms |
74368 KB |
Output is correct |
43 |
Correct |
266 ms |
73424 KB |
Output is correct |
44 |
Correct |
264 ms |
77248 KB |
Output is correct |
45 |
Correct |
296 ms |
73420 KB |
Output is correct |
46 |
Correct |
296 ms |
73436 KB |
Output is correct |
47 |
Correct |
297 ms |
77648 KB |
Output is correct |
48 |
Correct |
290 ms |
77624 KB |
Output is correct |
49 |
Correct |
436 ms |
77332 KB |
Output is correct |
50 |
Correct |
368 ms |
77260 KB |
Output is correct |
51 |
Correct |
439 ms |
84128 KB |
Output is correct |
52 |
Correct |
350 ms |
83580 KB |
Output is correct |
53 |
Correct |
823 ms |
75692 KB |
Output is correct |
54 |
Correct |
443 ms |
76260 KB |
Output is correct |
55 |
Correct |
356 ms |
74468 KB |
Output is correct |
56 |
Correct |
359 ms |
79188 KB |
Output is correct |
57 |
Correct |
559 ms |
75124 KB |
Output is correct |
58 |
Correct |
749 ms |
75560 KB |
Output is correct |
59 |
Correct |
249 ms |
77668 KB |
Output is correct |