UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215001#2037. awujiachen010ms1308kbC++1.3kb2024-11-25 19:39:212024-11-25 23:05:24

answer

#include<bits/stdc++.h>
using namespace std;
int a[1000005];
int ll[1000005],rr[1000005];
int main(){
    string s;
    cin>>s;
    int cnt=0;
    //cout<<"L"<<endl;
    for(int i=0;i<s.size();i++){
        if(s[i]=='('){
            cnt++;
        }
        else if(cnt){
            cnt--;
            ll[i+1]+=2;
        }
        ll[i+1]+=ll[i];
        //cout<<i+1<<" "<<ll[i+1]<<endl;
    }
    //cout<<"R"<<endl;
    cnt=0;
    for(int i=s.size()-1;i>=0;i--){
        if(s[i]==')'){
            cnt++;
        }
        else if(cnt){
            cnt--;
            rr[i+1]+=2;
        }
        rr[i+1]+=rr[i+2];
        //cout<<i+1<<" "<<rr[i+1]<<endl;
    }
    int n;
    cin>>n;
    //cout<<"ANS"<<endl;
    for(int i=1;i<=n;i++){
        int l,r;
        scanf("%d%d",&l,&r);
        l--,r--;
        int sum=0,ans=0;
        for(int j=l;j<=r;j++){
            if(s[j]=='('){
                sum++;
            }
            if(s[j]==')'&&sum){
                sum--;
                ans++;
            }
        }
        ans=ll[s.size()]-ll[l]-rr[r];
        if(l!=1){
            if(s[l-2]=='(')ans-=2;
        }
        if(r!=s.size()){
            if(s[r]==')')ans-=2;
        }
        cout<<ans<<endl;
    }
}

详细

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

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 1304kb

input:

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

output:

856
184
114
20
846
252
592
328
568
320
278
396
828
528
222
326
572
554
496
108
184
60
850
318
370
31...

result:

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

Test #2:

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

input:

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

output:

40
30
112
388
280
166
388
82
452
118
606
462
124
82
350
268
340
32
168
214
324
70
382
484
90
486
58
...

result:

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

Test #3:

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

input:

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

output:

724
242
98
228
254
310
418
792
236
230
224
626
452
338
290
420
294
522
164
498
240
736
286
242
830
4...

result:

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

Test #4:

score: 0
Wrong Answer
time: 3ms
memory: 1308kb

input:

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

output:

202
392
262
422
560
354
84
524
740
318
226
422
82
474
422
228
196
622
216
164
932
448
556
74
118
456...

result:

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

Test #5:

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

input:

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

output:

642
394
360
6
264
382
234
428
274
172
262
466
324
130
538
140
606
798
128
158
72
470
264
172
24
326
...

result:

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

Test #6:

score: 0
Wrong Answer
time: 3ms
memory: 1308kb

input:

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

output:

728
248
600
214
792
174
298
216
36
688
282
274
660
348
818
482
424
736
114
172
414
468
170
22
304
77...

result:

wrong answer 2nd lines differ - expected: '224', found: '248'

Test #7:

score: 0
Time Limit Exceeded

input:

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

output:

143186
236824
447118
759794
135124
749474
84008
686384
32606
573010
367194
68232
19006
604352
946622...

result:


Test #8:

score: 0
Time Limit Exceeded

input:

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

output:

583832
426132
255528
448890
201182
257878
168292
115832
55738
440600
138654
880308
580632
453454
991...

result:


Test #9:

score: 0
Time Limit Exceeded

input:

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

output:

48126
241612
324404
554800
111980
21412
52138
170140
82714
124962
108084
804880
123678
274588
136338...

result:


Test #10:

score: 0
Time Limit Exceeded

input:

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

output:

489608
427036
421224
177688
495200
783242
64140
27950
111518
309178
355654
304218
698832
3286
145742...

result: