QOJ.ac
QOJ
The 2nd Universal Cup Finals is coming! Check out our event page, schedule, and competition rules!
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#645622 | #7685. Barkley II | Liuhao | WA | 0ms | 3620kb | C++23 | 2.7kb | 2024-10-16 19:14:24 | 2024-10-16 19:14:26 |
Judging History
answer
//
// Created by liuhao.
//
// /## /## /## /###### /## /##
// | ## |__/ | ## /##__ ## | ## | ##
// | ## /## /## /## | ####### /###### /###### |__/ \ ## | ## | ##
// | ## | ## | ## | ## | ##__ ## |____ ## /##__ ## /######/ | ########
// | ## | ## | ## | ## | ## \ ## /####### | ## \ ## /##____/ |_____ ##
// | ## | ## | ## | ## | ## | ## /##__ ## | ## | ## | ## | ##
// | ## | ## | ######/ | ## | ## | ####### | ######/ | ######## | ##
// |__/ |__/ \______/ |__/ |__/ \_______/ \______/ |________/ |__/
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define PII pair<int,int>
#define fi first
#define se second
#define int long long
#define endl '\n'
#define vii vector<vector<int>>
struct Fenwick {
int n{};
vector<int> tr;
Fenwick(int n_) : n(n_), tr(n + 1) {}
void add(int x, int y) {
while (x <= n)tr[x] += y, x += x & -x;
}
int sum(int x) {
int res = 0;
while (x)res += tr[x], x -= x & -x;
return res;
}
};
auto CountColor(vector<int> &a, vector<pair<int, int>> &que) {
int n = a.size();
vector<int> ans(que.size());
vector<vector<pair<int, int>>> f(n + 1);
for (int i = 1; i < que.size(); i++)f[que[i].second].emplace_back(que[i].first, i);
Fenwick arr(n + 1);
map<int, int> mp;
for (int i = 1; i <= n; i++) {
if (mp[a[i]])arr.add(mp[a[i]], -1);
mp[a[i]] = i;
for (auto [l, j]: f[i])ans[j] = arr.sum(i) - arr.sum(l - 1);
}
return ans;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
int T;
cin >> T;
while (T--) {
map<int, int> st;
int n, m;
cin >> n >> m;
vector<int> a(n + 1);
map<int, vector<int>> mp;
for (int i = 1; i <= n; i++) {
cin >> a[i];
st[a[i]]++;
if (!mp.count(a[i]))mp[a[i]].push_back(0);
mp[a[i]].push_back(i);
}
map<int, int> b;
Fenwick arr(n + 1);
vector<PII > que(1);
vector<int> ans1(1);
for (auto &i: mp)i.se.push_back(n + 1);
for (auto [k, val]: mp) {
for (int i = 1; i < val.size(); i++) {
if (val[i - 1] + 1 <= val[i] - 1)que.emplace_back(val[i - 1] + 1, val[i] - 1), ans1.emplace_back(k);
}
}
que.emplace_back(1, n);
int mex = 0;
for (int i = 1; i <= m + 1; i++) {
if (!st[i]) {
mex = i;
break;
}
}
ans1.emplace_back(mex);
auto ans2= CountColor(a,que);
int ans = -1e18;
for(int i=1;i<ans1.size();i++){
ans=max(ans,ans2[i]-ans1[i]);
}
cout << ans << endl;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3620kb
input:
2 5 4 1 2 2 3 4 5 10000 5 2 3 4 1
output:
-2 -1
result:
wrong answer 1st numbers differ - expected: '2', found: '-2'