QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#592181#5459. Goose, goose, DUCK?Baiyu0123#WA 3ms5680kbC++201.2kb2024-09-26 21:03:242024-09-26 21:03:33

Judging History

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

  • [2024-09-26 21:03:33]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:5680kb
  • [2024-09-26 21:03:24]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+100;
int val[maxn<<2],n;
vector<int> d[maxn];
long long ans=0;
void gettag(int w,int x) {
	val[w]=min(val[w],x);
}
void pushtag(int w) {
	gettag(w<<1,val[w]);
	gettag(w<<1|1,val[w]);
}
void build(int l,int r,int w) {
	val[w]=n;
	if (l==r) return ;
	int mid=(l+r)>>1;
	build(l,mid,w<<1);
	build(mid+1,r,w<<1|1);
}
void modify(int ql,int qr,int l,int r,int w,int x) {
	if (ql<=l&&r<=qr) {
		gettag(w,x);
		return ;
	}
	int mid=(l+r)>>1;
	pushtag(w);
	if (ql<=mid) modify(ql,qr,l,mid,w<<1,x);
	if (qr>=mid+1) modify(ql,qr,mid+1,r,w<<1|1,x);
}
void calc(int l,int r,int w) {
	if (l==r) {
		ans+=val[w]-l+1;
		return ;
	}
	pushtag(w);
	int mid=(l+r)>>1;
	calc(l,mid,w<<1);
	calc(mid+1,r,w<<1|1);
}
int main() {
	ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int k;
	cin>>n>>k;
	build(1,n,1);
	for (int i=1;i<=n;i++) {
		int x;cin>>x;
		d[x].push_back(i);
	}
	for (int c=1;c<=1000000;c++) {
		if (d[c].size()<k) continue;
		for (int i=0;i+k-1<d[c].size();i++) {
			int l=d[c][i],r=d[c][i+k-1];
			modify(1,l,1,n,1,r-1); 
		}
	}
	calc(1,n,1);
	cout<<ans<<'\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

input:

6 1
1 2 3 4 5 6

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 2ms
memory: 5644kb

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:

1943

result:

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