QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#233856 | #2788. Horses | Camillus# | 0 | 213ms | 24212kb | C++20 | 4.0kb | 2023-11-01 01:19:50 | 2024-07-04 02:50:47 |
Judging History
answer
#pragma GCC optimize("Ofast")
#include "horses.h"
#include "bits/stdc++.h"
using ll = long long;
using i128 = __int128;
using namespace std;
struct mint {
static constexpr int mod = 1e9 + 7;
int data = 0;
mint() = default;
mint(int data) : data(data) {}
mint operator+(const mint &other) const {
int res = data + other.data;
if (res >= mod) {
res -= mod;
}
return res;
}
mint operator-(const mint &other) const {
int res = data + mod - other.data;
if (res >= mod) {
res -= mod;
}
return res;
}
mint operator*(const mint &other) const {
return mint(1ll * data * other.data % mod);
}
};
int n;
vector<int> X, Y;
constexpr int maxn = 1 << 19;
namespace st0 {
int tree[maxn * 2 - 1];
void set(int i) {
int x = maxn + i - 1;
tree[x] = i;
while (x) {
x = (x - 1) / 2;
if (Y[tree[x * 2 + 1]] > Y[tree[x * 2 + 2]]) {
tree[x] = tree[x * 2 + 1];
} else {
tree[x] = tree[x * 2 + 2];
}
}
}
int get(int l, int r, int x = 0, int lx = 0, int rx = maxn) {
if (l <= lx && rx <= r) {
return tree[x];
}
if (l >= rx || lx >= r) {
return n;
}
int mx = (lx + rx) / 2;
int i = get(l, r, x * 2 + 1, lx, mx);
int j = get(l, r, x * 2 + 2, mx, rx);
if (Y[i] > Y[j]) {
return i;
} else {
return j;
}
}
} // namespace st0
namespace st1 {
int tree[maxn * 2 - 1];
void set(int i, int v) {
int x = maxn + i - 1;
tree[x] = v;
while (x) {
x = (x - 1) / 2;
tree[x] = max(tree[x * 2 + 1], tree[x * 2 + 2]);
}
}
int get(int l, int r, int x = 0, int lx = 0, int rx = maxn) {
if (l <= lx && rx <= r) {
return tree[x];
}
if (l >= rx || lx >= r) {
return 1;
}
return max(
get(l, r, x * 2 + 1, lx, (lx + rx) / 2),
get(l, r, x * 2 + 2, (lx + rx) / 2, rx)
);
}
} // namespace st1
namespace st2 {
mint tree[maxn * 2 - 1];
void set(int i, int v) {
int x = maxn + i - 1;
tree[x] = v;
while (x) {
x = (x - 1) / 2;
tree[x] = tree[x * 2 + 1] * tree[x * 2 + 2];
}
}
mint get(int l, int r, int x = 0, int lx = 0, int rx = maxn) {
if (l <= lx && rx <= r) {
return tree[x];
}
if (l >= rx || lx >= r) {
return 1;
}
return get(l, r, x * 2 + 1, lx, (lx + rx) / 2) * get(l, r, x * 2 + 2, (lx + rx) / 2, rx);
}
} // namespace st2
constexpr i128 INF = 1ll * mint::mod * mint::mod;
set<pair<int, int>> Q;
int calc() {
vector<pair<int, int>> q;
{
i128 cur = 1;
for (auto it = prev(Q.end()); ; it--) {
int r = it->first;
cur *= X[r];
if (cur > INF) {
break;
} else {
q.emplace_back(r, st0::get(r, r + it->second));
}
if (it == Q.begin()) {
break;
}
}
}
reverse(q.begin(), q.end());
vector<pair<i128, int>> v;
for (i128 cur = 1; auto [a, b] : q) {
cur *= X[a];
v.emplace_back(cur * Y[b], b);
}
int pos = max_element(v.begin(), v.end())->second;
return (st2::get(0, pos + 1) * Y[pos]).data;
}
int updateX(int pos, int val) {
if (X[pos] == val) {
return calc();
}
if (X[pos] == 1) {
auto it = Q.upper_bound(make_pair(pos, 0));
it = prev(it);
int r = it->first + it->second;
Q.emplace(it->first, pos - it->first);
Q.erase(it);
Q.emplace(pos, r - pos);
} else if (val == 1 && pos != 0) {
auto it = Q.lower_bound(make_pair(pos, 0));
int r = it->first + it->second;
it = prev(it);
Q.erase(next(it));
Q.emplace(it->first, r - it->first);
Q.erase(it);
}
X[pos] = val;
st2::set(pos, val);
return calc();
}
int updateY(int pos, int val) {
Y[pos] = val;
st0::set(pos);
return calc();
}
int init(int N, int _X[], int _Y[]) {
n = N;
Q.emplace(0, n);
X = vector<int>(_X, _X + n);
Y = vector<int>(_Y, _Y + n);
Y.push_back(0);
int last;
for (int i = 0; i < n; i++) {
last = updateX(i, X[i]);
st0::set(i);
st1::set(i, X[i]);
st2::set(i, X[i]);
}
return last;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 7920kb
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: 213ms
memory: 24212kb
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:
2 867564495 795463654 795463654 795463654 795463654 795463654 885679347 618832158 582471866 864166718 616649396 616649396 616649396 616649396 616649396 813424701 813424701 813424701 59958004 59958004 59958004 59958004 59958004 384797334 384797334 384797334 384797334 384797334 366790562 335613627 335...
result:
wrong answer 1st lines differ - expected: '967631222', found: '2'
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%