ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#214989 | #2037. a | jsxheng | 0 | 1581ms | 57600kb | C++11 | 1.8kb | 2024-11-25 19:20:53 | 2024-11-25 23:03:08 |
answer
#include<bits/stdc++.h>
#define int long long
#define N 1000010
#define ls now<<1
#define rs now<<1|1
using namespace std;
namespace IO{
template<typename T> inline void read(T &x){
bool f=1;x=0;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=0;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<1)+(x<<3)+(ch&15),ch=getchar();
x=f?x:-x;
}
template<typename T> inline void write(T x){
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(('0'+x%10));
}
template <typename T,typename ...Args> inline void read(T &x,Args &...args){read(x);read(args...);}
template<typename T> inline void write(T x,char c){write(x),putchar(c);}
}
using namespace IO;
char c[1000005];
int n,Q,sum[1000005],st[1000005],top;
int l[1000005],r[1000005],v[1000005];
int a[1000005],tr[4000005];
void init(int l,int r,int now){
if(l==r){
tr[now]=a[l];
return;
}
int mid=(l+r)>>1;
init(l,mid,ls);
init(mid+1,r,rs);
tr[now]=min(tr[ls],tr[rs]);
}
inline int query(int now,int l,int r,int tol,int tor){
if(tol<=l&&r<=tor) return tr[now];
int res=n,mid=(l+r)>>1;
if(tol<=mid)res=min(res,query(ls,l,mid,tol,tor));
if(tor>mid) res=min(res,query(rs,mid+1,r,tol,tor));
return res;
}
signed main(){
scanf("%s",c+1);read(Q);
n=strlen(c+1);
for(int i=1;i<=n;++i){
if(!top && c[i]==')')v[i]=1;
else if(c[i]=='(')st[++top]=i;
else{
sum[i]=st[top],sum[st[top]]=i;
a[st[top]]++,a[i+1]--;
l[st[top]+1]++,l[i+1]--;
r[st[top]]++,r[i]--;
top--;
}
}
for(;top;--top) v[st[top]]=1;
for(int i=1;i<=n;++i){
a[i]+=a[i-1];
r[i]+=r[i-1];
l[i]+=l[i-1];
}
for(int i=1;i<=n;++i)a[i]-=!v[i],v[i]+=v[i-1];
init(1,n,1);
for(int i=1,x,y;i<=Q;++i){
read(x,y);
write(max(0ll,y-x+1-(v[y]-v[x-1])-r[y]-l[x]+query(1,n,1,x,y)*2),'\n');
}
}
Details
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 1244kb
input:
(()))())))(())()())()()))((((()()))((((()((())()))(()((((()(())(())(()))())()())()())(())(()()((((((...
output:
854 116 108 12 836 206 550 228 526 266 220 344 830 486 158 278 522 512 464 98 160 0 840 298 324 256 ...
result:
wrong answer 2nd lines differ - expected: '136', found: '116'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 1240kb
input:
)))((()())((())((()()())())(((())())((()((())(())()((((((())))((()(()())))(()()(())())()))(()()))(((...
output:
22 22 96 382 252 154 386 56 434 102 590 456 114 56 346 252 324 0 138 184 320 36 380 470 62 476 40 41...
result:
wrong answer 1st lines differ - expected: '30', found: '22'
Test #3:
score: 0
Wrong Answer
time: 0ms
memory: 1244kb
input:
(()((())))))))((())(()()))()))()()())(()))(())))))))(((())((((((((((()((()())()(()(())(()())(()))(((...
output:
674 168 100 150 202 226 378 746 166 196 196 602 398 276 210 358 202 468 154 434 152 704 216 232 810 ...
result:
wrong answer 2nd lines differ - expected: '192', found: '168'
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 1240kb
input:
))))))))()))())()(()()())()())(((()())(((()(((()()))(()()()))())(()()(()()())()(())()())))))()((((()...
output:
164 374 232 376 548 324 48 488 724 270 180 394 66 448 404 188 192 594 188 120 918 420 516 20 108 430...
result:
wrong answer 1st lines differ - expected: '168', found: '164'
Test #5:
score: 0
Wrong Answer
time: 0ms
memory: 1240kb
input:
((())))(()((()()))()))))((((()()()()()()()))()()(()(())(()((()))()((())))))()(((()())()))()())))(())...
output:
634 386 334 6 246 372 226 424 274 168 254 448 312 112 532 126 594 780 112 150 68 470 260 150 22 322 ...
result:
wrong answer 32nd lines differ - expected: '18', found: '14'
Test #6:
score: 0
Wrong Answer
time: 0ms
memory: 1244kb
input:
))((()))()(())())(()()))))()()((((()()())()((())(())))))(())))()())()()(())()(())())(()())))(()()))(...
output:
728 224 580 200 784 142 280 194 0 664 274 260 630 328 816 470 388 736 82 130 406 440 136 10 276 776 ...
result:
wrong answer 6th lines differ - expected: '152', found: '142'
Test #7:
score: 0
Wrong Answer
time: 394ms
memory: 57596kb
input:
((((()))()()())(()))((()())(((())))(()((()))))))()()))()))((((()(()(()()()(()(())(()())))(((()())))(...
output:
142860 235344 446706 759772 133780 748980 83870 685562 31586 572204 366368 67746 18468 603330 946486...
result:
wrong answer 5th lines differ - expected: '134088', found: '133780'
Test #8:
score: 0
Wrong Answer
time: 411ms
memory: 57592kb
input:
())))()))))(()))()())(()(()))((()))))(()))((())()((()(()()((())(())()))(()))))())(((()(())()(())()()...
output:
583148 425884 254906 448502 200322 256890 167298 114904 55178 440164 138094 879918 580038 452166 982...
result:
wrong answer 3rd lines differ - expected: '255036', found: '254906'
Test #9:
score: 0
Wrong Answer
time: 396ms
memory: 57596kb
input:
)()((()())(())())(()())))(((()())()()(((((()(()()(()(())(()())((()(((()()))()))))()(((())(((((()()()...
output:
47942 241400 323510 553980 111490 19942 51890 169422 82080 124416 107806 804528 123414 274334 135650...
result:
wrong answer 6th lines differ - expected: '20570', found: '19942'
Test #10:
score: 0
Wrong Answer
time: 380ms
memory: 57600kb
input:
())()()(()())))())())))))))(()((()()(((()))(()(())))(())))())(()((()))()))(()))()((((((())(())(())((...
output:
487878 425694 419984 176404 493462 782462 63276 27400 109092 308166 354282 302574 697816 3128 144600...
result:
wrong answer 8th lines differ - expected: '27548', found: '27400'