QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591551#5459. Goose, goose, DUCK?ice_cup#WA 6ms36444kbC++142.0kb2024-09-26 16:23:202024-09-26 16:23:21

Judging History

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

  • [2024-09-26 16:23:21]
  • 评测
  • 测评结果:WA
  • 用时:6ms
  • 内存:36444kb
  • [2024-09-26 16:23:20]
  • 提交

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[1000100],pos[1000100],num[1000100<<2],mi[1000100<<2],la[1000100<<2];
ll ans;
vector<int>g[1000100];
void up(int p){
	if(mi[ls]==mi[rs]){
		mi[p]=mi[ls];
		num[p]=num[ls]+num[rs];
	}
	if(mi[ls]>mi[rs]){
		mi[p]=mi[rs];
		num[p]=num[rs];
	}
	if(mi[ls]<mi[rs]){
		mi[p]=mi[ls];
		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(lin>rin)swap(lin,rin);
	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(lin>rin)swap(lin,rin);
	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: 4ms
memory: 36444kb

input:

6 2
1 2 2 1 3 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 4ms
memory: 35424kb

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 6ms
memory: 36376kb

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:

4325

result:

wrong answer 1st numbers differ - expected: '4309', found: '4325'