QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#244446#7106. Infinite Parenthesis SequenceThe_Last_CandyRE 287ms4984kbC++141.7kb2023-11-09 07:39:262023-11-09 07:39:26

Judging History

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

  • [2023-11-09 07:39:26]
  • 评测
  • 测评结果:RE
  • 用时:287ms
  • 内存:4984kb
  • [2023-11-09 07:39:26]
  • 提交

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)
{
	if(!m) return 0; 
	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; 
 } 

详细

Test #1:

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

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: 0
Accepted
time: 287ms
memory: 4984kb

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:

908396520
228567121
365269747
1028565788
529302353
84346502
148764845
667996084
149825682
1186712870
281727640
995600518
63752581
740373707
867951696
27044667
530591272
345487789
415550920
701803793
413364407
187916462
386485772
125057026
296666743
470522533
367131179
635722815
58970215
379425066
18...

result:

ok 271661 lines

Test #3:

score: -100
Runtime Error

input:

7
((()(((()(((()((()((()((()(((()(((()((()(((()(((()((()(((()(((()(((()(((()((()(((()((()((()(((()(((()(((()((()((()(((()((()((()(((()(((()(((()((()(((()((()(((()((()((()(((()(((()(((()(((()((()(((()(((()((()((()((()(((()(((()((()(((()(((()(((()((()(((()(((()((()((()(((()(((()(((()((()((()(((()((()(...

output:

185704843
446800089
255099554
1156402
212636323
416191407
12472890
247228052
489620931
107469522
16222287
341270888
29184920
107393597
163613521
175919552
118376824
76183214
805506070
206363476
326077675
54361969
121810843
684646392
716061472
697723268
23956954
588434738
4870237
305505833
489380166
...

result: