QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#864228#1194. Parehtneses Editorcocoa_chan#WA 4ms40536kbC++141.6kb2025-01-20 12:29:022025-01-20 12:29:03

Judging History

你现在查看的是最新测评结果

  • [2025-01-20 12:29:03]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:40536kb
  • [2025-01-20 12:29:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll inf=1e18;
ll n,a[1100000],b[1100000],m,i,j,k,l,r,x,y,z,w,s,t,ans[1100000],query[1100000];
vector<pair<ll,ll>> rollback[1100000];
char c[1100000];
int main()
{
    scanf("%s",c);
    n=strlen(c);
    for(i=1;i<=n;i++)
    {
        if(c[i-1]=='(')
            a[i]=1;
        if(c[i-1]==')')
            a[i]=-1;
        if(c[i-1]=='-')
            a[i]=0;
    }
    t=0;
    z=500000;
    b[z]=1;
    for(i=1;i<=n;i++)
    {
        if(a[i]==1)
        {
            t++;
            z++;
            rollback[t].push_back({inf,s});
            s+=b[z];
            rollback[t].push_back({z,b[z]});
            b[z]=1;
            ans[t]=s;
            query[t]=1;
            printf("%lld\n",s);
        }
        if(a[i]==-1)
        {
            t++;
            b[z]=0;
            rollback[t].push_back({z,b[z]});
            z--;
            rollback[t].push_back({inf,s});
            s+=b[z];
            b[z]++;
            rollback[t].push_back({z,b[z]-1});
            ans[t]=s;
            query[t]=-1;
            printf("%lld\n",s);
        }
        if(a[i]==0)
        {
            for(auto pp:rollback[t])
            {
                if(pp.first==inf)
                {
                    s=pp.second;
                    continue;
                }
                b[pp.first]=pp.second;
            }
            if(query[t]==1)
                z--;
            else
                z++;
            t--;
            printf("%lld\n",ans[t]);
        }
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 38752kb

input:

(()())---)

output:

0
0
1
1
3
4
3
1
1
2

result:

ok 10 numbers

Test #2:

score: 0
Accepted
time: 1ms
memory: 38904kb

input:

()--()()----)(()()))

output:

0
1
0
0
0
1
1
3
1
1
0
0
0
0
0
1
1
3
4
4

result:

ok 20 numbers

Test #3:

score: -100
Wrong Answer
time: 4ms
memory: 40536kb

input:

))(((-)(()((---(-)(-())-(()()(-)--(())))--()((())-)(()(())((-))))(-(((()((()()()()))-(())((((--))-())-)(-(--))))((((-)(-(-)((((()--(---)(-))()(-)(()()-(())()(()()((()()))))(()(()(-(--)-()((()(((()-))-)(()-()()-(-((-)(-)(((()-)))))-())()-(()((()(-)()))((-))())))()()()(-(-(())-()(()-)-))((()))((--(-()...

output:

0
0
0
0
0
0
1
1
1
2
2
2
2
2
1
1
1
2
2
2
2
4
6
4
4
4
5
5
7
7
7
7
7
5
5
5
6
6
8
8
8
6
6
6
6
6
6
7
8
7
8
8
8
9
9
9
10
12
12
12
12
15
17
18
20
20
20
20
20
20
20
21
21
21
21
22
22
24
24
27
27
31
32
34
32
32
32
33
33
33
33
33
33
33
33
34
35
34
34
34
35
34
35
35
35
35
35
34
35
37
38
39
39
39
39
39
39
40
40...

result:

wrong answer 32nd numbers differ - expected: '10', found: '7'