QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#252774 | #7685. Barkley II | luyiming123 | WA | 68ms | 22184kb | C++14 | 1.6kb | 2023-11-16 10:54:02 | 2023-11-16 10:54:04 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 5;
int n, m;
int a[N], b[N], L;
int pre[N];
struct node
{
int l, Mex;
};
vector <node> Seg[N];
struct BIT
{
int c[N];
int lowbit(int x) { return x & (-x); }
void clear(void) {for(int i = 0; i <= n + 1; i++) c[i] = 0; return; }
void add(int x, int d = 1)
{
while(x <= n + 1) c[x] += d, x += lowbit(x);
return;
}
int query(int x)
{
int ans = 0;
while(x) ans += c[x], x -= lowbit(x); return ans;
}
void update(int l, int r) {add(l, 1), add(r + 1, -1); return; }
}T;
int main(void)
{
int Test; scanf("%d", &Test);
while(Test--)
{
scanf("%d%d", &n, &m);
L = 0;
for(int i = 1; i <= n; i++) scanf("%d", &a[i]), b[++L] = a[i], b[++L] = a[i] + 1;
sort(b + 1, b + L + 1); L = unique(b + 1, b + L + 1) - b - 1;
for(int i = 1; i <= L; i++) pre[i] = 0;
for(int i = 1; i <= n; i++) Seg[i].clear();
for(int i = 1; i <= n; i++)
{
a[i] = lower_bound(b + 1, b + L + 1, a[i]) - b;
if(!pre[a[i]] && 1 <= i - 1) Seg[i - 1].push_back({1, a[i]});
else if(pre[a[i]] + 1 <= i - 1) Seg[i - 1].push_back({pre[a[i]] + 1, a[i]});
pre[a[i]] = i;
}
for(int i = 1; i <= L; i++)
{
if(pre[i] + 1 <= n) Seg[n].push_back({pre[i] + 1, i});
}
for(int i = 1; i <= L; i++) pre[i] = 0;
T.clear();
int ans = -1e9;
for(int r = 1; r <= n; r++)
{
T.update(pre[a[r]] + 1, r); pre[a[r]] = r;
for(auto I : Seg[r])
{
ans = max(ans, T.query(I.l) - b[I.Mex]);
}
}
printf("%d\n", ans);
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 22184kb
input:
2 5 4 1 2 2 3 4 5 10000 5 2 3 4 1
output:
2 3
result:
ok 2 number(s): "2 3"
Test #2:
score: -100
Wrong Answer
time: 68ms
memory: 20176kb
input:
50000 10 19 12 6 1 12 11 15 4 1 13 18 10 8 8 7 6 7 6 2 2 3 4 8 10 6 3 2 6 6 5 2 3 4 5 6 10 11 6 3 7 9 2 1 2 10 10 4 10 6 6 1 2 6 1 1 3 4 2 1 10 9 8 5 3 9 1 7 5 5 1 1 10 5 1 4 3 2 5 4 5 3 5 2 10 14 3 8 12 10 4 2 3 13 7 3 10 14 5 5 12 2 8 1 13 9 8 5 10 7 5 5 6 6 1 5 3 7 3 4 10 7 5 1 4 6 1 6 4 3 7 5 10...
output:
6 1 2 4 2 4 3 3 4 4 4 5 2 3 0 3 4 5 7 6 3 3 2 2 4 5 7 2 3 0 6 2 2 3 2 5 3 3 3 3 2 5 2 1 3 5 3 3 3 8 4 2 5 4 4 2 5 4 2 2 4 3 3 3 2 3 1 7 7 6 3 5 4 3 3 4 -1 6 3 4 3 3 4 0 3 1 4 5 4 5 3 1 2 2 1 4 4 6 4 3 4 2 1 5 4 7 3 -1 6 5 3 5 4 4 5 4 6 5 6 7 4 4 5 4 4 3 3 4 3 -2 3 2 1 2 5 1 2 1 6 5 2 2 5 5 4 3 -2 6 ...
result:
wrong answer 2nd numbers differ - expected: '5', found: '1'