QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#233824 | #2788. Horses | Camillus# | 17 | 190ms | 14028kb | C++20 | 3.9kb | 2023-11-01 00:26:38 | 2024-07-04 02:22:11 |
Judging History
answer
#include "horses.h"
#include "bits/stdc++.h"
using ll = long long;
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 << 17;
namespace st0 {
int tree[maxn * 2 - 1];
void set(int i, int x = 0, int lx = 0, int rx = maxn) {
if (rx - lx == 1) {
tree[x] = lx;
return;
}
int mx = (lx + rx) / 2;
if (i < mx) {
set(i, x * 2 + 1, lx, mx);
} else {
set(i, x * 2 + 2, mx, rx);
}
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 l;
}
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 = 0, int lx = 0, int rx = maxn) {
if (rx - lx == 1) {
tree[x] = v;
return;
}
int mx = (lx + rx) / 2;
if (i < mx) {
set(i, v, x * 2 + 1, lx, mx);
} else {
set(i, v, x * 2 + 2, mx, rx);
}
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 INT32_MIN;
}
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 = 0, int lx = 0, int rx = maxn) {
if (rx - lx == 1) {
tree[x] = v;
return;
}
int mx = (lx + rx) / 2;
if (i < mx) {
set(i, v, x * 2 + 1, lx, mx);
} else {
set(i, v, x * 2 + 2, mx, rx);
}
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
int calc() {
vector<pair<int, int>> q;
{
ll cur = 1;
for (int r = n - 1; r >= 0;) {
int R = r + 1;
for (int j = 17; r >= 0 && j >= 0 && x[r] == 1; j--) {
if (R - (1 << j) >= 0 && st1::get(R - (1 << j), R) == 1) {
r -= (1 << j);
}
}
if (r == -1) {
r = 0;
}
cur *= x[r];
if (cur > 1e9) {
break;
} else {
q.emplace_back(r, st0::get(r, R));
}
r--;
}
}
reverse(q.begin(), q.end());
vector<pair<ll, int>> v;
for (ll 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 init(int N, int X[], int Y[]) {
n = N;
x = vector<int>(X, X + n);
y = vector<int>(Y, Y + n);
for (int i = 0; i < n; i++) {
st0::set(i);
st1::set(i, x[i]);
st2::set(i, x[i]);
}
return calc();
}
int updateX(int pos, int val) {
x[pos] = val;
st1::set(pos, val);
st2::set(pos, val);
return calc();
}
int updateY(int pos, int val) {
y[pos] = val;
st0::set(pos);
return calc();
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 17
Accepted
Test #1:
score: 17
Accepted
time: 0ms
memory: 3756kb
input:
1 2 3 0
output:
6
result:
ok single line: '6'
Test #2:
score: 17
Accepted
time: 0ms
memory: 3756kb
input:
10 2 1 1 5 2 1 1 10 5 1 3 5 7 9 4 1 4 10 10 9 0
output:
10000
result:
ok single line: '10000'
Test #3:
score: 17
Accepted
time: 0ms
memory: 5812kb
input:
10 10 10 10 1 1 1 1 1 1 1 2 3 4 2 7 6 5 4 3 2 0
output:
7000
result:
ok single line: '7000'
Test #4:
score: 17
Accepted
time: 1ms
memory: 3756kb
input:
10 9 1 1 1 1 1 1 1 1 2 4 1 1 1 1 1 1 1 1 2 0
output:
36
result:
ok single line: '36'
Test #5:
score: 17
Accepted
time: 0ms
memory: 3764kb
input:
10 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 6 7 8 9 10 0
output:
10
result:
ok single line: '10'
Test #6:
score: 17
Accepted
time: 1ms
memory: 3764kb
input:
10 1 1 1 1 1 1 1 1 1 1 10 9 8 7 6 5 4 3 2 1 0
output:
10
result:
ok single line: '10'
Test #7:
score: 17
Accepted
time: 0ms
memory: 3880kb
input:
10 10 10 10 1 1 1 1 1 1 1 10 10 2 3 4 5 6 7 8 9 0
output:
9000
result:
ok single line: '9000'
Test #8:
score: 17
Accepted
time: 0ms
memory: 5800kb
input:
10 10 10 10 1 1 1 1 1 1 1 10 10 9 8 7 6 5 4 3 2 0
output:
9000
result:
ok single line: '9000'
Test #9:
score: 17
Accepted
time: 0ms
memory: 3756kb
input:
10 1 1 1 1 2 2 1 1 1 1 8 8 8 8 1 1 2 2 2 2 0
output:
8
result:
ok single line: '8'
Test #10:
score: 17
Accepted
time: 0ms
memory: 3876kb
input:
10 1 1 1 1 1 1 1 1 1 1 1 2 3 4 5 9 8 7 6 1 0
output:
9
result:
ok single line: '9'
Test #11:
score: 17
Accepted
time: 0ms
memory: 5832kb
input:
2 2 5 9 7 0
output:
70
result:
ok single line: '70'
Test #12:
score: 17
Accepted
time: 1ms
memory: 6028kb
input:
1 1 1 0
output:
1
result:
ok single line: '1'
Test #13:
score: 17
Accepted
time: 0ms
memory: 4068kb
input:
7 7 1 1 6 2 3 2 7 6 5 4 3 7 1 0
output:
1764
result:
ok single line: '1764'
Test #14:
score: 17
Accepted
time: 0ms
memory: 3760kb
input:
1 10 10 0
output:
100
result:
ok single line: '100'
Test #15:
score: 17
Accepted
time: 0ms
memory: 3760kb
input:
2 1 4 7 2 0
output:
8
result:
ok single line: '8'
Test #16:
score: 17
Accepted
time: 0ms
memory: 3844kb
input:
10 1 10 1 10 1 1 10 1 1 1 7 3 10 10 4 10 1 4 5 10 0
output:
10000
result:
ok single line: '10000'
Test #17:
score: 17
Accepted
time: 1ms
memory: 4056kb
input:
6 1 1 1 1 1 1 1 1 1 1 1 1 0
output:
1
result:
ok single line: '1'
Test #18:
score: 17
Accepted
time: 0ms
memory: 3760kb
input:
4 1 2 4 8 8 4 2 1 0
output:
64
result:
ok single line: '64'
Test #19:
score: 17
Accepted
time: 1ms
memory: 5800kb
input:
6 1 2 2 3 1 1 7 1 1 2 1 1 0
output:
24
result:
ok single line: '24'
Test #20:
score: 17
Accepted
time: 1ms
memory: 5956kb
input:
10 2 1 1 5 2 1 1 10 5 1 3 5 7 9 4 1 4 10 7 9 0
output:
9000
result:
ok single line: '9000'
Subtask #2:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Test #21:
score: 17
Accepted
time: 1ms
memory: 3820kb
input:
10 10 10 10 10 10 10 1 1 1 1 1 1 1 1 9 5 4 7 3 2 5 1 5 1 2 5 123456789 1 5 1 1 8 987654321 1 9 777777777
output:
7000000 900000 678813585 678813585 294225928 75803567
result:
ok 6 lines
Test #22:
score: 0
Wrong Answer
time: 1ms
memory: 5736kb
input:
10 3 2 7 5 11 13 107 23 51 3 1 1 1 1 1000000000 1 1 1 1 1 16 1 1 1 1 2 1 1 0 1 1 8 1 1 7 1 1 9 1 1 1 25 1 8 123456789 1 4 1 1 6 1 1 3 1 1 5 1 1 5 12345 1 6 123456 1 7 1234567 2 4 3
output:
999983837 999991922 999998852 999999622 999999622 999999622 999999622 999990382 539408243 49037113 617280725 123456145 86419704 851238418 489396978 354709175 354709175
result:
wrong answer 13th lines differ - expected: '999999832', found: '86419704'
Subtask #3:
score: 0
Wrong Answer
Test #33:
score: 0
Wrong Answer
time: 190ms
memory: 14028kb
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:
125655169 125655169 125655169 751434861 443153763 443153763 443153763 443153763 443153763 247787127 383655330 383655330 383655330 383655330 383655330 841433545 841433545 841433545 841433545 841433545 417301412 417301412 417301412 417301412 417301412 896106800 896106800 896106800 896106800 896106800 ...
result:
wrong answer 1st lines differ - expected: '967631222', found: '125655169'
Subtask #4:
score: 0
Skipped
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%