# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
996424 | phoenix | 말 (IOI15_horses) | C++17 | 227 ms | 41556 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
// #include "horses.h"
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
const int N = (1 << 19);
int n;
ll y[N];
int mx[2 * N];
struct Z {
bool over = 0;
ll x = 1;
};
Z t[2 * N];
void updX(int pos, int val) {
for(t[pos += N].x = val; pos > 1; pos >>= 1) {
t[pos >> 1].over = (t[pos].over | t[(pos ^ 1)].over | (t[pos].x * t[(pos ^ 1)].x >= MOD));
t[pos >> 1].x = (t[pos].x * t[(pos ^ 1)].x) % MOD;
}
}
Z get(int ql, int qr) {
Z res;
for(ql += N, qr += N + 1; ql < qr; ql >>= 1, qr >>= 1) {
if(ql & 1) {
res.over = (res.over | t[ql].over | (res.x * t[ql].x >= MOD));
res.x = (res.x * t[ql].x) % MOD;
ql++;
}
if(qr & 1) {
qr--;
res.over = (res.over | t[qr].over | (res.x * t[qr].x >= MOD));
res.x = (res.x * t[qr].x) % MOD;
}
}
return res;
}
void build(int l = 0, int r = N - 1, int v = 1) {
if(l == r) {
mx[v] = l;
return;
}
int m = (l + r) / 2;
build(l, m, 2 * v);
build(m + 1, r, 2 * v + 1);
Z x = get(mx[2 * v] + 1, mx[2 * v + 1]);
mx[v] = mx[2 * v + (x.over || x.x * y[mx[2 * v + 1]] >= y[mx[2 * v]])];
}
void update(int pos) {
for(pos += N, pos >>= 1; pos; pos >>= 1) {
Z x = get(mx[2 * pos] + 1, mx[2 * pos + 1]);
mx[pos] = mx[2 * pos + (x.over || x.x * y[mx[2 * pos + 1]] >= y[mx[2 * pos]])];
}
}
int init(int N, int X[], int Y[]) {
n = N;
for(int i = 0; i < n; i++) {
y[i] = Y[i];
updX(i, X[i]);
}
build();
return (y[mx[1]] * get(0, mx[1]).x) % MOD;
}
int updateX(int pos, int val) {
updX(pos, val);
update(pos);
return (y[mx[1]] * get(0, mx[1]).x) % MOD;
}
int updateY(int pos, int val) {
y[pos] = val;
update(pos);
return (y[mx[1]] * get(0, mx[1]).x) % MOD;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |