# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
641872 | 2022-09-17T17:50:54 Z | QwertyPi | Horses (IOI15_horses) | C++14 | 1500 ms | 47464 KB |
#include "horses.h" #include <bits/stdc++.h> #define ll long long using namespace std; const ll MOD = 1e9 + 7; const ll MAXN = 5e5 + 11; ll x[MAXN], y[MAXN]; struct BIT{ ll bit[MAXN] = {0}, id; void init(ll id, ll (*f)(ll, ll)) { this->id = id; fill(bit, bit + MAXN, id); combine = f; } void add(ll pos, ll val){ pos++; for(ll i = pos; i < MAXN; i += i & -i){ bit[i] = combine(bit[i], val); } } ll qry(ll pos){ pos++; ll ret = id; for(ll i = pos; i; i -= i & -i){ ret = combine(ret, bit[i]); } return ret; } ll (*combine)(ll, ll); } bit_add, bit_mul; ll N; namespace RMQ{ int t[MAXN * 4] = {0}; void upd(int pos, int val, int v = 0, int tl = 0, int tr = N - 1){ if(tl == tr){ t[v] = val; return; } int tm = (tl + tr) / 2; if(pos <= tm){ upd(pos, val, v * 2 + 1, tl, tm); }else{ upd(pos, val, v * 2 + 2, tm + 1, tr); } t[v] = std::max(t[v * 2 + 1], t[v * 2 + 2]); } int max(int l, int r, int v = 0, int tl = 0, int tr = N - 1){ if(r < tl || tr < l) return 0; if(l <= tl && tr <= r) return t[v]; int tm = (tl + tr) / 2; return std::max(max(l, r, v * 2 + 1, tl, tm), max(l, r, v * 2 + 2, tm + 1, tr)); } }; set<ll> n1; ll add(ll x, ll y) { return x + y; } ll mul(ll x, ll y) { return x * y % MOD; } ll bp(ll a, ll b) { if(b == 0) return 1; return bp(a * a % MOD, b / 2) * (b % 2 ? a : 1) % MOD; } ll mi(ll a) { return bp(a, MOD - 2); } ll query() { ll ans = 1, rans = 1; ll c = 1; for(int i = 0; i < N; i++) n1.insert(i); auto ptr = --n1.end(); while(ptr != n1.begin() && c <= MOD){ ptr--; c *= x[*ptr]; } c = 1; for(; ptr != --n1.end(); ptr++){ int v = RMQ::max(*ptr, *next(ptr) - 1); assert(v == y[*ptr]); if(c * v > ans){ ans = c * v; rans = bit_add.qry(*ptr) > 0 ? 0 : mul(bit_mul.qry(*ptr), v); } c *= x[*next(ptr)]; } return rans; } int init(int N, int X[], int Y[]) { ::N = N; bit_add.init(0, add); bit_mul.init(1, mul); for(int i = 0; i < N; i++) x[i] = X[i]; for(int i = 0; i < N; i++) y[i] = Y[i]; for(int i = 0; i < N; i++){ if(x[i] == MOD) bit_add.add(i, 1); else bit_mul.add(i, x[i]); } n1.insert(0); n1.insert(N); for(int i = 0; i < N; i++){ if(x[i] != 1) n1.insert(i); } for(int i = 0; i < N; i++){ RMQ::upd(i, y[i]); } return query(); } int updateX(int pos, int val) { if(x[pos] == MOD) bit_add.add(pos, -1); else bit_mul.add(pos, mi(x[pos])); if(x[pos] != 1 && pos != 0) n1.erase(pos); x[pos] = val; if(x[pos] == MOD) bit_add.add(pos, 1); else bit_mul.add(pos, x[pos]); if(x[pos] != 1) n1.insert(pos); return query(); } int updateY(int pos, int val) { y[pos] = val; RMQ::upd(pos, val); return query(); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 8148 KB | Output is correct |
2 | Correct | 5 ms | 8148 KB | Output is correct |
3 | Correct | 5 ms | 8148 KB | Output is correct |
4 | Correct | 5 ms | 8148 KB | Output is correct |
5 | Correct | 5 ms | 8148 KB | Output is correct |
6 | Correct | 5 ms | 8148 KB | Output is correct |
7 | Correct | 4 ms | 8148 KB | Output is correct |
8 | Correct | 4 ms | 8148 KB | Output is correct |
9 | Correct | 4 ms | 8148 KB | Output is correct |
10 | Correct | 5 ms | 8148 KB | Output is correct |
11 | Correct | 4 ms | 8148 KB | Output is correct |
12 | Correct | 4 ms | 8060 KB | Output is correct |
13 | Correct | 4 ms | 8148 KB | Output is correct |
14 | Correct | 4 ms | 8148 KB | Output is correct |
15 | Correct | 5 ms | 8148 KB | Output is correct |
16 | Correct | 4 ms | 8148 KB | Output is correct |
17 | Correct | 4 ms | 8148 KB | Output is correct |
18 | Correct | 4 ms | 8148 KB | Output is correct |
19 | Correct | 5 ms | 8148 KB | Output is correct |
20 | Correct | 4 ms | 8148 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8148 KB | Output is correct |
2 | Correct | 5 ms | 8044 KB | Output is correct |
3 | Correct | 4 ms | 8148 KB | Output is correct |
4 | Correct | 4 ms | 8148 KB | Output is correct |
5 | Correct | 4 ms | 8148 KB | Output is correct |
6 | Correct | 4 ms | 8148 KB | Output is correct |
7 | Correct | 4 ms | 8148 KB | Output is correct |
8 | Correct | 5 ms | 8148 KB | Output is correct |
9 | Correct | 4 ms | 8148 KB | Output is correct |
10 | Correct | 4 ms | 8148 KB | Output is correct |
11 | Correct | 5 ms | 8148 KB | Output is correct |
12 | Correct | 4 ms | 8148 KB | Output is correct |
13 | Correct | 4 ms | 8148 KB | Output is correct |
14 | Correct | 4 ms | 8148 KB | Output is correct |
15 | Correct | 4 ms | 8148 KB | Output is correct |
16 | Correct | 4 ms | 8044 KB | Output is correct |
17 | Correct | 4 ms | 8148 KB | Output is correct |
18 | Correct | 4 ms | 8148 KB | Output is correct |
19 | Correct | 4 ms | 8148 KB | Output is correct |
20 | Correct | 4 ms | 8148 KB | Output is correct |
21 | Correct | 4 ms | 8148 KB | Output is correct |
22 | Correct | 5 ms | 8148 KB | Output is correct |
23 | Correct | 30 ms | 8276 KB | Output is correct |
24 | Correct | 26 ms | 8248 KB | Output is correct |
25 | Correct | 26 ms | 8236 KB | Output is correct |
26 | Correct | 29 ms | 8260 KB | Output is correct |
27 | Correct | 56 ms | 8216 KB | Output is correct |
28 | Correct | 25 ms | 8148 KB | Output is correct |
29 | Incorrect | 136 ms | 8224 KB | Output isn't correct |
30 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Execution timed out | 1588 ms | 47464 KB | Time limit exceeded |
2 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 8148 KB | Output is correct |
2 | Correct | 4 ms | 8148 KB | Output is correct |
3 | Correct | 5 ms | 8144 KB | Output is correct |
4 | Correct | 5 ms | 8148 KB | Output is correct |
5 | Correct | 4 ms | 8124 KB | Output is correct |
6 | Correct | 5 ms | 8076 KB | Output is correct |
7 | Correct | 4 ms | 8148 KB | Output is correct |
8 | Correct | 4 ms | 8148 KB | Output is correct |
9 | Correct | 4 ms | 8148 KB | Output is correct |
10 | Correct | 4 ms | 8148 KB | Output is correct |
11 | Correct | 4 ms | 8148 KB | Output is correct |
12 | Correct | 4 ms | 8148 KB | Output is correct |
13 | Correct | 4 ms | 8148 KB | Output is correct |
14 | Correct | 4 ms | 8036 KB | Output is correct |
15 | Correct | 5 ms | 8148 KB | Output is correct |
16 | Correct | 6 ms | 8124 KB | Output is correct |
17 | Correct | 4 ms | 8148 KB | Output is correct |
18 | Correct | 4 ms | 8148 KB | Output is correct |
19 | Correct | 4 ms | 8148 KB | Output is correct |
20 | Correct | 4 ms | 8148 KB | Output is correct |
21 | Correct | 4 ms | 8148 KB | Output is correct |
22 | Correct | 5 ms | 8148 KB | Output is correct |
23 | Correct | 31 ms | 8148 KB | Output is correct |
24 | Correct | 25 ms | 8244 KB | Output is correct |
25 | Correct | 25 ms | 8244 KB | Output is correct |
26 | Correct | 23 ms | 8148 KB | Output is correct |
27 | Correct | 52 ms | 8220 KB | Output is correct |
28 | Correct | 27 ms | 8244 KB | Output is correct |
29 | Incorrect | 140 ms | 8216 KB | Output isn't correct |
30 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 5 ms | 8148 KB | Output is correct |
2 | Correct | 4 ms | 8148 KB | Output is correct |
3 | Correct | 4 ms | 8148 KB | Output is correct |
4 | Correct | 4 ms | 8148 KB | Output is correct |
5 | Correct | 4 ms | 8148 KB | Output is correct |
6 | Correct | 4 ms | 8148 KB | Output is correct |
7 | Correct | 4 ms | 8148 KB | Output is correct |
8 | Correct | 4 ms | 8148 KB | Output is correct |
9 | Correct | 4 ms | 8148 KB | Output is correct |
10 | Correct | 4 ms | 8148 KB | Output is correct |
11 | Correct | 4 ms | 8148 KB | Output is correct |
12 | Correct | 4 ms | 8148 KB | Output is correct |
13 | Correct | 4 ms | 8148 KB | Output is correct |
14 | Correct | 4 ms | 8108 KB | Output is correct |
15 | Correct | 4 ms | 8148 KB | Output is correct |
16 | Correct | 4 ms | 8020 KB | Output is correct |
17 | Correct | 4 ms | 8148 KB | Output is correct |
18 | Correct | 4 ms | 8148 KB | Output is correct |
19 | Correct | 4 ms | 8148 KB | Output is correct |
20 | Correct | 4 ms | 8148 KB | Output is correct |
21 | Correct | 4 ms | 8148 KB | Output is correct |
22 | Correct | 4 ms | 8148 KB | Output is correct |
23 | Correct | 32 ms | 8236 KB | Output is correct |
24 | Correct | 24 ms | 8148 KB | Output is correct |
25 | Correct | 25 ms | 8228 KB | Output is correct |
26 | Correct | 25 ms | 8236 KB | Output is correct |
27 | Correct | 54 ms | 8148 KB | Output is correct |
28 | Correct | 25 ms | 8232 KB | Output is correct |
29 | Incorrect | 135 ms | 8148 KB | Output isn't correct |
30 | Halted | 0 ms | 0 KB | - |