# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
380063 | idk321 | Horses (IOI15_horses) | C++11 | 1585 ms | 12936 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 "horses.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int N = 500000;
const int R = 710;
int n;
int* x;
int* y;
int best[R];
ll left1[R][R];
ll right1[R][R];
void spMod(ll& num)
{
if (num >= mod)
{
num %= mod;
num += mod;
}
}
ll getBest()
{
ll cbest = left1[0][best[0]] % mod;
cbest *= y[best[0]];
cbest %= mod;
int ci = best[0];
ll fac = 1;
if (ci != min(R - 1, n - 1)) fac *= right1[0][ci + 1];
spMod(fac);
ll facAll = left1[0][min(R - 1, n - 1)];
facAll %= mod;
for (int a = R; a < n; a += R)
{
int i = best[a / R];
fac *= left1[a / R][i % R];
spMod(fac);
facAll *= left1[a / R][i % R];
facAll %= mod;
if (fac * y[i] > y[ci])
{
cbest = facAll * y[i];
cbest %= mod;
ci = i;
fac = 1;
}
if (i + 1 != min(n - 1, a + R - 1))
{
fac *= right1[a / R][(i + 1) % R];
spMod(fac);
facAll *= right1[a / R][(i + 1) % R];
facAll %= mod;
}
}
return cbest;
}
void makeBlock(int block)
{
int ci = block * R;
ll fac = 1;
for (int i = block * R + 1; i < min(n - 1, (block + 1) * R); i++)
{
fac *= x[i];
spMod(fac);
if (fac > y[ci] || fac * y[i] > y[ci])
{
ci = i;
fac = 1;
}
}
fac = 1;
for (int i = 0; i < R; i++)
{
if (i + block * R >= n) continue;
fac *= x[i + block * R];
spMod(fac);
left1[block][i] = fac;
}
fac = 1;
for (int i = R - 1; i >= 0; i--)
{
if (i + block * R >= n) continue;
fac *= x[i + block * R];
spMod(fac);
right1[block][i] = fac;
}
best[block] = ci;
}
int init(int N, int X[], int Y[]) {
n = N;
x = X;
y = Y;
for (int a = 0; a < R && a * R < n; a++)
{
makeBlock(a);
}
//cout << best[0] << endl;
return getBest() % mod;
}
int updateX(int pos, int val) {
x[pos] = val;
makeBlock(pos / R);
return getBest() % mod;
}
int updateY(int pos, int val) {
y[pos] = val;
makeBlock(pos / R);
return getBest() % 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... |