QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591490#5459. Goose, goose, DUCK?ice_cup#RE 3ms12172kbC++141.9kb2024-09-26 16:08:152024-09-26 16:08:15

Judging History

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

  • [2024-09-26 16:08:15]
  • 评测
  • 测评结果:RE
  • 用时:3ms
  • 内存:12172kb
  • [2024-09-26 16:08:15]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define mk make_pair
#define MID int mid=(l+r)>>1;
#define ll long long
#define ls p<<1
#define rs p<<1|1
#define endl '\n'
#define siz(a) int(a.size())
int n,k,a[200100],pos[200100],num[200100],mi[200100],la[200100];
ll ans;
vector<int>g[200100];
void up(int p){
	if(mi[ls]==mi[rs]){
		num[p]=num[ls]+num[rs];
	}
	if(mi[ls]>mi[rs]){
		num[p]=num[rs];
	}
	if(mi[ls]<mi[rs]){
		num[p]=num[ls];
	}
}
void build(int l,int r,int p){
	if(l==r){
		num[p]=1;
		mi[p]=0;return;
	}
	MID;
	build(l,mid,ls),build(mid+1,r,rs);
	up(p);
}
void add(int p,int val){
	mi[p]+=val;
	la[p]+=val;
}
void down(int p){
	if(la[p]){
		add(ls,la[p]);
		add(rs,la[p]);
		la[p]=0;
	}
}

void add(int l,int r,int lin,int rin,int p,int val){
	// cout<<lin<<' '<<rin<<endl;
	if(l==lin&&r==rin){
		add(p,val);
		return;
	}
	down(p);
	MID;
	if(rin<=mid)add(l,mid,lin,rin,ls,val);
	else if(lin>mid)add(mid+1,r,lin,rin,rs,val);
	else add(l,mid,lin,mid,ls,val),add(mid+1,r,mid+1,rin,rs,val);
	up(p);
}
void pr(int l,int r,int lin,int rin,int p){
	if(l==lin&&r==rin){
		if(mi[p]==0)ans+=num[p];
		return;
	}
	down(p);
	MID;
	if(rin<=mid)pr(l,mid,lin,rin,ls);
	else if(lin>mid)pr(mid+1,r,lin,rin,rs);
	else pr(l,mid,lin,mid,ls),pr(mid+1,r,mid+1,rin,rs);
}
void solve(){
	cin>>n>>k;
	build(1,n,1);
	for(int i=1;i<=n;i++)g[i].push_back(0);
	for(int i=1;i<=n;i++)cin>>a[i],g[a[i]].push_back(i),pos[i]=g[a[i]].size()-1;
	for(int i=1;i<=n;i++){
		if(pos[i]>=k){
			if(pos[i]>=k+1){
				add(1,n,g[a[i]][pos[i]-k-1]+1,g[a[i]][pos[i]-k],1,-1);
			}
			add(1,n,g[a[i]][pos[i]-k]+1,g[a[i]][pos[i]-k+1],1,+1);
		}
		pr(1,n,1,i,1);
	}
	cout<<ans;
}
int main(){
	// ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int TTT;
	// cin>>TTT;
	TTT=1;
	while(TTT--)solve();	
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

6 2
1 2 2 1 3 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 2ms
memory: 11280kb

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Runtime Error

input:

100 10
142826 764475 142826 986320 764475 142826 142826 986320 764475 986320 764475 764475 764475 142826 142826 986320 764475 986320 764475 764475 142826 764475 142826 764475 986320 986320 764475 142826 764475 764475 142826 764475 764475 986320 142826 142826 142826 142826 764475 986320 986320 764475...

output:


result: