# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
284564 |
2020-08-27T16:14:09 Z |
_7_7_ |
Horses (IOI15_horses) |
C++14 |
|
1149 ms |
53400 KB |
#include "horses.h"
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;
typedef tree < int, null_type, less < int >, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
const int inf = 1e9, maxn = 2e5 + 48, mod = 1e9 + 7, N = 5e5 + 11;
const int dx[] = {-1, 0, 1, 0}, dy[] = {0, -1, 0, 1}, block = 300;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = acos(-1);
const ll INF = 1e18;
int t[N << 2], tt[N << 2], n, x[N], y[N];
set < int > q;
void build (int v = 1, int tl = 0, int tr = n - 1) {
if (tl == tr) {
t[v] = y[tl];
tt[v] = x[tl];
return;
}
int tm = (tl + tr) >> 1;
build(v << 1, tl, tm);
build(v << 1 | 1, tm + 1, tr);
t[v] = max(t[v << 1], t[v << 1 | 1]);
tt[v] = tt[v << 1] * 1ll * tt[v << 1 | 1] % mod;
}
void updX (int pos, int x, int v = 1, int tl = 0, int tr = n - 1) {
if (tl == tr) {
tt[v] = x;
return;
}
int tm = (tl + tr) >> 1;
if (pos <= tm)
updX(pos, x, v << 1, tl, tm);
else
updX(pos, x, v << 1 | 1, tm + 1, tr);
tt[v] = tt[v << 1] * 1ll * tt[v << 1 | 1] % mod;
}
void updY (int pos, int x, int v = 1, int tl = 0, int tr = n - 1) {
if (tl == tr) {
t[v] = x;
return;
}
int tm = (tl + tr) >> 1;
if (pos <= tm)
updY(pos, x, v << 1, tl, tm);
else
updY(pos, x, v << 1 | 1, tm + 1, tr);
t[v] = max(t[v << 1], t[v << 1 | 1]);
}
int getX (int l, int r, int v = 1, int tl = 0, int tr = n - 1) {
if (l > r || tl > r || l > tr)
return 1;
if (l <= tl && tr <= r)
return tt[v];
int tm = (tl + tr) >> 1;
return getX(l, r, v << 1, tl, tm) * 1ll * getX(l, r, v << 1 | 1, tm + 1, tr) % mod;
}
int getY (int l, int r, int v = 1, int tl = 0, int tr = n - 1) {
if (l > r || tl > r || l > tr)
return 0;
if (l <= tl && tr <= r)
return t[v];
int tm = (tl + tr) >> 1;
return max(getY(l, r, v << 1, tl, tm), getY(l, r, v << 1 | 1, tm + 1, tr));
}
vector < pii > V;
bool cmp (int i, int j) {
bool rev = 0;
if (j > i) {
swap(i, j);
rev = 1;
}
int cur = V[i].s;
for (int k = j + 1; k <= i; ++k) {
if (cur > (2*inf) / x[V[k].f])
return rev^1;
cur *= x[V[k].f];
}
bool ok = 0;
if (cur > V[j].s)
ok = 1;
return ok ^ rev;
}
int solve () {
q.insert(0);
auto it = q.begin();
V.clear();
while (1) {
int cur = - *it;
V.pb(mp(cur, getY(cur, n - 1)));
++it;
if (it == q.end() || sz(V) == 31)
break;
}
reverse(all(V));
int j = 0;
for (int i = 1; i < sz(V); ++i)
if (cmp(i, j))
j = i;
// cerr << j << endl;
return getX(0, V[j].f) * 1ll * V[j].s % mod;
}
int init(int _n, int X[], int Y[]) {
n = _n;
for (int i = 0; i < n; ++i) {
x[i] = X[i];
y[i] = Y[i];
}
build();
for (int i = 0; i < n; ++i)
if (x[i] > 1)
q.insert(-i);
return solve();
}
int updateX(int pos, int val) {
updX(pos, val);
x[pos] = val;
if (val > 1)
q.insert(-pos);
else
q.erase(-pos);
return solve();
}
int updateY(int pos, int val) {
updY(pos, val);
y[pos] = val;
return solve();
}
Compilation message
horses.cpp: In function 'void build(int, int, int)':
horses.cpp:61:44: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
61 | tt[v] = tt[v << 1] * 1ll * tt[v << 1 | 1] % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void updX(int, int, int, int, int)':
horses.cpp:64:65: warning: declaration of 'x' shadows a global declaration [-Wshadow]
64 | void updX (int pos, int x, int v = 1, int tl = 0, int tr = n - 1) {
| ^
horses.cpp:45:31: note: shadowed declaration is here
45 | int t[N << 2], tt[N << 2], n, x[N], y[N];
| ^
horses.cpp:76:44: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
76 | tt[v] = tt[v << 1] * 1ll * tt[v << 1 | 1] % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'void updY(int, int, int, int, int)':
horses.cpp:80:65: warning: declaration of 'x' shadows a global declaration [-Wshadow]
80 | void updY (int pos, int x, int v = 1, int tl = 0, int tr = n - 1) {
| ^
horses.cpp:45:31: note: shadowed declaration is here
45 | int t[N << 2], tt[N << 2], n, x[N], y[N];
| ^
horses.cpp: In function 'int getX(int, int, int, int, int)':
horses.cpp:104:79: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
104 | return getX(l, r, v << 1, tl, tm) * 1ll * getX(l, r, v << 1 | 1, tm + 1, tr) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp: In function 'int solve()':
horses.cpp:166:40: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
166 | return getX(0, V[j].f) * 1ll * V[j].s % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
0 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
416 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
384 KB |
Output is correct |
25 |
Correct |
4 ms |
512 KB |
Output is correct |
26 |
Correct |
4 ms |
512 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
4 ms |
512 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
9 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1149 ms |
41048 KB |
Output is correct |
2 |
Correct |
845 ms |
41316 KB |
Output is correct |
3 |
Correct |
851 ms |
41336 KB |
Output is correct |
4 |
Correct |
930 ms |
41356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
0 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
1 ms |
384 KB |
Output is correct |
20 |
Correct |
0 ms |
384 KB |
Output is correct |
21 |
Correct |
0 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
384 KB |
Output is correct |
25 |
Correct |
4 ms |
512 KB |
Output is correct |
26 |
Correct |
4 ms |
512 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
4 ms |
512 KB |
Output is correct |
31 |
Correct |
6 ms |
384 KB |
Output is correct |
32 |
Correct |
8 ms |
384 KB |
Output is correct |
33 |
Correct |
121 ms |
20472 KB |
Output is correct |
34 |
Correct |
117 ms |
20472 KB |
Output is correct |
35 |
Correct |
252 ms |
50840 KB |
Output is correct |
36 |
Correct |
238 ms |
50808 KB |
Output is correct |
37 |
Correct |
115 ms |
18680 KB |
Output is correct |
38 |
Correct |
152 ms |
31480 KB |
Output is correct |
39 |
Correct |
36 ms |
18424 KB |
Output is correct |
40 |
Correct |
239 ms |
45928 KB |
Output is correct |
41 |
Correct |
85 ms |
18680 KB |
Output is correct |
42 |
Correct |
131 ms |
18556 KB |
Output is correct |
43 |
Correct |
170 ms |
46204 KB |
Output is correct |
44 |
Correct |
166 ms |
46328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
0 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
0 ms |
384 KB |
Output is correct |
9 |
Correct |
0 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
512 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
384 KB |
Output is correct |
18 |
Correct |
1 ms |
384 KB |
Output is correct |
19 |
Correct |
0 ms |
384 KB |
Output is correct |
20 |
Correct |
1 ms |
384 KB |
Output is correct |
21 |
Correct |
1 ms |
384 KB |
Output is correct |
22 |
Correct |
0 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
384 KB |
Output is correct |
25 |
Correct |
4 ms |
512 KB |
Output is correct |
26 |
Correct |
4 ms |
512 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
1 ms |
384 KB |
Output is correct |
30 |
Correct |
4 ms |
512 KB |
Output is correct |
31 |
Correct |
6 ms |
384 KB |
Output is correct |
32 |
Correct |
10 ms |
384 KB |
Output is correct |
33 |
Correct |
1137 ms |
44920 KB |
Output is correct |
34 |
Correct |
867 ms |
53400 KB |
Output is correct |
35 |
Correct |
842 ms |
44664 KB |
Output is correct |
36 |
Correct |
924 ms |
48504 KB |
Output is correct |
37 |
Correct |
124 ms |
20608 KB |
Output is correct |
38 |
Correct |
97 ms |
20524 KB |
Output is correct |
39 |
Correct |
244 ms |
50812 KB |
Output is correct |
40 |
Correct |
236 ms |
50808 KB |
Output is correct |
41 |
Correct |
115 ms |
18680 KB |
Output is correct |
42 |
Correct |
155 ms |
31480 KB |
Output is correct |
43 |
Correct |
37 ms |
18424 KB |
Output is correct |
44 |
Correct |
239 ms |
45920 KB |
Output is correct |
45 |
Correct |
83 ms |
18552 KB |
Output is correct |
46 |
Correct |
130 ms |
18552 KB |
Output is correct |
47 |
Correct |
166 ms |
46228 KB |
Output is correct |
48 |
Correct |
169 ms |
46328 KB |
Output is correct |
49 |
Correct |
874 ms |
23800 KB |
Output is correct |
50 |
Correct |
655 ms |
23544 KB |
Output is correct |
51 |
Correct |
825 ms |
52808 KB |
Output is correct |
52 |
Correct |
759 ms |
52216 KB |
Output is correct |
53 |
Correct |
851 ms |
21880 KB |
Output is correct |
54 |
Correct |
791 ms |
35448 KB |
Output is correct |
55 |
Correct |
139 ms |
19576 KB |
Output is correct |
56 |
Correct |
971 ms |
47736 KB |
Output is correct |
57 |
Correct |
635 ms |
20216 KB |
Output is correct |
58 |
Correct |
1119 ms |
20864 KB |
Output is correct |
59 |
Correct |
165 ms |
46200 KB |
Output is correct |