QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#268508 | #7043. Image Processing | 8BQube# | WA | 368ms | 168444kb | C++20 | 2.5kb | 2023-11-28 18:03:32 | 2023-11-28 18:03:32 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define X first
#define Y second
#define pb push_back
#define ALL(v) v.begin(), v.end()
#define SZ(a) ((int)a.size())
const int INF = 2e9 + 1;
int mx[1000005][20], mn[1000005][20];
int dp[1000005], boss[1000005];
int range(int l, int r) {
//cerr << "range " << l << " " << r << "\n";
assert(l <= r);
int lg = __lg(r - l + 1);
int mx_val = max(mx[r][lg], mx[l + (1 << lg) - 1][lg]);
int mn_val = min(mn[r][lg], mn[l + (1 << lg) - 1][lg]);
return mx_val - mn_val;
}
int finds(int x) {
if (x == boss[x]) return x;
return boss[x] = finds(boss[x]);
}
int main() {
ios::sync_with_stdio(0), cin.tie(0);
int n, k, c0 = 0;
cin >> n >> k;
int L = __lg(n);
vector<int> stk;
fill_n(mx[0], L, -1);
fill_n(mn[0], L, INF);
iota(boss, boss + n + 1, 0);
for (int i = 1; i <= n; ++i) {
int x;
cin >> x, x ^= c0;
mx[i][0] = mn[i][0] = x;
for (int j = 1; j <= L && i >= (1 << j); ++j) {
mx[i][j] = max(mx[i][j - 1], mx[i - (1 << (j - 1))][j - 1]);
mn[i][j] = min(mn[i][j - 1], mn[i - (1 << (j - 1))][j - 1]);
//cerr << "mx " << i << " " << j << " = " << mx[i][j] << "\n";
//cerr << "mn " << i << " " << j << " = " << mn[i][j] << "\n";
}
auto check1 = [&](int mid) {
int lb = finds(mid);
return (lb == 0 || lb >= k) && dp[lb] <= range(mid + 1, i);
};
auto check2 = [&](int mid) {
return range(stk[mid] + 1, i) <= dp[stk[mid]];
};
if (i >= k) {
if (i - k >= k || i == k) {
while (!stk.empty() && dp[stk.back()] >= dp[i - k]) {
boss[finds(stk.back())] = i - k;
stk.pop_back();
}
stk.pb(i - k);
}
{
int l = 0, r = i - k;
while (l < r) {
int mid = (l + r + 1) >> 1;
if (check1(mid)) l = mid;
else r = mid - 1;
}
dp[i] = range(l + 1, i);
}
{
int l = 0, r = SZ(stk) - 1;
while (l < r) {
int mid = (l + r) >> 1;
if (check2(mid)) r = mid;
else l = mid + 1;
}
dp[i] = max(dp[i], dp[stk[l]]);
}
}
cout << (c0 = dp[i]) << "\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7492kb
input:
5 2 50 110 190 120 34
output:
0 60 80 90 80
result:
ok 5 number(s): "0 60 80 90 80"
Test #2:
score: -100
Wrong Answer
time: 368ms
memory: 168444kb
input:
1000000 7 740760744 128949015 864430306 803157027 867410355 348411907 788815333 62537628 989888355 897434632 893725957 385915358 116671606 91645858 585889989 81062060 177182250 543069056 107482294 981936827 433021299 764779421 730485811 37353026 476269126 318260875 564753383 841579792 652031776 3016...
output:
0 0 0 0 0 0 738461340 738461340 738461340 738461340 738461340 861209643 861209643 861209643 861209643 861209643 861209643 861209643 861209643 861209643 861209643 861209643 861209643 861209643 861209643 861209643 861209643 868257634 868257634 868257634 868257634 868257634 868257634 868257634 86825763...
result:
wrong answer 14th numbers differ - expected: '738461340', found: '861209643'