QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#395464 | #7685. Barkley II | zzuqy# | WA | 64ms | 27488kb | C++14 | 1.6kb | 2024-04-21 15:01:53 | 2024-04-21 15:01:53 |
Judging History
answer
#include <bits/stdc++.h>
#define N 500006
int tree[N];
#define lowbit(x) (x&(-x))
int n, m;
inline int query(int x) {
int ans = 0;
for (; x; x -= lowbit(x))
ans += tree[x];
return ans;
}
inline void add(int x) {
for (; x <= n; x += lowbit(x))
tree[x]++;
}
inline void sub(int x) {
for (; x <= n; x += lowbit(x))
tree[x]--;
}
inline void add(int l, int r) {
add(l);
if (r != n)
sub(r + 1);
}
int vis[N];
std::vector<int>id[N];
int nex[N];
struct Ask {
int r, i;
};
std::vector<Ask>ask[N];
int a[N];
int main() {
int t;
scanf("%d", &t);
while (t--) {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", a + i);
id[a[i]].push_back(i);
}
int ans = -1;
for (int j = 1, i; j <= n; j++) {
i = a[j];
if (vis[i])
continue;
vis[i] = 1;
if (!id[i].size())
continue;
ask[1].push_back({id[i][0] - 1, i});
ask[id[i][id[i].size() - 1] + 1].push_back({n, i});
for (int j = 0; j + 1 < id[i].size(); j++) {
ask[id[i][j] + 1].push_back ({id[i][j + 1] - 1, i});
}
}
for (int i = n; i; i--) {
int o = nex[a[i]] ? nex[a[i]] : (n + 1);
nex[a[i]] = i;
add(i, o - 1);
for (int j = 0; j < ask[i].size(); j++) {
if (ask[i][j].r < i)
continue;
ans = std::max(ans, query(ask[i][j].r) - i);
}
}
int mex;
for (mex = 1; vis[mex]; mex++);
ans = std::max(ans, query(n) - mex);
printf("%d\n", ans);
for (int i = 1; i <= n; i++) {
if (vis[a[i]]) {
vis[a[i]] = nex[a[i]] = 0;
std::vector<int>().swap(id[a[i]]);
}
std::vector<Ask>().swap(ask[i]);
tree[i] = 0;
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 27264kb
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: 64ms
memory: 27488kb
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 5 4 6 3 4 3 7 5 4 4 5 3 3 6 6 7 5 7 6 5 5 6 2 6 8 7 3 5 5 6 2 4 3 4 5 5 3 7 3 4 6 6 3 5 5 3 3 3 8 6 6 5 7 4 4 6 5 6 6 6 6 7 3 6 3 3 7 7 6 6 7 4 3 5 5 4 6 3 4 6 6 5 5 5 9 4 5 7 5 5 5 2 2 5 6 6 8 5 3 5 5 5 5 7 7 4 2 6 6 3 6 4 5 5 6 6 6 6 7 7 5 5 7 4 7 4 7 6 6 6 5 4 3 5 4 3 3 6 5 3 6 6 5 5 4 5 6 6 6 ...
result:
wrong answer 4th numbers differ - expected: '4', found: '6'