QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#816044 | #9865. Dolls | Deltax | WA | 4ms | 10032kb | C++14 | 2.5kb | 2024-12-15 21:14:18 | 2024-12-15 21:14:30 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
x = 0; int f = 1;
char c = getchar();
while (!isdigit(c)) {if (c == '-') f = -f; c = getchar();}
while (isdigit(c)) x = (x << 1) + (x << 3) + (c & 15), c = getchar();
x = x * f;
}
const int MAXN = 1e5;
int a[MAXN + 10];
int mx[20][MAXN + 10], mn[20][MAXN + 10];
void build(int n) {
for (int i = 1; i <= n; ++i)
mn[0][i] = mx[0][i] = a[i];
for (int j = 1; j <= 18; ++j)
for (int i = 1; i + (1 << j) - 1 <= n; ++i) {
mn[j][i] = min(mn[j - 1][i], mn[j - 1][i + (1 << j - 1)]);
mx[j][i] = max(mx[j - 1][i], mx[j - 1][i + (1 << j - 1)]);
}
}
int qmin(int l, int r) {
int k = __lg(r - l + 1);
return min(mn[k][l], mn[k][r - (1 << k) + 1]);
}
int qmax(int l, int r) {
int k = __lg(r - l + 1);
return max(mx[k][l], mx[k][r - (1 << k) + 1]);
}
inline int merge(int l, int mid, int r) {
int mn1 = qmin(l, mid), mn2 = qmin(mid + 1, r);
int mx1 = qmax(l, mid), mx2 = qmax(mid + 1, r);
if (mn1 > mx2 || mx1 < mn2) return 1;
return 0;
}
bool chk(int L, int R) {
static int p[MAXN + 10];
int top = 0;
for (int i = L; i <= R; ++i)
p[++top] = i;
while (top > 1) {
for (int i = 1; i + 1 <= top; i += 2) {
int l = p[i], mid = p[i + 1] - 1, r = i + 2 > top? R : p[i + 2] - 1;
while (l <= mid && mid + 1 <= r) {
int pl = l, pr = r;
int ok = 0;
while (pl <= mid && pr >= mid + 1) {
if (pl <= mid) {
if (merge(l, pl, r)) {
ok = 1;
break;
}
++pl;
}
if (pr >= mid) {
if (merge(l, pr - 1, r)) {
ok = 2;
break;
}
--pr;
}
}
if (!ok) return 0;
if (ok == 1) l = pl + 1;
else r = pr - 1;
}
}
int tot = 0;
for (int i = 1; i <= top; i += 2)
p[++tot] = p[i];
top = tot;
}
return 1;
}
int main() {
//freopen ("std.in", "r", stdin);
//freopen ("std.out", "w", stdout);
int T; read(T);
while (T--) {
int n; read(n);
for (int i = 1; i <= n; ++i)
read(a[i]);
build(n);
//cerr << qmin(1, 4) << endl;
//cerr << chk(1, 4) << endl;
int l = 1, ans = 0;
while (l <= n) {
int r = l;
while (r < n) {
int rr = r + (r - l + 1);
if (chk(l, rr)) r = rr;
else break;
}
int r1 = r, r2 = min(r + (r - l + 1) - 1, n), res = r1;
while (r1 <= r2) {
int mid = r1 + r2 >> 1;
if (chk(l, mid)) r1 = (res = mid) + 1;
else r2 = mid - 1;
}
++ans;
l = res + 1;
}
printf("%d\n", n - ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5768kb
input:
8 4 2 1 4 3 4 1 4 2 3 4 3 1 4 2 5 1 3 5 2 4 5 1 4 2 5 3 5 2 5 3 1 4 6 1 3 6 5 2 4 6 2 5 1 3 6 4
output:
3 3 2 3 3 3 4 4
result:
ok 8 numbers
Test #2:
score: -100
Wrong Answer
time: 4ms
memory: 10032kb
input:
5913 1 1 2 1 2 2 2 1 3 1 2 3 3 1 3 2 3 2 1 3 3 2 3 1 3 3 1 2 3 3 2 1 4 1 2 3 4 4 1 2 4 3 4 1 3 2 4 4 1 3 4 2 4 1 4 2 3 4 1 4 3 2 4 2 1 3 4 4 2 1 4 3 4 2 3 1 4 4 2 3 4 1 4 2 4 1 3 4 2 4 3 1 4 3 1 2 4 4 3 1 4 2 4 3 2 1 4 4 3 2 4 1 4 3 4 1 2 4 3 4 2 1 4 4 1 2 3 4 4 1 3 2 4 4 2 1 3 4 4 2 3 1 4 4 3 1 2 4...
output:
0 1 1 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 3 2 3 3 2 3 3 3 3 3 3 3 3 3 3 4 4 4 4 4 4 4 3 4 4 3 4 4 3 4 4 3 4 4 4 4 4 4 4 4 3 4 3 3 3 4 3 4 4 3 4 3 3 4 4 3 4 3 3 3 4 3 4 4 3 3 3 3 3 4 3 4 4 3 4 4 3 4 4 3 4 3 3 3 3 3 4 4 3 4 3 3 3 4 3 4 4 3 3 4 3 4 4 3 4 3 3 3 4 3 4 4 4 4 4 4 4 4 3 4 4 3 4 4 3 4 4 3 4 4 4 4 ...
result:
wrong answer 41st numbers differ - expected: '4', found: '3'