QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#244445#7106. Infinite Parenthesis SequenceThe_Last_CandyRE 0ms4584kbC++141.6kb2023-11-09 07:38:212023-11-09 07:38:22

Judging History

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

  • [2023-11-09 07:38:22]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:4584kb
  • [2023-11-09 07:38:21]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5;
char a[N];
int q,n,m,f[20][N * 2],lg[N];
typedef long long ll;
inline void init()
{
	m = 0;
	for(int i = 0;i < n;i++)
		if(a[i] == '(') f[0][m++] = i;
	for(int i = m;i < 2 * m;i++)
		f[0][i] = f[0][i - m] + n;
	for(int i = 0;i < 2 * m;i++) f[0][i] -= 2 * i;
	for(int i = 1;i <= 19;i++)
		for(int j = 0;j < 2 * m;j++)
			f[i][j] = min(f[i - 1][j],f[i - 1][j + (1 << (i - 1))]);
}
inline int query(ll l,ll r)
{
	int len = min(r - l + 1,1ll * m);
	if(n - 2 * m >= 0) r = l + len - 1;
	else l = r - len + 1;
	ll ori = l;
	l = (l % m + m) % m;
	int dt = (ori >= 0 ? ori / m : ((ori + 1) / m - 1)),g = lg[len];
	return min(f[g][l],f[g][l + len - (1 << g)]) + dt * (n - 2 * m);
}
inline int num(int k,int x)
{
	ll l = -3e9,r = 3e9;
	while(l < r)
	{
		ll mid = (l + r + 1) >> 1;
		if(query(mid,mid + k) + k + 2ll * mid <= x) l = mid;
		else r = mid - 1;
	}
	return l;
}
inline int read()
{
	int s = 0,w = 1; char k = getchar();
	while(!isdigit(k)) {if(k == '-') w = -w; k = getchar();}
	while(isdigit(k)) s = (s << 3) + (s << 1) + (k ^ 48),k = getchar();
	return s * w;
}
inline void gets()
{
	n = 0;
	char k = getchar();
	while(k != ')' && k != '(') k = getchar();
	while(k == ')' || k == '(')
	{
		a[n] = k;
		++n;
		k = getchar();
	}
}
signed main()
{
	int T;
	T = read();
	lg[0] = -1;
	for(int i = 1;i < N;i++) lg[i] = lg[i >> 1] + 1;
	while(T--)
	{
		gets();
		init();
		q = read();
		for(int i = 1,k,l,r;i <= q;i++)
		{
			k = read();l = read();r = read();
			printf("%d\n",num(k,r) - num(k,l - 1));
		}
	}
	return 0; 
 } 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: