/ Randle /

记录详情

Memory Exceeded


  
# 状态 耗时 内存占用
#1 Accepted 5ms 2.5 MiB
#2 Accepted 5ms 2.223 MiB
#3 Accepted 5ms 2.125 MiB
#4 Accepted 6ms 2.133 MiB
#5 Accepted 23ms 9.844 MiB
#6 Accepted 26ms 9.875 MiB
#7 Accepted 34ms 2.625 MiB
#8 Memory Exceeded ≥1078ms ≥256.0 MiB
#9 Accepted 518ms 230.348 MiB
#10 Memory Exceeded ≥1090ms ≥256.0 MiB

代码

#include <stdio.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 5e4+5;
int c[maxn];
int len;
inline int lowbit(int x){return x&-x;}
inline void inc(int x){while(x<=len){c[x]++;x+=lowbit(x);}}
inline int sum(int x){int ret  = 0;while(x){ret+=c[x];x-=lowbit(x);}return ret;}
struct str {
	string s;
	int index;
} arr[maxn];
int newa[maxn];
bool operator<(const str &s1,const str &s2){
	return s1.s<s2.s;
}
int main() {
	int n,m;
	scanf("%d%d",&n,&m);
	string s;
	cin>>s;
	len = n;
	for(int i = 0; i<n; i++) {
		arr[i+1].s = s.substr(i,m);
		arr[i+1].index = i+1;
	}
	sort(arr+1,arr+1+len);
	for(int i = 1;i<=len;i++){
		int val;
		if(arr[i].s!=arr[i-1].s){
			val  = i;
		}else{
			val = newa[arr[i-1].index];
		}
		newa[arr[i].index] = val;
	}
	long long ans = 0;
	for(int i = 1;i<=len;i++){
		inc(newa[i]);
		ans+=i-sum(newa[i]);
	}
	cout<<ans;
	return 0;
}

信息

递交者
类型
递交
题目
后缀数组
题目数据
下载
语言
C++
递交时间
2017-11-06 20:45:56
评测时间
2017-11-06 20:45:56
评测机
分数
80
总耗时
≥2795ms
峰值内存
≥256.0 MiB