# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
1042036 |
2024-08-02T12:54:29 Z |
fv3 |
말 (IOI15_horses) |
C++14 |
|
1049 ms |
73808 KB |
#include <bits/stdc++.h>
#include "horses.h"
using namespace std;
typedef long long ll;
const ll mod = 1e9 + 7;
int N; vector<ll> X, Y;
int nt = 1;
vector<ll> st;
vector<ll> st_mod;
vector<ll> st_mx;
set<int> notOne;
int mx_index = 0;
ll get_range(int l, int r, int k, int x, int y)
{
if (y < l || x > r) return 1;
if (x >= l && y <= r) return st[k];
int c = (x + y) / 2;
return get_range(l, r, k*2, x, c) * get_range(l, r, k*2|1, c+1, y);
}
ll get_mod_range(int l, int r, int k, int x, int y)
{
if (y < l || x > r) return 1;
if (x >= l && y <= r) return st_mod[k];
int c = (x + y) / 2;
return (get_mod_range(l, r, k*2, x, c) * get_mod_range(l, r, k*2|1, c+1, y)) % mod;
}
ll get_max_range(int l, int r, int k, int x, int y)
{
if (y < l || x > r) return 1;
if (x >= l && y <= r) return st_mx[k];
int c = (x + y) / 2;
return max(get_max_range(l, r, k*2, x, c), get_max_range(l, r, k*2|1, c+1, y));
}
int get_full_max()
{
ll res = (X[0] * Y[0]) % mod, cnt = X[0];
mx_index = 0;
for (int i = 1; i < N; i++)
{
cnt = (cnt * X[i]) % mod;
ll last_mult = Y[mx_index];
ll mult_range = get_range(mx_index + 1, i, 1, 0, nt - 1);
if (mult_range >= last_mult || mult_range * Y[i] >= last_mult)
{
res = (cnt * Y[i]) % mod;
mx_index = i;
}
}
return (int)res;
}
int get_max()
{
// Find the value of s
// Go left 60 non-one steps
int c = 0;
int s = N - 1;
while (s > 0 && c < 60)
{
c++;
if (X[s] > 1)
{
s--;
continue;
}
auto it = notOne.lower_bound(s);
if (it == notOne.begin())
s = 0;
else
s = *--it;
}
mx_index = s;
ll cnt = get_mod_range(0, s, 1, 0, nt - 1);
ll res, mx_1;
if (X[s] == 1)
{
auto it = notOne.lower_bound(s);
if (it == notOne.end())
return (cnt * get_max_range(s, N - 1, 1, 0, nt - 1)) % mod;
int r = *notOne.lower_bound(s);
mx_1 = get_max_range(s, r - 1, 1, 0, nt - 1);
res = (cnt * mx_1) % mod;
s = r;
}
else
{
res = (Y[s] * cnt) % mod;
s++;
}
for (int i = s; i < N; )
{
ll last_mult = (X[mx_index] == 1 ? mx_1 : Y[mx_index]);
ll mult_range = get_range(mx_index + 1, i, 1, 0, nt - 1);
if (X[i] == 1)
{
auto it = notOne.lower_bound(i);
int r;
if (it == notOne.end())
r = N;
else
r = *it;
int mx_in_range = get_max_range(i, r-1, 1, 0, nt-1);
ll val = Y[mx_in_range];
if (mult_range * mx_in_range >= last_mult)
{
res = (cnt * mx_in_range) % mod;
mx_index = i;
mx_1 = mx_in_range;
}
i = r;
continue;
}
cnt = (cnt * X[i]) % mod;
if (mult_range >= last_mult || mult_range * Y[i] >= last_mult)
{
res = (cnt * Y[i]) % mod;
mx_index = i;
}
i++;
}
return (int)res;
}
int init(int n, int x[], int y[])
{
N = n;
X.resize(N);
Y.resize(N);
for (int i = 0; i < N; i++)
{
X[i] = x[i];
Y[i] = y[i];
if (X[i] > 1)
notOne.insert(i);
}
while (nt < N) nt <<= 1;
st = st_mx = st_mod = vector<ll>(2 * nt, 1);
for (int i = 0; i < N; i++)
{
st[nt + i] = X[i];
st_mod[nt + i] = X[i];
st_mx[nt + i] = Y[i];
}
for (int i = nt-1; i >= 1; i--)
{
st[i] = st[i*2] * st[i*2|1];
st_mod[i] = (st_mod[i*2] * st_mod[i*2|1]) % mod;
st_mx[i] = max(st_mx[i*2], st_mx[i*2|1]);
}
return get_full_max();
}
int updateX(int pos, int val)
{
if (X[pos] > 1)
notOne.erase(pos);
X[pos] = val;
if (val > 1)
notOne.insert(pos);
pos += nt;
st[pos] = val;
st_mod[pos] = val;
for (pos /= 2; pos >= 1; pos /= 2)
{
st[pos] = st[pos*2] * st[pos*2|1];
st_mod[pos] = (st_mod[pos*2] * st_mod[pos*2|1]) % mod;
}
return get_max();
}
int updateY(int pos, int val)
{
Y[pos] = val;
pos += nt;
st_mx[pos] = val;
for (pos /= 2; pos >= 1; pos /= 2)
{
st_mx[pos] = max(st_mx[pos*2], st_mx[pos*2|1]);
}
return get_max();
}
Compilation message
horses.cpp: In function 'int get_max()':
horses.cpp:94:57: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
94 | return (cnt * get_max_range(s, N - 1, 1, 0, nt - 1)) % mod;
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~
horses.cpp:120:35: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
120 | int mx_in_range = get_max_range(i, r-1, 1, 0, nt-1);
| ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~
horses.cpp:121:7: warning: unused variable 'val' [-Wunused-variable]
121 | ll val = Y[mx_in_range];
| ^~~
horses.cpp:135:31: warning: 'mx_1' may be used uninitialized in this function [-Wmaybe-uninitialized]
135 | if (mult_range >= last_mult || mult_range * Y[i] >= last_mult)
| ~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
416 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
344 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
5 ms |
348 KB |
Output is correct |
24 |
Correct |
3 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
588 KB |
Output is correct |
26 |
Correct |
3 ms |
468 KB |
Output is correct |
27 |
Correct |
5 ms |
348 KB |
Output is correct |
28 |
Correct |
4 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
3 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
344 KB |
Output is correct |
32 |
Correct |
5 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
514 ms |
61268 KB |
Output is correct |
2 |
Correct |
590 ms |
61268 KB |
Output is correct |
3 |
Correct |
580 ms |
61272 KB |
Output is correct |
4 |
Correct |
605 ms |
61268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
344 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
5 ms |
348 KB |
Output is correct |
24 |
Correct |
3 ms |
548 KB |
Output is correct |
25 |
Correct |
3 ms |
592 KB |
Output is correct |
26 |
Correct |
3 ms |
348 KB |
Output is correct |
27 |
Correct |
4 ms |
348 KB |
Output is correct |
28 |
Correct |
4 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
3 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
6 ms |
348 KB |
Output is correct |
33 |
Correct |
179 ms |
39140 KB |
Output is correct |
34 |
Correct |
134 ms |
40748 KB |
Output is correct |
35 |
Correct |
219 ms |
71068 KB |
Output is correct |
36 |
Correct |
200 ms |
71140 KB |
Output is correct |
37 |
Correct |
141 ms |
38992 KB |
Output is correct |
38 |
Correct |
176 ms |
51792 KB |
Output is correct |
39 |
Correct |
81 ms |
38864 KB |
Output is correct |
40 |
Correct |
201 ms |
66236 KB |
Output is correct |
41 |
Correct |
86 ms |
38852 KB |
Output is correct |
42 |
Correct |
184 ms |
38996 KB |
Output is correct |
43 |
Correct |
160 ms |
66644 KB |
Output is correct |
44 |
Correct |
154 ms |
66592 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
360 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
344 KB |
Output is correct |
20 |
Correct |
0 ms |
424 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
5 ms |
452 KB |
Output is correct |
24 |
Correct |
3 ms |
348 KB |
Output is correct |
25 |
Correct |
3 ms |
348 KB |
Output is correct |
26 |
Correct |
2 ms |
348 KB |
Output is correct |
27 |
Correct |
4 ms |
532 KB |
Output is correct |
28 |
Correct |
3 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
3 ms |
348 KB |
Output is correct |
31 |
Correct |
2 ms |
348 KB |
Output is correct |
32 |
Correct |
5 ms |
348 KB |
Output is correct |
33 |
Correct |
518 ms |
64104 KB |
Output is correct |
34 |
Correct |
587 ms |
73808 KB |
Output is correct |
35 |
Correct |
589 ms |
65028 KB |
Output is correct |
36 |
Correct |
619 ms |
68716 KB |
Output is correct |
37 |
Correct |
174 ms |
40788 KB |
Output is correct |
38 |
Correct |
121 ms |
40732 KB |
Output is correct |
39 |
Correct |
215 ms |
71120 KB |
Output is correct |
40 |
Correct |
200 ms |
70992 KB |
Output is correct |
41 |
Correct |
140 ms |
38908 KB |
Output is correct |
42 |
Correct |
179 ms |
51796 KB |
Output is correct |
43 |
Correct |
66 ms |
38736 KB |
Output is correct |
44 |
Correct |
186 ms |
66244 KB |
Output is correct |
45 |
Correct |
85 ms |
38744 KB |
Output is correct |
46 |
Correct |
180 ms |
38996 KB |
Output is correct |
47 |
Correct |
152 ms |
66428 KB |
Output is correct |
48 |
Correct |
153 ms |
66640 KB |
Output is correct |
49 |
Correct |
949 ms |
43856 KB |
Output is correct |
50 |
Correct |
489 ms |
43840 KB |
Output is correct |
51 |
Correct |
623 ms |
73040 KB |
Output is correct |
52 |
Correct |
525 ms |
72552 KB |
Output is correct |
53 |
Correct |
855 ms |
42060 KB |
Output is correct |
54 |
Correct |
896 ms |
55776 KB |
Output is correct |
55 |
Correct |
171 ms |
39760 KB |
Output is correct |
56 |
Correct |
574 ms |
67940 KB |
Output is correct |
57 |
Correct |
374 ms |
40532 KB |
Output is correct |
58 |
Correct |
1049 ms |
41020 KB |
Output is correct |
59 |
Correct |
159 ms |
66624 KB |
Output is correct |