QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#722077 | #5543. The Only Mode | xuxuxuxuxu# | WA | 1ms | 5640kb | C++14 | 3.3kb | 2024-11-07 17:42:04 | 2024-11-07 17:42:07 |
Judging History
answer
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
using std::cin;
using std::cout;
using i64 = long long;
const int nx = 1e5;
int n;
int a[nx + 5];
int bid[4], b[4][nx + 5];
int r0[nx + 5], r1[nx + 5], r2[nx + 5];
bool vis[nx + 5];
int ans[nx + 5];
struct BIT {
int lim;
int c[nx * 2 + 10];
int lb(int x) {
return (x & (-x));
}
void upd(int x, int k) {
while (x <= lim) {
c[x] = std::min(c[x], k);
x += lb(x);
}
}
void cov(int x, int k) {
while (x <= lim) {
c[x] = k;
x += lb(x);
}
}
int qry(int x) {
int res = n + 1;
while (x) {
res = std::min(res, c[x]);
x -= lb(x);
}
return res;
}
}t0;
void cdq1(int l, int r) {
if (l >= r) return;
int mid = (l + r) >> 1;
cdq1(l, mid), cdq1(mid + 1, r);
int pl = l, pr = mid + 1, p1 = l - 1, mi = n + 1;
while (pl <= mid && pr <= r) {
if (b[2][r1[pl]] < b[2][r1[pr]]) {
r2[++p1] = r1[pl++];
if (!vis[r2[p1]]) mi = std::min(mi, r2[p1]);
}else {
r2[++p1] = r1[pr++];
if (vis[r2[p1]])
ans[r2[p1]] = std::min(ans[r2[p1]], mi);
}
}
while (pl <= mid) r2[++p1] = r1[pl++];
while (pr <= r) {
r2[++p1] = r1[pr++];
if (vis[r2[p1]])
ans[r2[p1]] = std::min(ans[r2[p1]], mi);
}
for (int i = l; i <= r; ++i) {
r1[i] = r2[i];
if (!vis[r1[i]]) t0.cov(b[3][r1[i]] + 1 + n + 5, n + 1);
}
}
void cdq0(int l, int r) {
if (l >= r) return;
int mid = (l + r) >> 1;
cdq0(l, mid), cdq0(mid + 1, r);
int pl = l, pr = mid + 1, p1 = l - 1;
while (pl <= mid && pr <= r) {
if (b[1][r0[pl]] < b[1][r0[pr]]) r1[++p1] = r0[pl++], vis[r1[p1]] = false;
else r1[++p1] = r0[pr++], vis[r1[p1]] = true;
}
while (pl <= mid) {
r1[++p1] = r0[pl++];
vis[r1[p1]] = false;
}
while (pr <= r) {
r1[++p1] = r0[pr++];
vis[r1[p1]] = true;
}
for (int i = l; i <= r; ++i) r0[i] = r1[i];
cdq1(l, r);
}
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; ++i) cin >> a[i], r0[i] = i, ans[i] = n + 1;
t0.lim = n + n + 6;
for (int i = 0; i <= t0.lim; ++i) t0.c[i] = n + 1;
for (int k = 0; k < 4; ++k) {
int bidn = 0;
for (int i = 0; i < 4; ++i) if (i != k) bid[i] = bidn++;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j < 3; ++j) b[j][i] = 0;
if (a[i] == k) {
for (int j = 0; j < 3; ++j) b[j][i] = 1;
}else b[bid[a[i]]][i] = -1;
}
for (int i = 0; i < 3; ++i) {
for (int j = 1; j <= n; ++j) b[i][j] += b[i][j - 1];
}
std::sort(r0, r0 + n + 1, [&](int x, int y) {
return b[0][x] < b[0][y];
});
cdq0(0, n);
; int res = 0;
for (int i = 1; i <= n; ++i) {
if (ans[i] <= i) res = std::max(res, i - ans[i]);
ans[i] = n + 1;
}
cout << res << " ";
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 5640kb
input:
7 1 2 2 0 3 0 3
output:
4 1 5 5
result:
wrong answer 1st lines differ - expected: '4 1 5 3', found: '4 1 5 5 '