QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#591527#5459. Goose, goose, DUCK?ice_cup#WA 7ms36640kbC++142.0kb2024-09-26 16:18:402024-09-26 16:18:41

Judging History

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

  • [2024-09-26 16:18:41]
  • 评测
  • 测评结果:WA
  • 用时:7ms
  • 内存:36640kb
  • [2024-09-26 16:18:40]
  • 提交

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]){
		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(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: 0ms
memory: 36376kb

input:

6 2
1 2 2 1 3 3

output:

10

result:

ok 1 number(s): "10"

Test #2:

score: 0
Accepted
time: 3ms
memory: 35636kb

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 7ms
memory: 36640kb

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:

4395

result:

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