QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#303319 | #7685. Barkley II | ivaziva | WA | 3ms | 30900kb | C++17 | 2.2kb | 2024-01-12 06:44:20 | 2024-01-12 06:44:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define MAXN 500010
long long niz[MAXN];
vector<long long> pozicije[MAXN];
long long bit[MAXN];
long long last_visit[MAXN];
vector<pair<long long,long long>> query[MAXN];
void update(long long x,long long val,long long n)
{
for (long long i=x;i<=n;i+=(i&(-i))) bit[i]+=val;
}
long long sol(long long x)
{
long long br=0;
for (long long i=x;i>=1;i-=(i&(-i))) br+=bit[i];
return br;
}
void answer_queries(long long n)
{
for (long long i=1;i<=n;i++) bit[i]=0;
for (long long i=1;i<=n;i++) last_visit[i]=-1;
long long ans=-LLONG_MAX;
for (long long i=1;i<=n;i++)
{
if (last_visit[niz[i]]!=-1) update(last_visit[niz[i]],-1,n);
last_visit[niz[i]]=i;
update(i,1,n);
long long s=query[i].size();
for (long long j=0;j<s;j++)
{
long long l=query[i][j].first;
long long mex=query[i][j].second;
long long val=sol(i)-sol(l-1);
ans=max(ans,val-mex);
}
}
cout<<ans<<endl;
}
int main()
{
ios_base::sync_with_stdio(false);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long t;cin>>t;
for (long long z=0;z<t;z++)
{
long long n,m;cin>>n>>m;
for (long long i=1;i<=n;i++) cin>>niz[i];
for (long long i=1;i<=n;i++) pozicije[niz[i]].clear();
for (long long i=1;i<=n;i++) query[i].clear();
for (long long i=1;i<=n;i++) pozicije[niz[i]].push_back(i);
for (long long i=1;i<=n;i++)
{
long long s=pozicije[niz[i]].size();
for (long long j=1;j<s;j++)
{
long long poz1=pozicije[niz[i]][j-1];
long long poz2=pozicije[niz[i]][j];
if (poz2-1<poz1+1) continue;
query[poz2-1].push_back({poz1+1,niz[i]});
}
long long poz1=pozicije[niz[i]][0];
if (poz1-1>=1) query[poz1].push_back({1,niz[i]});
long long poz2=pozicije[niz[i]][s-1];
if (n>=poz2+1) query[n].push_back({poz2+1,niz[i]});
}
answer_queries(n);
}
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 30900kb
input:
2 5 4 1 2 2 3 4 5 10000 5 2 3 4 1
output:
2 4
result:
wrong answer 2nd numbers differ - expected: '3', found: '4'