QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#241651 | #7106. Infinite Parenthesis Sequence | hewanying | AC ✓ | 1282ms | 19124kb | C++14 | 1.5kb | 2023-11-06 15:07:16 | 2023-11-06 15:07:16 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N=1e5+3;
int T,m,n,q,lg[N],st[20][N<<1];
char s[N];
int read(){
int x=0,f=1;char ch=getchar();
while(!isdigit(ch)){if(ch=='-') f=-1;ch=getchar();}
while(isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
return x*f;
}
void print(ll x){
int p[25],tmp=0;
if(x==0) putchar('0');
if(x<0) putchar('-'),x=-x;
while(x) p[++tmp]=x%10,x/=10;
for(int i=tmp;i>=1;i--) putchar(p[i]+'0');
putchar('\n');
}
void init(){
m=0;
for(int i=0;i<n;i++) if(s[i]=='(') st[0][m++]=i;
for(int i=m;i<m*2;i++) st[0][i]=st[0][i-m]+n;
for(int i=0;i<m*2;i++) st[0][i]-=i*2;
for(int i=1;i<20;i++)
for(int j=0;j+(1<<i)-1<m*2;j++)
st[i][j]=min(st[i-1][j],st[i-1][j+(1<<(i-1))]);
}
ll calc(ll k,ll i){
ll L,R;
if(m*2<=n) L=i,R=min(i+k,L+m-1);
else R=i+k,L=max(R-m+1,i);
ll div=(L>=0?L/m:(L+1)/m-1),delta=1ll*n*div-2ll*m*div;
int len=R-L+1,p=lg[len],nw=(L%m+m)%m;
return min(st[p][nw],st[p][nw+len-(1<<p)])+delta+k+2*i;
}
ll query(ll k,ll x){
ll l=-3e9,r=3e9;
while(l<r){
ll mid=(l+r+1)/2;
if(calc(k,mid)<=x) l=mid;
else r=mid-1;
}
return l;
}
void sol(){
scanf("%s",s);
n=strlen(s);init();
q=read();
for(int i=1;i<=q;i++){
ll k=1ll*read(),l=1ll*read(),r=1ll*read();
if(m==0) puts("0");
else print(query(k,r)-query(k,l-1));
}
}
int main(){
lg[1]=0;
for(int i=2;i<N;i++) lg[i]=lg[i>>1]+1;
T=read();
while(T--) sol();
return 0;
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8300kb
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: 331ms
memory: 12312kb
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: 0
Accepted
time: 956ms
memory: 19124kb
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:
ok 700000 lines
Test #4:
score: 0
Accepted
time: 1282ms
memory: 19088kb
input:
5571 ()()(((() 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 971661 lines
Extra Test:
score: 0
Extra Test Passed