QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#525043#5459. Goose, goose, DUCK?solar_express#WA 8ms40600kbC++142.1kb2024-08-20 11:56:062024-08-20 11:56:07

Judging History

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

  • [2024-08-20 11:56:07]
  • 评测
  • 测评结果:WA
  • 用时:8ms
  • 内存:40600kb
  • [2024-08-20 11:56:06]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,k;
int o[1200000];
int pd[1200000];
int ch[1200000];
vector<int>vt[1200000];
long long ans=0;
int zan[1200000],ztop;
int tree[4000000],lazy[4000000];
int tp;
int pushup(int k){
	int RE=0;
	if(!lazy[k<<1])RE+=tree[k<<1];
	if(!lazy[k<<1|1])RE+=tree[k<<1|1];
	return RE;
}
void tree_init(int l,int r,int k,int x,int y){
	if(l>y||r<x){tree[k]=lazy[k]=0;return ;}
	if(l==r){tree[k]=1;lazy[k]=0;return ;}
	int mid=(l+r)>>1;
	tree_init(l,mid,k<<1,x,y);
	tree_init(mid+1,r,k<<1|1,x,y);
	tree[k]=pushup(k);
	lazy[k]=0;
}
void add(int l,int r,int k,int x,int y,int v){
	if(x<=l&&r<=y){lazy[k]+=v;return ;}
	int mid=(l+r)>>1;
	if(x<=mid)add(l,mid,k<<1,x,y,v);
	if(y>mid)add(mid+1,r,k<<1|1,x,y,v);
	tree[k]=pushup(k);
}
void init(int l,int r,int mid){
	r=r;//No Warning "r"
	tree_init(1,n,1,l,mid);
	for(int i=1;i<=ztop;i++){
		if(pd[zan[i]]>=k){
			add(1,n,1,vt[zan[i]][k+1]+1,vt[zan[i]][k],1);
		}
	}
}
void update(int x){
	if(pd[x]){
			if(ch[x]+pd[x]>=k&&ch[x]<=k){
			add(1,n,1,vt[x][k-ch[x]+1]+1,vt[x][k-ch[x]],-1);
		}
		ch[x]++;
		if(ch[x]+pd[x]>=k&&ch[x]<=k){
			add(1,n,1,vt[x][k-ch[x]+1]+1,vt[x][k-ch[x]],1);
		}
		return ;
	}
	else{
		if(ch[x]==k)tp--;
		ch[x]++;
		if(ch[x]==k)tp++;
	}
}
void sol(int l,int r){
	if(l==r){if(k!=1)ans++;return ;}
	if(l+1==r){
		if(o[l]==o[r]){if(k!=1)ans+=2;if(k!=2)ans++;}
		else if(k!=1)ans+=3;return ;
	}
	int mid=(l+r)>>1;
	ztop=0;
	vt[o[mid]].push_back(mid+1);
	vt[o[mid]].push_back(mid);
	pd[o[mid]]++;
	zan[++ztop]=o[mid];ch[o[mid]]=0;
	for(int i=mid-1;i>=l;i--){
		if(!pd[o[i]]){
			vt[o[i]].push_back(mid);
			zan[++ztop]=o[i];
			ch[o[i]]=0;
		}
		pd[o[i]]++;
		vt[o[i]].push_back(i);
	}
	for(int i=1;i<=ztop;i++){
		vt[zan[i]].push_back(l-1);
	}
	init(l,r,mid);
	tp=0;
	for(int i=mid+1;i<=r;i++){
		update(o[i]);
		if(tp)continue;
		ans+=tree[1];
	}
	for(int i=l;i<=r;i++){
		pd[o[i]]=0,vt[o[i]].clear();
		ch[o[i]]=0;
	}
	ztop=0;
	sol(l,mid);sol(mid+1,r);
}
int main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)scanf("%d",&o[i]);
	sol(1,n);
	cout<<ans<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 8ms
memory: 33776kb

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: 32048kb

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

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:

4309

result:

ok 1 number(s): "4309"

Test #4:

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

input:

1000 100
144044 144044 606320 144044 144044 653289 606320 606320 606320 144044 653289 606320 144044 606320 144044 653289 606320 653289 144044 144044 606320 606320 606320 144044 606320 653289 653289 144044 606320 606320 606320 606320 606320 606320 606320 606320 653289 606320 653289 606320 653289 6532...

output:

494331

result:

ok 1 number(s): "494331"

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 34696kb

input:

1000 2
37158 712133 695735 352502 37158 111876 979836 322207 850 170255 712133 37158 68113 170255 269273 322207 644692 127744 575843 269273 352502 68113 166126 413274 111876 575843 704107 695735 37158 604776 127744 269273 166126 704107 850 111876 352502 979836 850 850 712133 850 979836 575843 704107...

output:

472845

result:

wrong answer 1st numbers differ - expected: '382010', found: '472845'