QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#177229 | #7106. Infinite Parenthesis Sequence | 275307894a | WA | 256ms | 14032kb | C++14 | 1.8kb | 2023-09-12 18:20:40 | 2023-09-12 18:20:40 |
Judging History
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
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>;using LL=__int128;
const int N=2e5+5,M=N*20+5,K=600+5,mod=998244353,Mod=mod-1;const db eps=1e-9;const ll INF=1e18+7;mt19937 rnd(time(0));
int n,A[N],Sum[N],pl[N],ph;char s[N];
int st[20][N];
int qst(int x,int y){int d=__lg(y-x+1);return min(st[d][x],st[d][y-(1<<d)+1]);}
int calc(int x,int k){
int ans=0,y=x/(ph/2);
ans=y*n;
x-=y*(ph/2);
while(x<=0) x+=ph/2,ans-=n;
return ans+qst(x,min(ph,x+k))+k+2*x;
}
int qry(int x,int k){
int l=-1e9-1,r=1e9+1,mid;
while(l+1<r) mid=l+r>>1,(calc(mid,k)<=x?l:r)=mid;
return l;
}
void Solve(){
int i,j;scanf("%s",s+1);n=strlen(s+1);
for(i=1;i<=n;i++) A[i]=(s[i]^')'?1:0);
int Ct=0;for(i=1;i<=n;i++) Ct+=A[i];
int flag=0;if(Ct*2>n){for(i=1;i<=n;i++) A[i]^=1;reverse(A+1,A+n+1);flag=1;}
for(i=n+1;i<=2*n;i++) A[i]=A[i-n];
ph=0;for(i=1;i<=2*n;i++) if(A[i]) pl[++ph]=i;
for(i=1;i<=2*n;i++) Sum[i]=Sum[i-1]+A[i];
for(i=1;i<=ph;i++) st[0][i]=pl[i]-2*i;
for(i=1;(1<<i)<=ph;i++) {
for(j=1;j+(1<<i)-1<=ph;j++) st[i][j]=min(st[i-1][j],st[i-1][j+(1<<i-1)]);
}
// cerr<<ph<<'\n';
// cerr<<qry(6,1)<<'\n';
int q;scanf("%d",&q);
while(q--){
int x,y,k;scanf("%d%d%d",&k,&x,&y);x++;y++;
if(flag) x*=-1,y*=-1,swap(x,y);
int ans=0;
if(ph) ans=qry(y,k)-qry(x-1,k);
if(flag) ans=y-x+1-ans;printf("%d\n",ans);
}
}
int main(){
int t=1;
scanf("%d",&t);
while(t--) Solve();
cerr<<clock()*1.0/CLOCKS_PER_SEC<<'\n';
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7868kb
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
Wrong Answer
time: 256ms
memory: 14032kb
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 365269748 1028565788 529302352 84346502 148764845 667996084 149825682 1186712870 281727641 995600518 63752581 740373708 867951695 27044668 530591273 345487789 415550920 701803794 413364406 187916461 386485772 125057025 296666742 470522532 367131179 635722815 58970215 379425066 18...
result:
wrong answer 3rd lines differ - expected: '365269747', found: '365269748'