QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#765998 | #9584. 顾影自怜 | forget-star# | WA | 48ms | 23784kb | C++20 | 1.2kb | 2024-11-20 15:53:51 | 2024-11-20 15:54:01 |
Judging History
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();
}
st[0]=0;top=0;
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: 0ms
memory: 14152kb
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: 48ms
memory: 23784kb
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'