/ Randle /

记录详情

Memory Exceeded

/in/foo.cc: In function 'int getsum(int)':
/in/foo.cc:29:9: warning: unused variable 'i' [-Wunused-variable]
     int i,sum=0;
         ^
# 状态 耗时 内存占用
#1 Accepted 6ms 2.215 MiB
#2 Accepted 5ms 2.223 MiB
#3 Accepted 3ms 2.25 MiB
#4 Accepted 5ms 2.125 MiB
#5 Accepted 50ms 9.75 MiB
#6 Accepted 52ms 9.977 MiB
#7 Accepted 55ms 2.625 MiB
#8 Memory Exceeded ≥1000ms ≥256.0 MiB
#9 Accepted 980ms 230.25 MiB
#10 Memory Exceeded ≥1012ms ≥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];//树状数组闪亮登场 
inline bool cmp(node x,node y)
{
	return x.s<y.s;
}

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

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,cmp);
	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 15:32:25
评测时间
2017-11-06 15:32:25
评测机
分数
80
总耗时
≥3172ms
峰值内存
≥256.0 MiB