QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#124300 | #2788. Horses | valerikk# | 0 | 303ms | 62400kb | C++17 | 2.2kb | 2023-07-14 16:42:58 | 2024-07-04 00:39:44 |
Judging History
answer
#include "horses.h"
#include <bits/stdc++.h>
using namespace std;
namespace {
typedef long long ll;
const int N = 5e5 + 7;
const ll md = 1e9 + 7;
const ll INF = 1e18;
ll mul(ll a, ll b) {
return a <= INF / b ? a * b : INF;
}
int n;
int x[N], y[N];
struct node {
ll pref, suf, prod, prodmd, ans;
bool neut;
};
node merge(const node &l, const node &r) {
if (l.neut) {
return r;
}
if (r.neut) {
return l;
}
node ret;
ret.prod = mul(l.prod, r.prod);
ret.prodmd = l.prodmd * r.prodmd % md;
ret.pref = max(l.pref, mul(r.pref, l.prod));
ret.suf = max(r.suf, mul(l.suf, r.prod));
ret.ans = max({l.ans, r.ans, mul(l.suf, r.pref)});
ret.neut = 0;
return ret;
}
node t[4 * N];
void build(int v, int tl, int tr) {
if (tr - tl == 1) {
t[v].pref = mul(x[tl], y[tl]);
t[v].suf = x[tl];
t[v].prod = x[tl];
t[v].prodmd = x[tl];
t[v].ans = mul(x[tl], y[tl]);
t[v].neut = 0;
return;
}
int tm = (tl + tr) / 2;
build(2 * v, tl, tm);
build(2 * v + 1, tm, tr);
t[v] = merge(t[2 * v], t[2 * v + 1]);
}
void upd(int v, int tl, int tr, int pos) {
if (tr - tl == 1) {
t[v].pref = mul(x[tl], y[tl]);
t[v].suf = x[tl];
t[v].prod = x[tl];
t[v].prodmd = x[tl];
t[v].ans = mul(x[tl], y[tl]);
return;
}
int tm = (tl + tr) / 2;
if (pos < tm) {
upd(2 * v, tl, tm, pos);
} else {
upd(2 * v + 1, tm, tr, pos);
}
t[v] = merge(t[2 * v], t[2 * v + 1]);
}
node get(int v, int tl, int tr, int l, int r) {
if (tl >= r || tr <= l) {
return {0, 0, 0, 0, 0, 1};
}
if (tl >= l && tr <= r) {
return t[v];
}
int tm = (tl + tr) / 2;
return merge(get(2 * v, tl, tm, l, r), get(2 * v + 1, tm, tr, l, r));
}
ll getans() {
int l = -1, r = n;
while (r - l > 1) {
int mid = (l + r) / 2;
if (get(1, 0, n, mid, n).ans > 1e9) {
l = mid;
} else {
r = mid;
}
}
return get(1, 0, n, r, n).ans % md * get(1, 0, n, 0, r).prodmd % md;
}
}
int init(int grdn, int grdx[], int grdy[]) {
n = grdn;
for (int i = 0; i < n; ++i) {
x[i] = grdx[i];
y[i] = grdy[i];
}
build(1, 0, n);
return getans();
}
int updateX(int pos, int val) {
x[pos] = val;
upd(1, 0, n, pos);
return getans();
}
int updateY(int pos, int val) {
y[pos] = val;
upd(1, 0, n, pos);
return getans();
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7864kb
input:
1 2 3 0
output:
0
result:
wrong answer 1st lines differ - expected: '6', found: '0'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 303ms
memory: 62400kb
input:
500000 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2...
output:
967631222 967631222 967631222 967631222 967631222 501991144 501991144 501991144 501991144 501991144 967631222 967631222 967631222 967631222 967631222 967631222 967631222 967631222 967631222 967631222 967631222 967631222 967631222 967631222 967631222 967631222 967631222 967631222 967631222 967631222 ...
result:
wrong answer 3rd lines differ - expected: '795463654', found: '967631222'
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%