QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#252764 | #7685. Barkley II | luyiming123 | TL | 5ms | 21804kb | C++14 | 1.5kb | 2023-11-16 10:40:38 | 2023-11-16 10:40:38 |
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) {memset(c, 0, sizeof(c)); 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);
for(int i = 1; i <= n; i++) scanf("%d", &a[i]), b[i] = a[i];
sort(b + 1, b + n + 1); L = unique(b + 1, b + n + 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: 5ms
memory: 21804kb
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
Time Limit Exceeded
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:
3 1 2 4 2 3 3 3 3 3 4 5 2 3 -1 3 1 3 7 6 3 3 -1 2 4 4 6 2 3 0 6 1 2 2 2 5 3 3 3 3 2 5 2 1 3 3 2 3 1 4 2 2 4 4 2 2 5 3 2 1 4 3 3 3 2 3 0 4 7 6 2 2 4 3 3 4 -2 6 3 3 3 3 4 0 1 1 4 5 4 5 3 1 1 2 1 3 3 4 4 3 4 2 1 3 4 4 3 -1 3 4 3 5 4 4 2 4 6 4 4 5 3 4 5 1 4 3 3 3 3 -2 3 2 1 2 5 1 2 1 4 4 2 2 4 5 4 3 -4 ...