QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#177239 | #7106. Infinite Parenthesis Sequence | 275307894a | WA | 270ms | 12256kb | C++14 | 1.8kb | 2023-09-12 18:35:02 | 2023-09-12 18:35:03 |
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;
assert(x>=1&&x<=ph/2);
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<<flag<<'\n';
// cerr<<qry(6,1)<<'\n';
int q;scanf("%d",&q);
while(q--){
int x,y,k;scanf("%d%d%d",&k,&x,&y);
if(flag) x=n-x-1,y=n-y-1,swap(x,y);
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: 1ms
memory: 8084kb
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: 270ms
memory: 12256kb
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:
wrong answer 279th lines differ - expected: '1172759948', found: '203071625'