QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#644179#8781. Element-Wise ComparisontreeiiiWA 1ms7648kbC++141.4kb2024-10-16 11:34:212024-10-16 11:34:22

Judging History

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

  • [2024-10-16 11:34:22]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7648kb
  • [2024-10-16 11:34:21]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define _int __int128
#define y1 _
using namespace std;

static char buf[1000000],*p1=buf,*p2=buf;

inline int read(){
	char c=getchar();
	int res=0,f=1;
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		res=res*10+c-'0';
		c=getchar();
	}
	return res*f;
}

inline void write(int x){
	static char buf[20];
	static int len=-1;
	if(x<0){
		putchar('-');
		x=-x;
	}
	do{
		buf[++len]=x%10;
		x/=10;
	}
	while(x);
	while(len>=0){
		putchar(buf[len--]+48);
	}
}

const int maxn=50005;
const int maxm=510;
const int inf=1e18;
const int bas=100;
const int mod=1e9+7;
const double eps=1e-4;

int n,m;
bitset<maxn-5> s1[maxn],s2[maxn],s3;
int a[maxn],p[maxn];

void solve(){
	n=read(),m=read();
	for(int i=1;i<=n;i++){
		a[i]=read();
		p[a[i]]=i;
	}
	for(int i=n;i>=1;i--){
		s1[p[i]]=s3;
		s3[p[i]]=1;
	}	
	for(int i=1;i<=n;i++){
		s2[i]=(s1[i]>>=i);
	}
	for(int i=1;i<=n;i++){
		if(i%m){
			s1[i]&=s1[i-1];
		}
	}
	for(int i=n-1;i>=1;i--){
		if(i%m!=m-1){
			s2[i]&=s2[i+1];
		}
	}
	int ans=0;
	s3.reset();
	for(int i=2;i<=n-m+1;i++){
		s3[i]=1;
	}
	for(int i=1;i<=n-m;i++){
		ans+=(s2[i]&s1[i+m-1]&s3).count();
		s3[n-m-i]=0;
	}
	write(ans);
	puts("");
	return ;
}

signed main(){
	//	freopen("puxi.in","r",stdin);
	//	freopen("puxi.out","w",stdout);
	int T=1;
	//	T=read();
	while(T--){
		solve();
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 7648kb

input:

5 3
5 2 1 3 4

output:

0

result:

ok answer is '0'

Test #2:

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

input:

5 2
3 1 4 2 5

output:

1

result:

wrong answer expected '2', found '1'