QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#244533#7106. Infinite Parenthesis SequenceSkyjoyRE 1ms5196kbC++141.4kb2023-11-09 11:19:122023-11-09 11:19:13

Judging History

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

  • [2023-11-09 11:19:13]
  • 评测
  • 测评结果:RE
  • 用时:1ms
  • 内存:5196kb
  • [2023-11-09 11:19:12]
  • 提交

answer

#include<bits/stdc++.h>
#define I using
#define love namespace
#define Elaina std
#define ll long long
I love Elaina;
const int N=100010;
ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return x*f;
}
ll T,n,m,k,x,y,z,st[N<<1][20],lg[N<<1];
char str[N];
vector<int>pos;
ll query(int ql,int qr){
	int k=lg[qr-ql+1];
	return min(st[ql][k],st[qr-(1<<k)+1][k]);
}
ll calcf(ll x,ll y){
	ll l,r;
	if(n>=2*k)l=y,r=min(x+y,y+k-1);
	else l=max(y,x+y-k+1),r=x+y;
	return query((l%k+k)%k,(l%k+k)%k+r-l)+(l-(l%k+k)%k)/k*(n-2*k)+2*y+x;
}
ll calcg(ll x,ll y){
	ll l=-2e9,r=2e9,res=-2e9;
	while(l<=r){
		ll mid=(l+r)/2;
		if(calcf(x,mid)<=y)res=mid,l=mid+1;
		else r=mid-1;
	}
	return res;
}
int main(){
	lg[0]=-1;
	for(int i=1;i<=200000;i++)lg[i]=lg[i>>1]+1;
	T=read();
	while(T--){
		pos.clear();
		scanf("%s",str);
		n=strlen(str),m=read();
		for(int i=0;i<n;i++)if(str[i]=='(')pos.push_back(i);
		k=pos.size();
		for(int i=0;i<k;i++)st[i][0]=pos[i];
		for(int i=k;i<2*k;i++)st[i][0]=st[i-k][0]+n;
		for(int i=0;i<2*k;i++)st[i][0]-=2*i;
		for(int j=1;j<20;j++)for(int i=0;i<2*k-(1<<j)+1;i++)st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]);
		while(m--){
			x=read(),y=read(),z=read();
			printf("%lld\n",calcg(x,z)-calcg(x,y-1));
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 5196kb

input:

3
(())
3
0 -3 2
1 -2 3
2 0 0
))()(
3
0 -3 4
2 1 3
3 -4 -1
))()(()(
4
1234 -5678 9012
123 -456 789
12 -34 56
1 -2 3

output:

3
3
0
4
1
1
7345
623
45
3

result:

ok 10 lines

Test #2:

score: -100
Runtime Error

input:

5564
()()(((()
16
0 -825489608 537105171
0 481386502 824237183
0 -32590250 515314371
0 -634830457 908018223
3 -494274112 299679416
125527658 81646800 208166552
632660143 -774899605 -551752339
4 -874787302 127206822
4 -102348267 122390255
2 -881139944 898929361
0 -656262874 -233671414
111787130 -5925...

output:


result: