# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
615391 |
2022-07-31T08:50:01 Z |
8e7 |
말 (IOI15_horses) |
C++17 |
|
610 ms |
51328 KB |
//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r){
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 500005
#define mod 1000000007
#define pii pair<int, int>
#define ff first
#define ss second
#include "horses.h"
struct segtree{
int seg[4*maxn];
void init(int cur, int l, int r, int a[]) {
if (r <= l) return;
if (r - l == 1){
seg[cur] = a[l];
return;
}
int m = (l + r) / 2;
init(cur*2, l, m, a), init(cur*2+1, m, r, a);
seg[cur] = max(seg[cur*2], seg[cur*2+1]);
}
void modify(int cur, int l, int r, int ind, int x){
if (r <= l) return;
if (r - l == 1){
seg[cur] = x;
return;
}
int m = (l + r) / 2;
if (ind < m) modify(cur*2, l, m, ind, x);
else modify(cur*2+1, m, r, ind, x);
seg[cur] = max(seg[cur*2], seg[cur*2+1]);
}
int query(int cur, int l, int r, int ql, int qr){
if (r <= l || ql >= r || qr <= l) return 0;
if (ql <= l && qr >= r) return seg[cur];
int m = (l + r) / 2;
return max(query(cur*2, l, m, ql, qr), query(cur*2+1, m, r, ql, qr));
}
} tr;
struct BIT{
ll bit[maxn];
void init(int n){
for (int i = 0;i <= n;i++) bit[i] = 1;
}
void modify(int ind, ll val) {
ind++;
for (;ind < maxn;ind += ind & (-ind)) bit[ind] = bit[ind] * val % mod;
}
ll query(int ind) {
ind++;
ll ret = 1;
for (;ind > 0;ind -= ind & (-ind)) ret = ret * bit[ind] % mod;
return ret;
}
} bit;
ll modpow(ll x, ll p){
ll ret = 1;
while (p) {
if (p & 1) ret = ret * x % mod;
p >>= 1, x = x * x % mod;
}
return ret;
}
const ll inf = 1e9;
int n;
int a[maxn];
set<int> se;
int query() {
pary(se.begin(), se.end());
ll ret = 0;
ll suf = 1;
auto it = prev(se.end());
vector<ll> v, mul;
while (true) {
bool fi = it == se.begin();
int lef = (fi ? 0 : *prev(it)), rig = *it; //[lef, rig)
ll val = max(suf, (ll)tr.query(1, 0, n, lef, rig));
v.push_back(val);
ll m = fi ? 1 : a[*prev(it)];
mul.push_back(m);
suf *= m;
if (fi || suf >= inf) {
mul.pop_back();
reverse(v.begin(), v.end());
reverse(mul.begin(), mul.end());
pary(v.begin(), v.end());
pary(mul.begin(), mul.end());
ll pref = fi ? 1: bit.query(*prev(it));
ll best = 0, p = 1;
for (int i = 0;i < v.size();i++) {
best = max(best, p * v[i]);
if (i < (int)v.size() - 1)p *= mul[i];
}
ret = (best % mod) * pref % mod;
return ret;
}
it = prev(it);
}
}
int init(int N, int X[], int Y[]) {
n = N;
bit.init(n);
for (int i = 0;i < n;i++) {
a[i] = X[i];
if (a[i] > 1) se.insert(i);
bit.modify(i, X[i]);
}
se.insert(n);
tr.init(1, 0, n, Y);
return query();
}
int updateX(int pos, int val) {
bit.modify(pos, modpow(a[pos], mod - 2));
if (a[pos] > 1) {
se.erase(se.find(pos));
}
a[pos] = val;
if (a[pos] > 1) {
se.insert(pos);
}
bit.modify(pos, val);
return query();
}
int updateY(int pos, int val) {
tr.modify(1, 0, n, pos, val);
return query();
}
Compilation message
horses.cpp: In function 'int query()':
horses.cpp:13:19: warning: statement has no effect [-Wunused-value]
13 | #define pary(...) 0
| ^
horses.cpp:83:2: note: in expansion of macro 'pary'
83 | pary(se.begin(), se.end());
| ^~~~
horses.cpp:13:19: warning: statement has no effect [-Wunused-value]
13 | #define pary(...) 0
| ^
horses.cpp:100:4: note: in expansion of macro 'pary'
100 | pary(v.begin(), v.end());
| ^~~~
horses.cpp:13:19: warning: statement has no effect [-Wunused-value]
13 | #define pary(...) 0
| ^
horses.cpp:101:4: note: in expansion of macro 'pary'
101 | pary(mul.begin(), mul.end());
| ^~~~
horses.cpp:104:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
104 | for (int i = 0;i < v.size();i++) {
| ~~^~~~~~~~~~
horses.cpp:109:11: warning: conversion from 'long long int' to 'int' may change value [-Wconversion]
109 | return ret;
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
464 KB |
Output is correct |
26 |
Correct |
2 ms |
468 KB |
Output is correct |
27 |
Correct |
3 ms |
340 KB |
Output is correct |
28 |
Correct |
2 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
432 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
4 ms |
340 KB |
Output is correct |
32 |
Correct |
6 ms |
316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
591 ms |
38604 KB |
Output is correct |
2 |
Correct |
288 ms |
38608 KB |
Output is correct |
3 |
Correct |
313 ms |
38612 KB |
Output is correct |
4 |
Correct |
399 ms |
38604 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
2 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
316 KB |
Output is correct |
25 |
Correct |
3 ms |
468 KB |
Output is correct |
26 |
Correct |
2 ms |
464 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
340 KB |
Output is correct |
30 |
Correct |
2 ms |
340 KB |
Output is correct |
31 |
Correct |
4 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
53 ms |
18252 KB |
Output is correct |
34 |
Correct |
47 ms |
18232 KB |
Output is correct |
35 |
Correct |
208 ms |
48568 KB |
Output is correct |
36 |
Correct |
173 ms |
48584 KB |
Output is correct |
37 |
Correct |
82 ms |
16492 KB |
Output is correct |
38 |
Correct |
112 ms |
29192 KB |
Output is correct |
39 |
Correct |
42 ms |
16264 KB |
Output is correct |
40 |
Correct |
164 ms |
43648 KB |
Output is correct |
41 |
Correct |
69 ms |
16260 KB |
Output is correct |
42 |
Correct |
74 ms |
16348 KB |
Output is correct |
43 |
Correct |
165 ms |
44004 KB |
Output is correct |
44 |
Correct |
166 ms |
43952 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
340 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
2 ms |
340 KB |
Output is correct |
25 |
Correct |
2 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
452 KB |
Output is correct |
27 |
Correct |
4 ms |
340 KB |
Output is correct |
28 |
Correct |
3 ms |
340 KB |
Output is correct |
29 |
Correct |
2 ms |
384 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
3 ms |
340 KB |
Output is correct |
32 |
Correct |
3 ms |
340 KB |
Output is correct |
33 |
Correct |
610 ms |
42444 KB |
Output is correct |
34 |
Correct |
344 ms |
51328 KB |
Output is correct |
35 |
Correct |
372 ms |
42360 KB |
Output is correct |
36 |
Correct |
467 ms |
46272 KB |
Output is correct |
37 |
Correct |
49 ms |
18292 KB |
Output is correct |
38 |
Correct |
48 ms |
18276 KB |
Output is correct |
39 |
Correct |
194 ms |
48632 KB |
Output is correct |
40 |
Correct |
183 ms |
48576 KB |
Output is correct |
41 |
Correct |
85 ms |
16436 KB |
Output is correct |
42 |
Correct |
107 ms |
29268 KB |
Output is correct |
43 |
Correct |
40 ms |
16264 KB |
Output is correct |
44 |
Correct |
160 ms |
43648 KB |
Output is correct |
45 |
Correct |
59 ms |
16248 KB |
Output is correct |
46 |
Correct |
72 ms |
16384 KB |
Output is correct |
47 |
Correct |
167 ms |
43932 KB |
Output is correct |
48 |
Correct |
160 ms |
44044 KB |
Output is correct |
49 |
Correct |
154 ms |
21344 KB |
Output is correct |
50 |
Correct |
128 ms |
21280 KB |
Output is correct |
51 |
Correct |
342 ms |
50580 KB |
Output is correct |
52 |
Correct |
234 ms |
49996 KB |
Output is correct |
53 |
Correct |
542 ms |
19712 KB |
Output is correct |
54 |
Correct |
278 ms |
33124 KB |
Output is correct |
55 |
Correct |
134 ms |
17224 KB |
Output is correct |
56 |
Correct |
254 ms |
45420 KB |
Output is correct |
57 |
Correct |
372 ms |
17892 KB |
Output is correct |
58 |
Correct |
496 ms |
18468 KB |
Output is correct |
59 |
Correct |
168 ms |
44044 KB |
Output is correct |