QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#765985#9584. 顾影自怜forget-star#WA 50ms24648kbC++201.2kb2024-11-20 15:51:372024-11-20 15:51:40

Judging History

你现在查看的是最新测评结果

  • [2024-11-20 15:51:40]
  • 评测
  • 测评结果:WA
  • 用时:50ms
  • 内存:24648kb
  • [2024-11-20 15:51:37]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<cmath>
#include<bitset>
#include<stack>
using namespace std;
typedef long double ld;
typedef long long ll;
const int N=1e6+10;
int n,k,a[N],id[N],l[N],r[N],st[N],top;
vector<int>v[N];
int main()
{
	int T;scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d",&n,&k);
		for(int i=1;i<=n;i++) scanf("%d",&a[i]);
		for(int i=1;i<=n;i++) v[i].clear();
		for(int i=1;i<=n;i++)
		{
			v[a[i]].push_back(i);
			id[i]=v[a[i]].size();
		}
		for(int i=1;i<=n;i++)
		{
			while(top>0&&a[st[top]]<=a[i]) top--;
			l[i]=st[top];
			st[++top]=i;
		}
		st[0]=n+1;top=0;
		for(int i=n;i>=1;i--)
		{
			while(top>0&&a[st[top]]<=a[i]) top--;
			r[i]=st[top];
			st[++top]=i;
		}
		ll ans=0;
		for(int i=1;i<=n;i++)
		{
			int l1=(id[i]>1?v[a[i]][id[i]-2]:0);
			if((id[i]+k-1)<=v[a[i]].size())
			{
				int r1=((id[i]+k)<=v[a[i]].size()?v[a[i]][id[i]+k-1]:n+1);
				int l2=max(l1,l[i])+1,r2=min(r1,r[i])-1;
				if(l2<=i&&v[a[i]][id[i]+k-2]<=r2)
					ans+=1ll*(i-l2+1)*(r2-v[a[i]][id[i]+k-2]+1);
			}
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 12120kb

input:

2
5 2
1 3 3 2 2
4 3
1 4 2 1

output:

7
0

result:

ok 2 lines

Test #2:

score: -100
Wrong Answer
time: 50ms
memory: 24648kb

input:

1
1000000 1
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

1000000

result:

wrong answer 1st lines differ - expected: '500000500000', found: '1000000'