# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1039837 | 2024-07-31T10:13:02 Z | Zicrus | Horses (IOI15_horses) | C++17 | 67 ms | 21380 KB |
#include <bits/stdc++.h> #include "horses.h" using namespace std; typedef long long ll; ll n, pow2; vector<ll> segMul; vector<bool> segOF; vector<ll> x, y; #define OF (1000000007) #define MOD (1000000007) void setX(int pos, int val) { x[pos] = val; pos += pow2; segMul[pos] = val; pos /= 2; while (pos) { segMul[pos] = segMul[2*pos] * segMul[2*pos+1]; if (segOF[2*pos] || segOF[2*pos+1] || segMul[pos] > OF) { segMul[pos] %= MOD; segOF[pos] = true; } pos /= 2; } } int getOFId(int i = 1, ll prod = 1) { if (i >= pow2) return i-pow2; if (segOF[2*i+1] || segMul[2*i+1] * prod >= OF) return getOFId(2*i+1, prod); return getOFId(2*i, prod * segMul[2*i+1]); } int getMulMod(int i) { int low = pow2, high = pow2+i; ll res = 1; while (low <= high) { if (low & 1) res = (res * segMul[low++]) % MOD; if (!(high & 1)) res = (res * segMul[high--]) % MOD; low /= 2; high /= 2; } return res % MOD; } int calc() { ll ofId = getOFId(); ll mx = y[ofId]; ll offCnt = getMulMod(ofId); ll tCnt = 1; ll mxRes = (y[ofId] * offCnt) % MOD; ofId++; if (!segOF[1]) { offCnt = 1; ofId = 0; mx = 0; } for (int i = ofId; i < n; i++) { offCnt *= x[i]; offCnt %= MOD; tCnt *= x[i]; ll val = tCnt * y[i]; if (val > mx) { mx = val; mxRes = (offCnt * y[i]) % MOD; } } return mxRes; } int init(int N, int X[], int Y[]) { n = N; pow2 = 1ll << (ll)ceil(log2(n)); x = vector<ll>(n); y = vector<ll>(n); for (int i = 0; i < n; i++) { x[i] = X[i]; y[i] = Y[i]; } segMul = vector<ll>(2*pow2, 1); segOF = vector<bool>(2*pow2); for (int i = 0; i < n; i++) { segMul[pow2+i] = X[i]; } for (int i = pow2-1; i > 0; i--) { segMul[i] = segMul[2*i] * segMul[2*i+1]; if (segOF[2*i] || segOF[2*i+1] || segMul[i] >= OF) { segMul[i] %= MOD; segOF[i] = true; } } return calc(); } int updateX(int pos, int val) { setX(pos, val); return calc(); } int updateY(int pos, int val) { y[pos] = val; return calc(); }
Compilation message
# | Verdict | Execution time | Memory | 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 | 360 KB | Output is correct |
7 | Correct | 0 ms | 348 KB | Output is correct |
8 | Correct | 0 ms | 348 KB | Output is correct |
9 | Correct | 1 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 | 344 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 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 | 344 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 | 344 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 | 1 ms | 344 KB | Output is correct |
24 | Correct | 1 ms | 348 KB | Output is correct |
25 | Incorrect | 0 ms | 348 KB | Output isn't correct |
26 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 45 ms | 21380 KB | Output is correct |
2 | Correct | 67 ms | 21336 KB | Output is correct |
3 | Correct | 43 ms | 21296 KB | Output is correct |
4 | Correct | 62 ms | 21316 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 348 KB | Output is correct |
2 | Correct | 1 ms | 348 KB | Output is correct |
3 | Correct | 1 ms | 344 KB | Output is correct |
4 | Correct | 0 ms | 348 KB | Output is correct |
5 | Correct | 0 ms | 348 KB | Output is correct |
6 | Correct | 1 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 | 1 ms | 344 KB | Output is correct |
24 | Correct | 1 ms | 344 KB | Output is correct |
25 | Incorrect | 0 ms | 348 KB | Output isn't correct |
26 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | 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 | 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 | 1 ms | 344 KB | Output is correct |
21 | Correct | 0 ms | 348 KB | Output is correct |
22 | Correct | 0 ms | 348 KB | Output is correct |
23 | Correct | 1 ms | 344 KB | Output is correct |
24 | Correct | 0 ms | 348 KB | Output is correct |
25 | Incorrect | 0 ms | 348 KB | Output isn't correct |
26 | Halted | 0 ms | 0 KB | - |