# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
164385 |
2019-11-20T06:13:12 Z |
tri |
말 (IOI15_horses) |
C++14 |
|
796 ms |
86984 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
#define pb push_back
#define f first
#define s second
namespace debug {
const int DEBUG = true;
template<class T1, class T2>
void pr(const pair<T1, T2> &x);
template<class T, size_t SZ>
void pr(const array<T, SZ> &x);
template<class T>
void pr(const vector<T> &x);
template<class T>
void pr(const set<T> &x);
template<class T1, class T2>
void pr(const map<T1, T2> &x);
template<class T>
void pr(const T &x) { if (DEBUG) cout << x; }
template<class T, class... Ts>
void pr(const T &first, const Ts &... rest) { pr(first), pr(rest...); }
template<class T1, class T2>
void pr(const pair<T1, T2> &x) { pr("{", x.f, ", ", x.s, "}"); }
template<class T>
void prIn(const T &x) {
pr("{");
bool fst = 1;
for (auto &a : x) {
pr(fst ? "" : ", ", a), fst = 0;
}
pr("}");
}
template<class T, size_t SZ>
void pr(const array<T, SZ> &x) { prIn(x); }
template<class T>
void pr(const vector<T> &x) { prIn(x); }
template<class T>
void pr(const set<T> &x) { prIn(x); }
template<class T1, class T2>
void pr(const map<T1, T2> &x) { prIn(x); }
void ps() { pr("\n"), cout << flush; }
template<class Arg, class... Args>
void ps(const Arg &first, const Args &... rest) {
pr(first, " ");
ps(rest...);
}
}
using namespace debug;
const int MAXN = 600000;
const ll MOD = 1e9 + 7;
struct ProdTr {
ll tr[4 * MAXN];
void b(int i, int l, int r, int o[]) {
if (l == r) {
tr[i] = o[l];
return;
}
int mid = (l + r) / 2;
b(i * 2, l, mid, o);
b(i * 2 + 1, mid + 1, r, o);
tr[i] = tr[i * 2] * tr[i * 2 + 1] % MOD;
}
ll q(int i, int l, int r, int s, int e) {
if (e < l || r < s) {
return 1;
}
if (s <= l && r <= e) {
return tr[i];
}
int mid = (l + r) / 2;
return q(i * 2, l, mid, s, e) * q(i * 2 + 1, mid + 1, r, s, e) % MOD;
}
void u(int i, int l, int r, int x, int d) {
if (l == r) {
tr[i] = d;
return;
}
int mid = (l + r) / 2;
if (x <= mid) {
u(i * 2, l, mid, x, d);
} else {
u(i * 2 + 1, mid + 1, r, x, d);
}
tr[i] = tr[i * 2] * tr[i * 2 + 1] % MOD;
}
} prodTr;
struct MaxTr {
ll tr[4 * MAXN];
void b(int i, int l, int r, int o[]) {
if (l == r) {
tr[i] = o[l];
return;
}
int mid = (l + r) / 2;
b(i * 2, l, mid, o);
b(i * 2 + 1, mid + 1, r, o);
tr[i] = max(tr[i * 2], tr[i * 2 + 1]);
}
ll q(int i, int l, int r, int s, int e) {
if (e < l || r < s) {
return 0;
}
if (s <= l && r <= e) {
return tr[i];
}
int mid = (l + r) / 2;
return max(q(i * 2, l, mid, s, e), q(i * 2 + 1, mid + 1, r, s, e));
}
void u(int i, int l, int r, int x, int d) {
if (l == r) {
tr[i] = d;
return;
}
int mid = (l + r) / 2;
if (x <= mid) {
u(i * 2, l, mid, x, d);
} else {
u(i * 2 + 1, mid + 1, r, x, d);
}
tr[i] = max(tr[i * 2], tr[i * 2 + 1]);
}
} maxTr;
int N;
vl X, Y;
bool first = true;
set<int> notO;
ll query() {
if (first) {
// ps(notO);
first = false;
}
auto it = notO.end(); // at N + 1 mark
it--;
int bI = -1;
ll bY = -1;
long double bestV = -1;
ll denom = 1;
// more than 30 not 1's will produce factor greater than 10^9
while (denom < 1e9) {
int last = *it;
it--;
int i = *it;
// ps("i", i);
ll cY = maxTr.q(1, 1, N, i, last - 1);
if ((ld) cY / denom > bestV) {
bestV = (ld) cY / denom;
bI = i;
bY = cY;
}
denom *= X[i];
if (it == notO.begin()) {
break;
}
}
// ps("bI, bY:", bI, bY);
ll ans = prodTr.q(1, 1, N, 1, bI) * bY % MOD;
return ans;
}
int init(int iN, int iX[], int iY[]) {
N = iN;
fill(prodTr.tr, prodTr.tr + 4 * MAXN, 1);
fill(maxTr.tr, maxTr.tr + 4 * MAXN, 0);
//1-indexing
X.pb(-1);
Y.pb(-1);
X.pb(1);
Y.pb(1);
for (int i = 0; i < N; i++) {
X.pb(iX[i]);
Y.pb(iY[i]);
}
N++;
for (int i = 1; i <= N; i++) {
prodTr.u(1, 1, N, i, X[i]);
maxTr.u(1, 1, N, i, Y[i]);
if (X[i] != 1) {
notO.insert(i);
}
}
notO.insert(1);
notO.insert(N + 1);
// ps(X);
// ps(Y);
// ps(notO);
return query();
}
int updateX(int i, int v) {
i += 2;
// ps("changing", i, v);
X[i] = v;
prodTr.u(1, 1, N, i, v);
if (v == 1) {
notO.erase(i);
} else {
notO.insert(i);
}
return query();
}
int updateY(int i, int v) {
i += 2;
Y[i] = v;
maxTr.u(1, 1, N, i, v);
return query();
}
Compilation message
horses.cpp: In function 'll query()':
horses.cpp:182:20: warning: conversion to 'double' from 'll {aka long long int}' may alter its value [-Wconversion]
while (denom < 1e9) {
^~~
horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:228:34: warning: conversion to 'int' from '__gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type {aka long long int}' may alter its value [-Wconversion]
prodTr.u(1, 1, N, i, X[i]);
^
horses.cpp:229:33: warning: conversion to 'int' from '__gnu_cxx::__alloc_traits<std::allocator<long long int> >::value_type {aka long long int}' may alter its value [-Wconversion]
maxTr.u(1, 1, N, i, Y[i]);
^
horses.cpp:241:17: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return query();
~~~~~^~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:254:17: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return query();
~~~~~^~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:261:17: warning: conversion to 'int' from 'll {aka long long int}' may alter its value [-Wconversion]
return query();
~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
37884 KB |
Output is correct |
2 |
Correct |
32 ms |
37880 KB |
Output is correct |
3 |
Correct |
33 ms |
37880 KB |
Output is correct |
4 |
Correct |
32 ms |
38008 KB |
Output is correct |
5 |
Correct |
32 ms |
37880 KB |
Output is correct |
6 |
Correct |
32 ms |
37880 KB |
Output is correct |
7 |
Correct |
32 ms |
37880 KB |
Output is correct |
8 |
Correct |
32 ms |
37880 KB |
Output is correct |
9 |
Correct |
32 ms |
37880 KB |
Output is correct |
10 |
Correct |
32 ms |
37880 KB |
Output is correct |
11 |
Correct |
32 ms |
37880 KB |
Output is correct |
12 |
Correct |
32 ms |
37880 KB |
Output is correct |
13 |
Correct |
32 ms |
37880 KB |
Output is correct |
14 |
Correct |
32 ms |
37880 KB |
Output is correct |
15 |
Correct |
33 ms |
37880 KB |
Output is correct |
16 |
Correct |
32 ms |
37880 KB |
Output is correct |
17 |
Correct |
32 ms |
38008 KB |
Output is correct |
18 |
Correct |
32 ms |
37880 KB |
Output is correct |
19 |
Correct |
35 ms |
37880 KB |
Output is correct |
20 |
Correct |
32 ms |
37880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
37880 KB |
Output is correct |
2 |
Correct |
38 ms |
37852 KB |
Output is correct |
3 |
Correct |
33 ms |
37880 KB |
Output is correct |
4 |
Correct |
32 ms |
37880 KB |
Output is correct |
5 |
Correct |
32 ms |
37840 KB |
Output is correct |
6 |
Correct |
33 ms |
37880 KB |
Output is correct |
7 |
Correct |
33 ms |
37880 KB |
Output is correct |
8 |
Correct |
32 ms |
37880 KB |
Output is correct |
9 |
Correct |
33 ms |
37880 KB |
Output is correct |
10 |
Correct |
32 ms |
37880 KB |
Output is correct |
11 |
Correct |
33 ms |
37880 KB |
Output is correct |
12 |
Correct |
59 ms |
37908 KB |
Output is correct |
13 |
Correct |
34 ms |
37880 KB |
Output is correct |
14 |
Correct |
32 ms |
37880 KB |
Output is correct |
15 |
Correct |
32 ms |
37880 KB |
Output is correct |
16 |
Correct |
32 ms |
37880 KB |
Output is correct |
17 |
Correct |
32 ms |
37904 KB |
Output is correct |
18 |
Correct |
32 ms |
37880 KB |
Output is correct |
19 |
Correct |
33 ms |
37832 KB |
Output is correct |
20 |
Correct |
32 ms |
37880 KB |
Output is correct |
21 |
Correct |
32 ms |
37880 KB |
Output is correct |
22 |
Correct |
34 ms |
37916 KB |
Output is correct |
23 |
Correct |
37 ms |
38008 KB |
Output is correct |
24 |
Correct |
33 ms |
38008 KB |
Output is correct |
25 |
Correct |
33 ms |
38008 KB |
Output is correct |
26 |
Correct |
75 ms |
38008 KB |
Output is correct |
27 |
Correct |
35 ms |
38008 KB |
Output is correct |
28 |
Correct |
33 ms |
38008 KB |
Output is correct |
29 |
Correct |
33 ms |
38008 KB |
Output is correct |
30 |
Correct |
34 ms |
38064 KB |
Output is correct |
31 |
Correct |
34 ms |
38008 KB |
Output is correct |
32 |
Correct |
35 ms |
38008 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
796 ms |
74200 KB |
Output is correct |
2 |
Correct |
576 ms |
86984 KB |
Output is correct |
3 |
Correct |
577 ms |
78184 KB |
Output is correct |
4 |
Correct |
684 ms |
81824 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
37880 KB |
Output is correct |
2 |
Correct |
32 ms |
37880 KB |
Output is correct |
3 |
Correct |
35 ms |
37880 KB |
Output is correct |
4 |
Correct |
32 ms |
37880 KB |
Output is correct |
5 |
Correct |
32 ms |
37880 KB |
Output is correct |
6 |
Correct |
33 ms |
37880 KB |
Output is correct |
7 |
Correct |
32 ms |
37880 KB |
Output is correct |
8 |
Correct |
32 ms |
38004 KB |
Output is correct |
9 |
Correct |
32 ms |
37880 KB |
Output is correct |
10 |
Correct |
32 ms |
37880 KB |
Output is correct |
11 |
Correct |
32 ms |
38008 KB |
Output is correct |
12 |
Correct |
32 ms |
37880 KB |
Output is correct |
13 |
Correct |
33 ms |
38008 KB |
Output is correct |
14 |
Correct |
32 ms |
37900 KB |
Output is correct |
15 |
Correct |
32 ms |
38008 KB |
Output is correct |
16 |
Correct |
32 ms |
37880 KB |
Output is correct |
17 |
Correct |
33 ms |
37880 KB |
Output is correct |
18 |
Correct |
32 ms |
38008 KB |
Output is correct |
19 |
Correct |
32 ms |
37880 KB |
Output is correct |
20 |
Correct |
32 ms |
37852 KB |
Output is correct |
21 |
Correct |
45 ms |
37888 KB |
Output is correct |
22 |
Correct |
32 ms |
38136 KB |
Output is correct |
23 |
Correct |
33 ms |
38008 KB |
Output is correct |
24 |
Correct |
33 ms |
38008 KB |
Output is correct |
25 |
Correct |
33 ms |
38008 KB |
Output is correct |
26 |
Correct |
33 ms |
38008 KB |
Output is correct |
27 |
Correct |
34 ms |
38008 KB |
Output is correct |
28 |
Correct |
34 ms |
38052 KB |
Output is correct |
29 |
Correct |
33 ms |
37980 KB |
Output is correct |
30 |
Correct |
33 ms |
38008 KB |
Output is correct |
31 |
Correct |
34 ms |
38008 KB |
Output is correct |
32 |
Correct |
34 ms |
38008 KB |
Output is correct |
33 |
Correct |
220 ms |
53832 KB |
Output is correct |
34 |
Correct |
219 ms |
53988 KB |
Output is correct |
35 |
Correct |
453 ms |
84264 KB |
Output is correct |
36 |
Correct |
440 ms |
84064 KB |
Output is correct |
37 |
Correct |
254 ms |
52176 KB |
Output is correct |
38 |
Correct |
325 ms |
64724 KB |
Output is correct |
39 |
Correct |
209 ms |
51920 KB |
Output is correct |
40 |
Correct |
431 ms |
79248 KB |
Output is correct |
41 |
Correct |
227 ms |
52076 KB |
Output is correct |
42 |
Correct |
243 ms |
52168 KB |
Output is correct |
43 |
Correct |
430 ms |
79588 KB |
Output is correct |
44 |
Correct |
445 ms |
79568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
31 ms |
37880 KB |
Output is correct |
2 |
Correct |
32 ms |
37924 KB |
Output is correct |
3 |
Correct |
32 ms |
37884 KB |
Output is correct |
4 |
Correct |
32 ms |
37880 KB |
Output is correct |
5 |
Correct |
32 ms |
37880 KB |
Output is correct |
6 |
Correct |
84 ms |
37880 KB |
Output is correct |
7 |
Correct |
32 ms |
37880 KB |
Output is correct |
8 |
Correct |
31 ms |
37852 KB |
Output is correct |
9 |
Correct |
32 ms |
37880 KB |
Output is correct |
10 |
Correct |
32 ms |
37904 KB |
Output is correct |
11 |
Correct |
34 ms |
37852 KB |
Output is correct |
12 |
Correct |
32 ms |
37880 KB |
Output is correct |
13 |
Correct |
32 ms |
37880 KB |
Output is correct |
14 |
Correct |
32 ms |
37880 KB |
Output is correct |
15 |
Correct |
32 ms |
37852 KB |
Output is correct |
16 |
Correct |
31 ms |
37940 KB |
Output is correct |
17 |
Correct |
32 ms |
37880 KB |
Output is correct |
18 |
Correct |
32 ms |
37892 KB |
Output is correct |
19 |
Correct |
32 ms |
37884 KB |
Output is correct |
20 |
Correct |
31 ms |
37920 KB |
Output is correct |
21 |
Correct |
32 ms |
37876 KB |
Output is correct |
22 |
Correct |
31 ms |
37880 KB |
Output is correct |
23 |
Correct |
33 ms |
38008 KB |
Output is correct |
24 |
Correct |
33 ms |
38008 KB |
Output is correct |
25 |
Correct |
33 ms |
38008 KB |
Output is correct |
26 |
Correct |
36 ms |
38008 KB |
Output is correct |
27 |
Correct |
35 ms |
38008 KB |
Output is correct |
28 |
Correct |
33 ms |
38008 KB |
Output is correct |
29 |
Correct |
33 ms |
38008 KB |
Output is correct |
30 |
Correct |
34 ms |
37956 KB |
Output is correct |
31 |
Correct |
34 ms |
38008 KB |
Output is correct |
32 |
Correct |
37 ms |
38008 KB |
Output is correct |
33 |
Correct |
781 ms |
78160 KB |
Output is correct |
34 |
Correct |
581 ms |
86808 KB |
Output is correct |
35 |
Correct |
630 ms |
78084 KB |
Output is correct |
36 |
Correct |
668 ms |
81872 KB |
Output is correct |
37 |
Correct |
220 ms |
53972 KB |
Output is correct |
38 |
Correct |
219 ms |
53996 KB |
Output is correct |
39 |
Correct |
518 ms |
84340 KB |
Output is correct |
40 |
Correct |
460 ms |
84176 KB |
Output is correct |
41 |
Correct |
253 ms |
52180 KB |
Output is correct |
42 |
Correct |
334 ms |
64720 KB |
Output is correct |
43 |
Correct |
306 ms |
51920 KB |
Output is correct |
44 |
Correct |
446 ms |
79440 KB |
Output is correct |
45 |
Correct |
251 ms |
52000 KB |
Output is correct |
46 |
Correct |
276 ms |
52108 KB |
Output is correct |
47 |
Correct |
441 ms |
79720 KB |
Output is correct |
48 |
Correct |
444 ms |
79688 KB |
Output is correct |
49 |
Correct |
361 ms |
56784 KB |
Output is correct |
50 |
Correct |
329 ms |
57040 KB |
Output is correct |
51 |
Correct |
605 ms |
85960 KB |
Output is correct |
52 |
Correct |
510 ms |
85620 KB |
Output is correct |
53 |
Correct |
710 ms |
55168 KB |
Output is correct |
54 |
Correct |
541 ms |
68864 KB |
Output is correct |
55 |
Correct |
346 ms |
53064 KB |
Output is correct |
56 |
Correct |
537 ms |
81104 KB |
Output is correct |
57 |
Correct |
568 ms |
53648 KB |
Output is correct |
58 |
Correct |
596 ms |
54264 KB |
Output is correct |
59 |
Correct |
430 ms |
79692 KB |
Output is correct |