QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#645633 | #7685. Barkley II | 22016020736 | WA | 5ms | 18288kb | C++17 | 2.6kb | 2024-10-16 19:16:33 | 2024-10-16 19:16:34 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int pre[500009];
//map<int, int> pre, cnt;
int kuai;
map<int,int>cnt;
int arr[500009];
vector<int> pos[500009];
//int ne[500009][29];
struct node {
int l, r, val;
} qry[500009];
bool cmp(node a,node b)
{
if(a.l/kuai==b.l/kuai)
{
if((a.l/kuai)%2==0)
{
return a.r<b.r;
}
else
{
return a.r>b.r;
}
}
else return a.l/kuai<b.l/kuai;
}
int ans,cut;
void jia(int id)
{
cnt[arr[id]]++;
if(cnt[arr[id]]==1) cut++;
}
void jian(int id)
{
cnt[arr[id]]--;
if(cnt[arr[id]]==0) cut--;
}
int main() {
int tt = 0;
// cout<<(1<<25)<<endl;
scanf("%d", &tt);
while (tt--) {
int tot = 0;
int n,m;
int mn=1e9+7,mx=-1;
scanf("%d%d",&n,&m);
//if(n==250000&&m==144237) printf("tot:%d\n",arr[238583]);
for (int i = 1; i <= n; i++) {
scanf("%d",&arr[i]);
mn=min(arr[i],mn);
mx=max(mx,arr[i]);
if(arr[i] <= n )
{
if(pre[arr[i]]+1<=i-1)
{
if(i-pre[arr[i]]-1>=arr[i]-1) qry[++tot]={pre[arr[i]]+1,i-1,arr[i]};
}
pre[arr[i]]=i;
}
}
for (int i = 1; i <= n; i++) {
if(pre[i]==0)
{
qry[++tot]={1,n,i};
break;
}
else
{
if(pre[i]+1<=n)
{
if(n-pre[i]>=i-1) qry[++tot]={pre[i]+1,n,i};
}
}
}
kuai=sqrt(n);
//if(n==250000&&tot>=54237) printf("tot:%d\n",arr[39499495949594]);
sort(qry+1,qry+1+tot,cmp);
ans=-1,cut=0;
int l=1,r=0;
for(int i=1;i<=sqrt(n);i++)
{
while( l<qry[i].l)
{
jian(l);
l++;
}
while(l>qry[i].l)
{
l--;
jia(l);
}
while(r<qry[i].r)
{
r++;
jia(r);
}
while(r>qry[i].r)
{
jian(r);
r--;
}
// if(qry[i].val==1) printf("cut:%d %d %d %d %d\n",l,r,cut,qry[i].l,qry[i].r);
ans=max(ans,cut-qry[i].val );
}
if(mn==mx&&mx==1) ans=-1;
printf("%d\n",ans);
//pre.clear();
//cnt.clear();
for(int i=1;i<=n;i++) pre[i]=0;
cnt.clear();
ans=0,cut=0;
}
return 0;
}
詳細信息
Test #1:
score: 0
Wrong Answer
time: 5ms
memory: 18288kb
input:
2 5 4 1 2 2 3 4 5 10000 5 2 3 4 1
output:
-1 -1
result:
wrong answer 1st numbers differ - expected: '2', found: '-1'