QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#597939#9425. Generated Stringucup-team1004#RE 0ms55196kbC++144.2kb2024-09-28 19:31:472024-09-28 19:31:54

Judging History

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

  • [2024-10-14 17:49:05]
  • hack成功,自动添加数据
  • (/hack/995)
  • [2024-09-30 06:26:23]
  • hack成功,自动添加数据
  • (/hack/927)
  • [2024-09-30 06:25:24]
  • hack成功,自动添加数据
  • (/hack/926)
  • [2024-09-28 19:31:54]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:55196kb
  • [2024-09-28 19:31:47]
  • 提交

answer

#include<bits/stdc++.h>
#define Gc() getchar()
#define Me(x,y) memset(x,y,sizeof(x))
#define Mc(x,y) memcpy(x,y,sizeof(x))
#define d(x,y) ((m)*(x-1)+(y))
#define R(n) (rnd()%(n)+1)
#define Pc(x) putchar(x)
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define eb emplace_back
#define all(x) x.begin(),x.end()
using namespace std;using ll=long long;using db=double;using lb=long db;using ui=unsigned;using ull=unsigned long long;using pii=pair<int,int>;
const int N=2e5+5,M=1e7+5,K=1000+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const int INF=1e9+7;mt19937 rnd(263082);
#define Tp template<typename T>
#define Ts template<typename T,typename... Ar>
namespace Debug{
	Tp void _debug(char* f,T t){cerr<<f<<'='<<t<<endl;}
	Ts void _debug(char* f,T x,Ar... y){while(*f!=',') cerr<<*f++;cerr<<'='<<x<<",";_debug(f+1,y...);}
	#ifdef LOCAL
	#define gdb(...) _debug((char*)#__VA_ARGS__,__VA_ARGS__)
	#else 
	#define gdb(...) void()
	#endif
}using namespace Debug;
int n,q,X[N],op[N];
const int P=1e9+7;
const int bas=137;
ll pw[N],sum[N];
ll qryHa(int l,int r){
	return (sum[r]+(P-sum[l-1])*pw[r-l+1])%P;
}
struct str{
	vector<int> L,R;
	ll len;
	vector<ll> siz,sum;
	void init(){
		siz.resize(L.size());
		sum.resize(R.size());
		for(int i=0;i<L.size();i++){
			siz[i]=(i?siz[i-1]:0)+R[i]-L[i]+1;
			sum[i]=((i?sum[i-1]:0)*pw[R[i]-L[i]+1]+qryHa(L[i],R[i]))%P;
		}
		len=siz.back();
	}
	ll qry(ll x){
		if(!x) return 0;
		int i=LB(all(siz),x)-siz.begin();
		x-=(i?siz[i-1]:0);
		return ((i?sum[i-1]:0)*pw[x]+qryHa(L[i],L[i]+x-1))%P;
	}
	ll qryS(ll x){
		return (qry(x)+(P-qry(x-1))*bas)%P;
	}
}A[N],B[N];
char s[N];
void readstr(str &A){
	int k;scanf("%d",&k);
	A.L.resize(k);A.R.resize(k);
	for(int i=0;i<k;i++) scanf("%d%d",&A.L[i],&A.R[i]);
}
void rev(str &A){
	swap(A.L,A.R);
	for(int &j:A.L) j=2*n+1-j;
	for(int &j:A.R) j=2*n+1-j;
	reverse(all(A.L));
	reverse(all(A.R));
}
ll LCP(str &A,str &B){
	ll l=0,r=min(A.len,B.len)+1,mid;
	while(l+1<r) mid=l+r>>1,(A.qry(mid)==B.qry(mid)?l:r)=mid;
	return l;
}
int b1[N],e1[N],b2[N],e2[N];
void Sort(str *A,int *bg,int *en){
	static int id[N],ih;
	ih=0;
	for(int i=1;i<=n;i++) if(!A[i].L.empty()) id[++ih]=i;
	sort(id+1,id+ih+1,[&](int x,int y){
		ll len=LCP(A[x],A[y]);
		if(len==min(A[x].len,A[y].len)) return A[x].len<A[y].len;
		return A[x].qryS(len+1)<A[y].qryS(len+1);
	});
	for(int i=1;i<=ih;i++){
		bg[id[i]]=i;
		int l=i,r=ih+1,mid;
		while(l+1<r) mid=l+r>>1,(LCP(A[id[i]],A[id[mid]])==A[id[i]].len?l:r)=mid;
		en[id[i]]=l;
	}
}
struct ques{int x,l,r,id,w;}Q[N];int qh,ans[N];
namespace bit{
	int f[N];
	void add(int x,int w){while(x<=q) f[x]+=w,x+=x&-x;}
	int qry(int x){int ans=0;while(x) ans+=f[x],x-=x&-x;return ans;}
}
void calc(int l=1,int r=qh){
	if(l==r) return;
	int m=l+r>>1;calc(l,m);calc(m+1,r);
	int R=l;
	for(int i=m+1;i<=r;i++){
		while(R<=m&&Q[R].x<=Q[i].x){
			if(Q[R].id==-1) bit::add(Q[R].l,Q[R].w);
			R++;
		}
		if(~Q[i].id) ans[Q[i].id]+=Q[i].w*(bit::qry(Q[i].r)-bit::qry(Q[i].l-1));
	}
	while(R>l){
		R--;
		if(Q[R].id==-1) bit::add(Q[R].l,-Q[R].w);
	}
	inplace_merge(Q+l,Q+m+1,Q+r+1,[](ques x,ques y){return x.x<y.x;});
}
void Solve(){
	scanf("%d%d",&n,&q);
	scanf("%s",s+1);
	for(int i=1;i<=n;i++) s[2*n-i+1]=s[i];
	for(int i=pw[0]=1;i<=2*n;i++) pw[i]=pw[i-1]*bas%P;
	for(int i=1;i<=2*n;i++) sum[i]=(sum[i-1]*bas+s[i])%P;
	for(int i=1;i<=q;i++){
		char c=Gc();
		while(c^'+'&&c^'-'&&c^'?') c=Gc();
		if(c=='+'){
			op[i]=1;
			readstr(A[i]);
			B[i]=A[i];
			rev(B[i]);
			A[i].init();
			B[i].init();
		}else if(c=='-'){
			op[i]=2;
			scanf("%d",&X[i]);
		}else{
			op[i]=3;
			readstr(A[i]);
			readstr(B[i]);
			rev(B[i]);
			A[i].init();
			B[i].init();
		}
	}
	// gdb(LCP(A[1],A[2]));
	// return;
	Sort(A,b1,e1);Sort(B,b2,e2);
	for(int i=1;i<=q;i++){
		if(op[i]==1){
			Q[++qh]=(ques){b1[i],b2[i],b2[i],-1,1};
		}else if(op[i]==2){
			Q[++qh]=(ques){b1[X[i]],b2[X[i]],b2[X[i]],-1,-1};
		}else{
			Q[++qh]=(ques){b1[i]-1,b2[i],e2[i],i,-1};
			Q[++qh]=(ques){e1[i],b2[i],e2[i],i,1};
		}
	}
	calc();
	for(int i=1;i<=q;i++) if(op[i]==3) printf("%d\n",ans[i]);
}
int main(){
	int t=1;
	// scanf("%d",&t);
	while(t--) Solve();
	cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 55196kb

input:

8 7
abcaabbc
+ 3 1 3 2 4 3 8
+ 2 1 4 1 8
+ 1 2 4
? 1 5 6 1 7 8
- 3
+ 1 2 5
? 1 2 3 1 5 5

output:

2
1

result:

ok 2 lines

Test #2:

score: -100
Runtime Error

input:

5 2000
bbaab
+ 1 3 5
+ 2 5 5 3 5
- 2
? 1 1 3 3 3 3 4 5 2 5
- 1
? 3 1 1 2 4 1 5 1 3 4
? 1 1 2 2 2 4 4 4
? 1 1 5 1 5 5
+ 3 1 2 1 5 1 4
? 2 1 5 1 3 2 1 2 5 5
? 1 3 4 1 4 5
- 9
? 1 1 4 1 2 3
+ 2 1 5 1 2
+ 1 1 4
- 15
- 14
? 2 2 5 2 5 1 3 4
+ 1 2 3
- 19
+ 3 1 4 1 5 4 5
- 21
+ 1 2 5
? 3 1 5 5 5 1 5 1 3 5
?...

output:


result: