QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#639358 | #7685. Barkley II | yimg | WA | 112ms | 4184kb | C++20 | 2.1kb | 2024-10-13 19:08:18 | 2024-10-13 19:08:21 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
using i64 = long long;
struct node {
int l, r;
i64 dat;
};
struct HisSeg {
int n, idx;
vector<int> root;
vector<node> tr;
HisSeg(int _n, int m) {
n = _n;
idx = 0;
tr.resize(n * 4 + (__lg(n) + 2) * (m), {});
root.resize(m + 1);
root[0] = build(0, n);
}
int build(int l, int r) {
int p = ++idx;
if(r - l == 1) {
return p;
}
int m = l + r >> 1;
tr[p].l = build(l, m);
tr[p].r = build(m, r);
return p;
}
void pull(int p){
tr[p].dat = tr[tr[p].l].dat + tr[tr[p].r].dat;
}
int insert(int nv, int v, int x, int val) {
return root[nv] = insert(root[v], 0, n, x, val);
}
int insert(int p, int l, int r, int x, int val) {
int q = ++idx;
tr[q] = tr[p];
if(r - l == 1) {
tr[q].dat += val;
return q;
}
int m = l + r >> 1;
if(x < m) tr[q].l = insert(tr[p].l, l, m, x, val);
else tr[q].r = insert(tr[p].r, m, r, x, val);
pull(q);
return q;
}
int query(int l, int vr){
return query(root[vr], 0, n, l);
}
int query(int p, int l, int r, int x){
if(r - l == 1){
return tr[p].dat;
}
int m = l + r >> 1;
if(x < m) return query(tr[p].l, l, m, x) + tr[tr[p].r].dat;
else return query(tr[p].r, m, r, x);
}
};
void work()
{
int n, m;
cin >> n >> m;
int ans = -1;
HisSeg his(m + 1, (n + 1) * 2);
map<int, int> mp;
bool flag = false;
vector<int> a(n + 1), lst(m + 1);
for(int i = 1; i <= n; ++i){
cin >> a[i];
mp[a[i]] = 1;
if(!lst[a[i]]){
his.insert(i, i - 1, i, 1);
}
else{
his.insert(n + i, i - 1, lst[a[i]], -1);
his.insert(i, n + i, i, 1);
}
ans = max(ans, his.query(lst[a[i]], i) - a[i] - 1);
// cout << "PPP " << a[i] << " " << his.query(lst[a[i]] , i) << "\n";
lst[a[i]] = i;
}
for(int i = 1; i <= n + 1; ++i){
if(lst[i] < n){
ans = max(ans, his.query(lst[i], n) - i - mp[i]);
// cout << "HHH : " << i << " " << lst[i] << " " << his.query(lst[i] , n) << "\n";
}
}
cout << ans << "\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int t = 1;
cin >> t;
while(t--){
work();
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 4184kb
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: 112ms
memory: 3532kb
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 4 2 4 3 7 4 4 4 5 2 3 6 6 7 5 7 6 5 5 6 2 6 8 7 2 5 5 6 2 2 3 4 5 3 3 7 3 2 5 6 2 3 5 3 3 3 8 6 6 5 7 4 4 5 4 6 6 6 3 7 3 6 3 3 7 7 6 6 7 4 3 3 4 4 6 3 4 6 6 4 5 5 9 4 5 7 5 3 5 2 2 5 6 6 8 4 3 4 5 5 5 7 7 3 2 6 5 3 5 4 4 5 6 6 5 6 7 7 4 5 7 4 7 3 7 6 6 6 5 4 2 5 4 2 3 6 5 2 6 5 5 4 3 5 6 6 6 ...
result:
wrong answer 44th numbers differ - expected: '1', found: '2'