/ Randle /

记录详情

Memory Exceeded

/in/foo.cc: In function 'int getsum(int)':
/in/foo.cc:28:9: warning: unused variable 'i' [-Wunused-variable]
     int i,sum=0;
         ^
# 状态 耗时 内存占用
#1 Accepted 6ms 2.125 MiB
#2 Accepted 6ms 2.621 MiB
#3 Accepted 6ms 2.125 MiB
#4 Accepted 6ms 2.25 MiB
#5 Accepted 24ms 9.75 MiB
#6 Accepted 22ms 10.207 MiB
#7 Accepted 39ms 2.594 MiB
#8 Memory Exceeded ≥1003ms ≥256.0 MiB
#9 Accepted 612ms 230.375 MiB
#10 Memory Exceeded ≥1003ms ≥256.0 MiB

代码

#include <bits/stdc++.h>
#include <string>
using namespace std;
int n,m,ans=0;
string s;
struct node
{
	int pos;
	string s;
}a[50001];
int b[50001];
int c[50001];//树状数组闪亮登场 
bool operator<(const node &nd,const node &nd2){
	return nd.s<nd2.s;
}

inline void add(int t)
{
    while(t<=n)
    {
    	c[t]++;
    	t+=t&(-t);
	}
}

inline int getsum(int t)
{
    int i,sum=0;
    while(t)
    {
    	sum+=c[t];
    	t-=t&(-t);
	}
    return sum;
}
int main()
{
	//freopen("sort2.in","r",stdin);
	//freopen("sort.out","w",stdout);
	int i;
	scanf("%d %d",&n,&m);
	cin>>s;
	for(i=1;i<=n;i++)
		a[i].s=s.substr(i-1,m),a[i].pos=i;
	sort(a+1,a+n+1);
	int p=1;
	b[a[1].pos]=p;
	for(i=2;i<=n;i++)
	{
		if(a[i-1].s!=a[i].s)
			p++;
		b[a[i].pos]=p;
	}
	//for(i=1;i<=n;i++)
		//cout<<b[i]<<" ";
	//cout<<endl;
	for(i=1;i<=n;i++)
    {
		add(b[i]);
		ans+=i-getsum(b[i]);
	}
	cout<<ans;
}

信息

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