QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#142117#5368. 异世界的文章分割者DaiRuiChen007Compile Error//C++142.3kb2023-08-18 15:09:542023-08-18 15:09:56

Judging History

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

  • [2023-08-18 15:09:56]
  • 评测
  • [2023-08-18 15:09:54]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int MAXN=5e4+5,inf=1e18;
struct Node {
	int link,len,ch[26];
}	tr[MAXN<<1];
int lst,tot;
inline int insert(int c) {
	int cur=++tot,p=lst;
	tr[cur].len=tr[lst].len+1;
	memset(tr[cur].ch,0,sizeof(tr[cur].ch));
	while(p&&!tr[p].ch[c]) tr[p].ch[c]=cur,p=tr[p].link;
	if(!p) tr[cur].link=1;
	else {
		int q=tr[p].ch[c];
		if(tr[q].len==tr[p].len+1) tr[cur].link=q;
		else {
			int r=++tot;
			tr[r].link=tr[q].link,tr[r].len=tr[p].len+1;
			memcpy(tr[r].ch,tr[q].ch,sizeof(tr[r].ch));
			tr[cur].link=tr[q].link=r;
			while(p&&tr[p].ch[c]==q) tr[p].ch[c]=r,p=tr[p].link;
		}
	}
	return lst=cur;
} //SAM
char str[MAXN];
int e[MAXN],q[MAXN],w[MAXN],st[MAXN<<1],ed[MAXN<<1]; //ans[i]=qi+w
int buc[MAXN],
inline int eval(int l,int r) { //get val(S[l,r])
	lst=tot=1,memset(tr[1].ch,0,sizeof(tr[1].ch));
	for(int i=l;i<=r;++i) e[i]=insert(str[i]-'a');
	fill(st+1,st+tot+1,inf),fill(ed+1,ed+tot+1,-inf);
	for(int i=l;i<=r;++i) st[e[i]]=ed[e[i]]=i;
	vector <vector<int>> Nodes(r-l+2);
	for(int i=2;i<=tot;++i) Nodes[tr[i].len].push_back(i);
	for(int i=r-l+1;i;--i) {
		for(int p:Nodes[i]) {
			st[tr[p].link]=min(st[tr[p].link],st[p]);
			ed[tr[p].link]=max(ed[tr[p].link],ed[p]);
		}
	}
	fill(q+l,q+r+1,0),fill(w+l,w+r+1,0);
	for(int i=2;i<=tot;++i) {
		auto add=[&](int x,int y,int nq,int nw) {
			if(x>y) return ;
			q[x]+=nq,w[x]+=nw;
			if(y<r) q[y+1]-=nq,w[y+1]-=nw;
		};
		int mx=tr[i].len,mn=tr[tr[i].link].len;
		add(st[i]+1,ed[i]-mx,0,mx-mn);
		add(max(st[i]+1,ed[i]-mx+1),ed[i]-mn,-1,ed[i]-mn+1);
	}
	int ans=0;
	for(int i=l+1;i<=r;++i) {
		q[i]+=q[i-1],w[i]+=w[i-1];
		ans+=(q[i]*i+w[i])*(q[i]*i+w[i]);
	}
	return ans;
}
int n,k;
inline bool check(int x) {
	int st=1,tot=0;
	while(st<=n) {
		if((++tot)>k) return false;
		auto judge=[&](int len) {
			if(st+len-1<=n) return eval(st,st+len-1)<=x;
			return false;
		};
		int k=1,len=0;
		while(judge(1<<k)) ++k;
		len=1<<(k-1);
		for(int d=k-2;~d;--d) if(judge(len+(1<<d))) len+=1<<d;
		st+=len;
	}
	return true;
}
signed main() {
	scanf("%lld%lld%s",&n,&k,str+1);
	int l=0,r=inf,res=0;
	while(l<=r) {
		int mid=(l+r)>>1;
		if(check(mid)) res=mid,r=mid-1;
		else l=mid+1;
	}
	printf("%lld\n",res);
	return 0;
}

詳細信息

answer.code:31:1: error: expected unqualified-id before ‘inline’
   31 | inline int eval(int l,int r) { //get val(S[l,r])
      | ^~~~~~
answer.code: In lambda function:
answer.code:68:48: error: ‘eval’ was not declared in this scope
   68 |                         if(st+len-1<=n) return eval(st,st+len-1)<=x;
      |                                                ^~~~
answer.code: In function ‘int main()’:
answer.code:80:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   80 |         scanf("%lld%lld%s",&n,&k,str+1);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~