UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#215026#2037. awujiachen01753ms12032kbC++1.1kb2024-11-25 20:09:592024-11-25 23:08:40

answer

#include<bits/stdc++.h>
using namespace std;
int a[1000005];
int ll[1000005],rr[1000005];
bool ll1[1000005],rr1[1000005];
stack<int> st;
int main(){
    string s;
    cin>>s;
    int cnt=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='('){
            cnt++;
            st.push(i+1);
        }
        else if(cnt){
            cnt--;
            ll1[st.top()]=1;
            st.pop();
            ll[i+1]+=2;
        }
        ll[i+1]+=ll[i];
    }
    while(st.size()){
        st.pop();
    }
    cnt=0;
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]==')'){
            cnt++;
            st.push(i+1);
        }
        else if(cnt){
            cnt--;
            rr1[st.top()]=1;
            st.pop();
            rr[i+1]+=2;
        }
        rr[i+1]+=rr[i+2];
    }
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        int l,r,ans=0;
        scanf("%d%d",&l,&r);
        ans=ll[s.size()]-ll[l-1]-rr[r+1];
        if(l!=1&&ll1[l-1]){
            if(s[l-2]=='(')ans-=2;
        }
        if(r!=s.size()&&rr1[r+1]){
            if(s[r]==')')ans-=2;
        }
        printf("%d\n",ans);
    }
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 1296kb

input:

(()))())))(())()())()()))((((()()))((((()((())()))(()((((()(())(())(()))())()())()())(())(()()((((((...

output:

862
182
116
24
850
252
594
330
568
322
282
398
830
530
224
330
574
558
498
112
186
64
852
318
374
32...

result:

wrong answer 1st lines differ - expected: '854', found: '862'

Test #2:

score: 0
Wrong Answer
time: 0ms
memory: 1300kb

input:

)))((()())((())((()()())())(((())())((()((())(())()((((((())))((()(()())))(()()(())())()))(()()))(((...

output:

44
30
116
392
280
168
388
84
456
122
608
464
124
84
350
266
342
32
170
216
324
72
382
486
90
484
62
...

result:

wrong answer 1st lines differ - expected: '30', found: '44'

Test #3:

score: 0
Wrong Answer
time: 0ms
memory: 1296kb

input:

(()((())))))))((())(()()))()))()()())(()))(())))))))(((())((((((((((()((()())()(()(())(()())(()))(((...

output:

724
242
100
228
258
312
424
794
236
232
224
628
458
336
294
424
294
526
168
500
244
738
288
242
828
...

result:

wrong answer 1st lines differ - expected: '674', found: '724'

Test #4:

score: 0
Wrong Answer
time: 0ms
memory: 1300kb

input:

))))))))()))())()(()()())()())(((()())(((()(((()()))(()()()))())(()()(()()())()(())()())))))()((((()...

output:

202
396
264
426
562
356
90
526
746
316
230
422
86
478
428
230
198
626
220
166
934
452
554
74
120
458...

result:

wrong answer 1st lines differ - expected: '168', found: '202'

Test #5:

score: 0
Wrong Answer
time: 1ms
memory: 1300kb

input:

((())))(()((()()))()))))((((()()()()()()()))()()(()(())(()((()))()((())))))()(((()())()))()())))(())...

output:

644
398
362
8
270
382
236
430
276
174
260
466
328
132
538
144
606
798
126
160
74
472
264
172
28
330
...

result:

wrong answer 1st lines differ - expected: '634', found: '644'

Test #6:

score: 0
Wrong Answer
time: 0ms
memory: 1296kb

input:

))((()))()(())())(()()))))()()((((()()())()((())(())))))(())))()())()()(())()(())())(()())))(()()))(...

output:

732
252
600
218
794
180
298
220
38
688
284
274
660
348
822
482
426
740
116
174
418
466
172
22
306
77...

result:

wrong answer 1st lines differ - expected: '728', found: '732'

Test #7:

score: 0
Wrong Answer
time: 453ms
memory: 12032kb

input:

((((()))()()())(()))((()())(((())))(()((()))))))()()))()))((((()(()(()()()(()(())(()())))(((()())))(...

output:

143186
236826
447120
759794
135124
749474
84010
686388
32606
573012
367196
68234
19004
604358
946622...

result:

wrong answer 1st lines differ - expected: '142860', found: '143186'

Test #8:

score: 0
Wrong Answer
time: 428ms
memory: 12028kb

input:

())))()))))(()))()())(()(()))((()))))(()))((())()((()(()()((())(())()))(()))))())(((()(())()(())()()...

output:

583834
426134
255526
448890
201186
257882
168294
115834
55738
440604
138656
880312
580636
453458
991...

result:

wrong answer 1st lines differ - expected: '583148', found: '583834'

Test #9:

score: 0
Wrong Answer
time: 442ms
memory: 12032kb

input:

)()((()())(())())(()())))(((()())()()(((((()(()()(()(())(()())((()(((()()))()))))()(((())(((((()()()...

output:

48130
241610
324408
554802
111986
21414
52140
170140
82718
124964
108086
804884
123680
274590
136340...

result:

wrong answer 1st lines differ - expected: '47942', found: '48130'

Test #10:

score: 0
Wrong Answer
time: 429ms
memory: 12028kb

input:

())()()(()())))())())))))))(()((()()(((()))(()(())))(())))())(()((()))()))(()))()((((((())(())(())((...

output:

489608
427038
421228
177692
495202
783244
64140
27950
111520
309178
355656
304218
698834
3286
145744...

result:

wrong answer 1st lines differ - expected: '487878', found: '489608'