/ Randle /

记录详情

Time Exceeded


  
# 状态 耗时 内存占用
#1 Accepted 1ms 208.0 KiB
#2 Accepted 1ms 216.0 KiB
#3 Accepted 1ms 212.0 KiB
#4 Accepted 1ms 220.0 KiB
#5 Accepted 72ms 356.0 KiB
#6 Accepted 82ms 356.0 KiB
#7 Accepted 15ms 1.48 MiB
#8 Accepted 14ms 1.48 MiB
#9 Time Exceeded ≥1002ms ≥720.0 KiB
#10 Time Exceeded ≥1004ms ≥724.0 KiB

代码

//sort
#include<bits/stdc++.h>
#define int long long
#define lowbit(x) x&(-x)
using namespace std;
const int N=5e4+5;
int n,m,ans,v[N],w[N],f[N];
char s[N];
void put(int x,int y){
	for(;x<=n;x+=lowbit(x))
		f[x]+=y;
}
int get(int x){
	int res=0;
	for(;x;x-=lowbit(x))
		res+=f[x];
	return res;
}
bool cmp(int x,int y){
	for(int l=1,i=x,j=y;l<=m;i++,j++,l++){
		if((i>n)||(j>n)) return i>n;
		else if(s[i]!=s[j]) return s[i]<s[j];
	}
	return x<y;
}
signed main(){
	//freopen("sort.in", "r", stdin);
	//freopen("sort.out", "w", stdout);
	scanf("%lld%lld%s",&n,&m,s+1);
	for(int i=1;i<=n;i++) v[i]=i;
	sort(v+1,v+1+n,cmp);
	for(int i=1;i<=n;i++) w[v[i]]=i;
	for(int i=1;i<=n;i++)
		ans+=get(n)-get(w[i]),put(w[i],1);
	printf("%lld\n",ans);
	return 0;
}

信息

递交者
类型
递交
题目
后缀数组
题目数据
下载
语言
C++
递交时间
2020-03-03 08:24:24
评测时间
2020-03-03 08:24:24
评测机
分数
80
总耗时
≥2198ms
峰值内存
≥1.48 MiB