QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#240655#5459. Goose, goose, DUCK?ucup-team1769#WA 3ms30412kbC++201.1kb2023-11-05 17:20:192023-11-05 17:20:20

Judging History

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

  • [2023-11-05 17:20:20]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:30412kb
  • [2023-11-05 17:20:19]
  • 提交

answer

#include<bits/stdc++.h>

using namespace std;
const int N=1000100;

int a[N];
vector<int>pos[N];
vector<array<int,3>> seg,seg1,seg2;
queue<int>q;
int c[N];
void modify(int x,int d){
	for(;x<=N;x+=x&-x) c[x]+=d;
}
int query(int x){
	int s=0;
	for(;x;x-=x&-x) s+=c[x];
	return s;
}
int main(){

	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++){ 
		scanf("%d",&a[i]);
		pos[a[i]].push_back(i);
	}
	for(int i=1;i<=n;i++){
		int x=a[i];
		if(pos[x].size()>=k){
			
			if(pos[x].size()>k){
				seg.push_back({i,pos[x][k-1],pos[x][k]});
			}
			else
				seg2.push_back({i,pos[x][k-1],n});
			pos[x].erase(pos[x].begin());
		}
		
	}
	int lst=0;
	long long ans=0;
	sort(seg2.begin(),seg2.end());
	reverse(seg2.begin(),seg2.end());
	for(int i=0;i<seg2.size();i++){

		if(query(seg2[i][1])==0)
			seg1.push_back({seg2[i][0],seg2[i][1],seg2[i][2]});
		modify(seg2[i][1],1);

	}
	sort(seg1.begin(),seg1.end());
	for(auto [x,y,z]:seg1){
	//	cout<<x<<" "<<y<<endl;
		ans=ans+1ll*(x-lst)*(z-y+1);
		lst=x;
	}
	printf("%lld\n",1ll*n*(n-1)/2+n-ans);

}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 30352kb

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

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 3ms
memory: 30412kb

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:

4343

result:

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