# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
984242 | 2024-05-16T11:59:00 Z | SmuggingSpun | Horses (IOI15_horses) | C++14 | 361 ms | 19916 KB |
#include "horses.h" #include<bits/stdc++.h> using namespace std; typedef long long ll; const int mod = 1e9 + 7; const int lim = 5e5 + 5; int power(int a, int b){ int ans = 1; for(; b > 0; b >>= 1, a = 1LL * a * a % mod){ if(b & 1){ ans = 1LL * ans * a % mod; } } return ans; } int n, st[lim << 2], x[lim], x_st[lim << 1], y[lim], bit[lim]; int get_bit(int p){ int ans = 1; for(; p > 0; p -= p & -p){ ans = 1LL * ans * bit[p] % mod; } return ans; } void update_bit(int p, int x){ for(; p <= n; p += p & -p){ bit[p] = 1LL * bit[p] * x % mod; } } int get_x_prod(int l, int r){ int res = 1; for(l += n, r += n + 1; l < r; l >>= 1, r >>= 1){ if(l & 1){ res = min(ll(mod), 1LL * res * x_st[l++]); } if(r & 1){ res = min(ll(mod), 1LL * res * x_st[--r]); } } return res; } void modify_x(int p, int X){ update_bit(p, 1LL * power(x[p], mod - 2) * (x_st[p + n] = X) % mod); for(p += n; p > 1; p >>= 1){ x_st[p >> 1] = min(ll(mod), 1LL * x_st[p] * x_st[p ^ 1]); } } int merge(int l, int r){ if(l == 0){ return r; } if(r == 0){ return l; } return 1LL * get_x_prod(l + 1, r) * y[r] < ll(y[l]) ? l : r; } void update_X(int id, int l, int r, int p, int X){ if(l == r){ x[st[id] = l] = X; modify_x(l, X); return; } int m = (l + r) >> 1; if(m < p){ update_X(id << 1 | 1, m + 1, r, p, X); } else{ update_X(id << 1, l, m, p, X); } st[id] = merge(st[id << 1], st[id << 1 | 1]); x_st[id] = min(ll(mod), 1LL * x_st[id << 1] * x_st[id << 1 | 1]); } void update_Y(int p, int Y){ y[p] = Y; int id = 1, l = 1, r = n; while(l < r){ int m = (l + r) >> 1; id <<= 1; if(m < p){ l = m + 1; id |= 1; } else{ r = m; } } while((id >>= 1) > 0){ st[id] = merge(st[id << 1], st[id << 1 | 1]); } } int init(int N, int X[], int Y[]){ n = N; fill(bit, bit + lim, 1); for(int i = 1; i <= n; i++){ y[i] = Y[i - 1]; update_bit(i, x[i] = X[i - 1]); } fill(x_st, x_st + (lim << 2), 1); for(int i = 1; i <= n; i++){ update_X(1, 1, n, i, X[i - 1]); } return 1LL * get_bit(st[1]) * y[st[1]] % mod; } int updateX(int pos, int val){ update_X(1, 1, n, pos + 1, val); return 1LL * get_bit(st[1]) * y[st[1]] % mod; } int updateY(int pos, int val){ update_Y(pos + 1, val); return 1LL * get_bit(st[1]) * y[st[1]] % mod; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 12892 KB | Output is correct |
2 | Correct | 3 ms | 12892 KB | Output is correct |
3 | Correct | 2 ms | 12892 KB | Output is correct |
4 | Correct | 2 ms | 12892 KB | Output is correct |
5 | Correct | 2 ms | 12892 KB | Output is correct |
6 | Correct | 2 ms | 12892 KB | Output is correct |
7 | Correct | 2 ms | 12892 KB | Output is correct |
8 | Correct | 3 ms | 12892 KB | Output is correct |
9 | Correct | 3 ms | 12888 KB | Output is correct |
10 | Correct | 2 ms | 12892 KB | Output is correct |
11 | Correct | 2 ms | 12908 KB | Output is correct |
12 | Correct | 3 ms | 12892 KB | Output is correct |
13 | Correct | 2 ms | 12912 KB | Output is correct |
14 | Correct | 2 ms | 12892 KB | Output is correct |
15 | Correct | 2 ms | 12892 KB | Output is correct |
16 | Correct | 2 ms | 12892 KB | Output is correct |
17 | Correct | 2 ms | 12888 KB | Output is correct |
18 | Correct | 2 ms | 12892 KB | Output is correct |
19 | Correct | 3 ms | 12892 KB | Output is correct |
20 | Correct | 3 ms | 12892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 12892 KB | Output is correct |
2 | Correct | 2 ms | 12908 KB | Output is correct |
3 | Correct | 2 ms | 12888 KB | Output is correct |
4 | Correct | 2 ms | 12892 KB | Output is correct |
5 | Correct | 2 ms | 12888 KB | Output is correct |
6 | Correct | 2 ms | 12888 KB | Output is correct |
7 | Correct | 2 ms | 12888 KB | Output is correct |
8 | Correct | 2 ms | 12892 KB | Output is correct |
9 | Correct | 3 ms | 12892 KB | Output is correct |
10 | Correct | 2 ms | 12892 KB | Output is correct |
11 | Correct | 3 ms | 12888 KB | Output is correct |
12 | Correct | 2 ms | 12892 KB | Output is correct |
13 | Correct | 2 ms | 12892 KB | Output is correct |
14 | Correct | 2 ms | 12892 KB | Output is correct |
15 | Correct | 3 ms | 12892 KB | Output is correct |
16 | Correct | 3 ms | 12892 KB | Output is correct |
17 | Correct | 2 ms | 12892 KB | Output is correct |
18 | Correct | 3 ms | 12892 KB | Output is correct |
19 | Correct | 2 ms | 12892 KB | Output is correct |
20 | Correct | 3 ms | 12892 KB | Output is correct |
21 | Incorrect | 2 ms | 12892 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 271 ms | 19916 KB | Output is correct |
2 | Incorrect | 361 ms | 19652 KB | Output isn't correct |
3 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 12892 KB | Output is correct |
2 | Correct | 2 ms | 12892 KB | Output is correct |
3 | Correct | 3 ms | 13144 KB | Output is correct |
4 | Correct | 2 ms | 12892 KB | Output is correct |
5 | Correct | 2 ms | 12892 KB | Output is correct |
6 | Correct | 2 ms | 12892 KB | Output is correct |
7 | Correct | 2 ms | 12892 KB | Output is correct |
8 | Correct | 3 ms | 12892 KB | Output is correct |
9 | Correct | 3 ms | 12892 KB | Output is correct |
10 | Correct | 3 ms | 12892 KB | Output is correct |
11 | Correct | 3 ms | 12892 KB | Output is correct |
12 | Correct | 2 ms | 12892 KB | Output is correct |
13 | Correct | 2 ms | 12892 KB | Output is correct |
14 | Correct | 2 ms | 12892 KB | Output is correct |
15 | Correct | 3 ms | 12892 KB | Output is correct |
16 | Correct | 2 ms | 12888 KB | Output is correct |
17 | Correct | 2 ms | 12892 KB | Output is correct |
18 | Correct | 3 ms | 12892 KB | Output is correct |
19 | Correct | 2 ms | 12892 KB | Output is correct |
20 | Correct | 2 ms | 12888 KB | Output is correct |
21 | Incorrect | 3 ms | 12892 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 12912 KB | Output is correct |
2 | Correct | 3 ms | 12924 KB | Output is correct |
3 | Correct | 3 ms | 12892 KB | Output is correct |
4 | Correct | 2 ms | 12928 KB | Output is correct |
5 | Correct | 2 ms | 12892 KB | Output is correct |
6 | Correct | 2 ms | 12892 KB | Output is correct |
7 | Correct | 3 ms | 12892 KB | Output is correct |
8 | Correct | 3 ms | 12892 KB | Output is correct |
9 | Correct | 3 ms | 12892 KB | Output is correct |
10 | Correct | 2 ms | 12892 KB | Output is correct |
11 | Correct | 2 ms | 12892 KB | Output is correct |
12 | Correct | 2 ms | 12892 KB | Output is correct |
13 | Correct | 2 ms | 12888 KB | Output is correct |
14 | Correct | 3 ms | 12892 KB | Output is correct |
15 | Correct | 2 ms | 12904 KB | Output is correct |
16 | Correct | 3 ms | 12888 KB | Output is correct |
17 | Correct | 2 ms | 12892 KB | Output is correct |
18 | Correct | 2 ms | 12888 KB | Output is correct |
19 | Correct | 2 ms | 12916 KB | Output is correct |
20 | Correct | 2 ms | 12892 KB | Output is correct |
21 | Incorrect | 3 ms | 12892 KB | Output isn't correct |
22 | Halted | 0 ms | 0 KB | - |