QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#291202 | #7685. Barkley II | OAleksa | WA | 0ms | 31256kb | C++14 | 1.6kb | 2023-12-26 05:38:49 | 2023-12-26 05:38:49 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
const int N = 5e5 + 69;
int n, m, a[N], fenw[N];
vector<int> pos[N];
map<int, int> lst, sv;
vector<pair<int, int>> q[N];
signed main() {
ios_base::sync_with_stdio(false);
cout.tie(nullptr);
cin.tie(nullptr);
//freopen("newbarn.in", "r", stdin);
//freopen(newbarn.out", "w", stdout);
int tt = 1;
cin >> tt;
while (tt--) {
auto add = [&](int v, int val) {
for (int i = v;i < N;i += (i & -i))
fenw[i] += val;
};
auto get = [&](int v) {
int res = 0;
for (int i = v;i >= 1;i -= (i & -i))
res += fenw[i];
return res;
};
cin >> n >> m;
for (auto i : lst)
add(i.s, -1);
sv.clear();
lst.clear();
for (int i = 1;i <= n;i++) {
q[i].clear();
pos[i].clear();
cin >> a[i];
sv[a[i]] = 1;
}
for (auto u : sv)
pos[u.f].push_back(0);
for (int i = 1;i <= n;i++)
pos[a[i]].push_back(i);
for (auto u : sv)
pos[u.f].push_back(n + 1);
for (auto i : sv) {
for (int j = 1;j < (int)pos[i.f].size();j++) {
q[pos[i.f][j] - 1].push_back({pos[i.f][j - 1] + 1, i.f});
}
}
int mx = 1;
for (auto u : sv) {
if (mx != u.f)
break;
else
mx++;
}
int ans = sv.size() - mx;
for (int i = 1;i <= n;i++) {
if (lst[a[i]] > 0)
add(lst[a[i]], -1);
add(i, 1);
for (auto u : q[i]) {
int l = u.f, mx = u.s;
if (i == n)
ans = max(ans, get(i) - get(l - 1) - mx);
}
lst[a[i]] = i;
}
cout << ans << '\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 31256kb
input:
2 5 4 1 2 2 3 4 5 10000 5 2 3 4 1
output:
2 1
result:
wrong answer 2nd numbers differ - expected: '3', found: '1'