QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#286541 | #7685. Barkley II | etohari# | WA | 0ms | 18856kb | C++14 | 1.5kb | 2023-12-17 23:44:21 | 2023-12-17 23:44:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 5e5 + 10;
constexpr int MAXM = 5e5 + 10;
int n, m, a[MAXN], last[MAXM], tree[MAXN];
vector<pair<int, int> > query[MAXN];
void update(int pos, int val) {
if (pos == 0) return;
for (; pos <= n; pos += pos & -pos) {
tree[pos] += val;
}
}
int get(int pos) {
int sum = 0;
for (; pos > 0; pos -= pos & -pos) {
sum += tree[pos];
}
return sum;
}
int get_range(int l, int r) {
if (l > r) return 0;
return get(r) - get(l - 1);
}
signed main() {
cin.tie(NULL)->sync_with_stdio(false);
int test;
cin >> test;
while (test--) {
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
for (int i = 1; i <= n; i++) {
query[i - 1].emplace_back(last[a[i]] + 1, a[i]);
last[a[i]] = i;
}
for (int i = 1; i <= m; i++) {
last[a[i]] = n + 1;
}
for (int i = n; i >= 1; i--) {
query[last[a[i]] - 1].emplace_back(i + 1, a[i]);
last[a[i]] = i;
}
for (int i = 1; i <= m; i++) {
last[a[i]] = 0;
}
int ans = -1;
for (int r = 1; r <= n; r++) {
update(last[a[r]], -1);
last[a[r]] = r;
update(last[a[r]], 1);
for (auto [l, v] : query[r]) {
ans = max(ans, get_range(l, r) - v);
}
}
cout << ans << "\n";
for (int i = 1; i <= max(n, m); i++) {
last[a[i]] = 0;
query[i].clear();
tree[i] = 0;
}
}
return (0 ^ 0);
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 18856kb
input:
2 5 4 1 2 2 3 4 5 10000 5 2 3 4 1
output:
1 3
result:
wrong answer 1st numbers differ - expected: '2', found: '1'