QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#431290#7973. 括号Kalenist0 2ms22492kbC++205.1kb2024-06-05 10:28:192024-06-05 10:29:00

Judging History

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

  • [2024-06-05 10:29:00]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:22492kb
  • [2024-06-05 10:28:19]
  • 提交

answer

#include<bits/stdc++.h>
#define N 200010
#define pii pair<int,int>
#define fi first
#define se second
#define ll long long
#define lc k<<1
#define rc k<<1|1
#define inf 0x3f3f3f3f
#define For(i,a,b) for(register int i=a;i<=b;i++)
#define Down(i,a,b) for(register int i=a;i>=b;i--)
using namespace std;
int n,m,a[N],v[N],sum,cnt,pos[N];
int x[N*3],y[N*3],cp[N*3],num[30];
int val[N<<2],adt[N<<2],in[N];
pii mx[N<<2],mn[N<<2];
ll ans[N*3];
char s[N];
bool mark[N];
inline pii min(pii a,pii b){return pii(min(a.fi,b.fi),a.fi<b.fi?a.se:b.se);}
inline pii max(pii a,pii b){return pii(max(a.fi,b.fi),a.fi>b.fi?a.se:b.se);}
inline void upd(int k,int d){val[k]+=d,adt[k]+=d;}
inline int read()
{
    register int x=0,c=getchar();
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
    return x;
}

inline void print(ll x)
{
    num[0]=0;
    while(x) num[++num[0]]=x%10,x/=10;
    while(num[0]) putchar(num[num[0]--]+'0');
    return void(putchar('\n'));
}

inline void pushdown(int k)
{
    if(!adt[k]) return;
    upd(lc,adt[k]),upd(rc,adt[k]);
    return void(adt[k]=0);
}

inline void build(int k,int l,int r)
{
    mx[k]=pii(-inf,0);
    mn[k]=pii(inf,0);
    adt[k]=val[k]=0;
    if(l == r) return;
    int mid=l+r>>1;
    return build(lc,l,mid),build(rc,mid+1,r);
}

inline void modify(int k,int l,int r,int x,int y,int d)
{
    if(l >= x && r <= y) return upd(k,d);
    int mid=l+r>>1;pushdown(k);
    if(x <= mid) modify(lc,l,mid,x,y,d);
    if(mid < y) modify(rc,mid+1,r,x,y,d);
    return void(val[k]=max(val[lc],val[rc]));
}

inline int findl(int k,int l,int r,int pos)
{
    if(val[k] < 0) return 0;
    if(l == r) return l;
    int mid=l+r>>1,res=0;pushdown(k);
    if(mid < pos) res=findl(rc,mid+1,r,pos);
    return res?res:findl(lc,l,mid,pos);
}

inline int findr(int k,int l,int r,int pos)
{
    if(val[k] < 0) return cnt;
    if(l == r) return l;
    int mid=l+r>>1,res=cnt;pushdown(k);
    if(pos <= mid) res=findr(lc,l,mid,pos);
    return res<cnt?res:findr(rc,mid+1,r,pos);
}

inline int query(int k,int l,int r,int x,int y)
{
    if(l >= x && r <= y) return val[k];
    int mid=l+r>>1,res=-inf;pushdown(k);
    if(x <= mid) res=max(res,query(lc,l,mid,x,y));
    if(mid < y) res=max(res,query(rc,mid+1,r,x,y));
    return res;
}

inline void change(int k,int l,int r,int pos,int t)
{
    if(l == r)
    {
        if(t) mn[k]=pii(inf,0),mx[k]=pii(v[l],l);
        else mn[k]=pii(v[l],l),mx[k]=pii(-inf,0);
        return;
    }int mid=l+r>>1;
    if(pos <= mid) change(lc,l,mid,pos,t);
    else change(rc,mid+1,r,pos,t);
    mn[k]=min(mn[lc],mn[rc]);
    mx[k]=max(mx[lc],mx[rc]);
    return;
}

inline pii qmx(int k,int l,int r,int x,int y)
{
    if(l >= x && r <= y) return mx[k];
    int mid=l+r>>1;pii res(-inf,0);
    if(x <= mid) res=max(res,qmx(lc,l,mid,x,y));
    if(mid < y) res=max(res,qmx(rc,mid+1,r,x,y));
    return res;
}

inline pii qmn(int k,int l,int r,int x,int y)
{
    if(l >= x && r <= y) return mn[k];
    int mid=l+r>>1;pii res(inf,0);
    if(x <= mid) res=min(res,qmn(lc,l,mid,x,y));
    if(mid < y) res=min(res,qmn(rc,mid+1,r,x,y));
    return res;
}

inline void ins(int x,ll &ans)
{
    int nmx=query(1,1,cnt,x,cnt);
    if(nmx > 0)
    {
        change(1,1,cnt,x,1),ans+=v[x];
        modify(1,1,cnt,x,cnt,-1),in[x]=1;
    }
    else
    {
        int np=x>1?findl(1,1,cnt,x-1):0;
        pii nw=qmx(1,1,cnt,np+1,cnt);
        if(nw.fi <= v[x]) return change(1,1,cnt,x,0);
        ans+=v[x]-nw.fi;
        in[x]=1,in[nw.se]=0;
        change(1,1,cnt,x,1);
        change(1,1,cnt,nw.se,0);
        modify(1,1,cnt,x,cnt,-1);
        modify(1,1,cnt,nw.se,cnt,1);
    }
    return;
}

inline void del(int x,ll &ans)
{
    if(!in[x]) return;
    int np=findr(1,1,cnt,x);
    pii nw=qmn(1,1,cnt,1,np);
    ans-=v[x],change(1,1,cnt,x,0);
    modify(1,1,cnt,x,cnt,1),in[x]=0;
    if(nw.fi == inf) return;
    ans+=nw.fi,change(1,1,cnt,nw.se,1);
    modify(1,1,cnt,nw.se,cnt,-1),in[nw.se]=1;
    return;
}

inline void solve()
{
    while(cnt && !mark[cnt]) cnt--;
    if(!cnt) return;
    build(1,1,cnt);
    For(i,1,cnt) if(mark[i])
        modify(1,1,cnt,i,cnt,1);
    For(i,1,cnt) ins(i,ans[0]);
    For(i,1,m)
    {
        ans[i]=ans[i-1];
        if(cp[i] && cp[i] <= cnt)
        {
            del(cp[i],ans[i]);
            v[cp[i]]=y[i];
            ins(cp[i],ans[i]);
        }
    }
    return;
}

int main()
{
    n=read()<<1,m=read();
    For(i,1,n) a[i]=read();
    scanf("%s",s+1);
    For(i,1,m) x[i]=read(),y[i]=read();
    For(i,1,n)
    {
        if(s[i] == ')') v[++cnt]=a[i],pos[i]=cnt;
        sum+=s[i]=='('?1:-1;
        if(sum < 0) mark[cnt]=true,sum=1;
    }For(i,1,m) cp[i]=pos[x[i]];
    solve(),sum=cnt=0;
    memset(mark,false,sizeof(mark));
    memset(pos,0,sizeof(pos));
    memset(in,0,sizeof(in));
    Down(i,n,1)
    {
        if(s[i] == '(') v[++cnt]=a[i],pos[i]=cnt;
        sum+=s[i]==')'?1:-1;
        if(sum < 0) mark[cnt]=true,sum=1;
    }For(i,1,m) cp[i]=pos[x[i]];
    solve();
    For(i,0,m) printf("%lld\n",ans[i]);
    return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

input:

100 100
655884441 790777510 663667368 332762945 67681448 458058488 445481314 200508190 812326927 374891900 320371513 765529851 490260632 588113266 286392696 888016940 214376080 894477437 944447014 386015667 956960774 692332579 606560669 561835357 887377361 130572961 550186106 193341110 4130416 66982...

output:

1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
1883520337
188...

result:

wrong answer 2nd lines differ - expected: '1938040724', found: '1883520337'

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 0
Wrong Answer
time: 2ms
memory: 21076kb

input:

1000 1000
851064227 277152131 421722407 126468670 510326499 619107836 287335428 653386549 173788833 304176934 21753544 293653999 493165671 887566717 813114839 976556173 459946448 939807420 605205411 920860669 545229689 895277168 777349694 126341157 564711820 892644312 314220085 125767094 816813109 9...

output:

2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
2793453944
279...

result:

wrong answer 2nd lines differ - expected: '2784207960', found: '2793453944'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #14:

score: 5
Accepted
time: 0ms
memory: 22492kb

input:

1000 1000
49658 21707 94558 56676 18487 74906 55206 78654 54538 14591 105694 138 3148 106151 90191 67461 90337 86524 39272 78899 111590 3181 67245 47146 1958 34378 6544 74125 93643 44483 2159 16309 41619 24332 1519 85340 25811 55827 51528 89913 71355 103446 97370 44299 107887 105014 44419 62592 1965...

output:

13395019
13351991
13351991
13351991
13351991
13351991
13351991
13351991
13351991
13381782
13345375
13349826
13338684
13322461
13322461
13322461
13322461
13322461
13306716
13289968
13289968
13289968
13290694
13282032
13302932
13286589
13317058
13317058
13360189
13360189
13360189
13360189
13390898
133...

result:

ok 1001 lines

Test #15:

score: 5
Accepted
time: 0ms
memory: 21236kb

input:

1000 1000
48741 78915 65982 52179 49201 75885 71026 47007 75592 105723 58292 60053 94233 34736 3710 50633 88449 99895 6144 61740 40074 112109 81809 59449 27344 83326 27661 35015 77525 23183 80535 33235 2240 78293 2764 106350 97971 96527 35415 39791 85893 54169 7133 70924 78499 65993 50156 97046 1068...

output:

681032
681032
681032
681032
681032
681032
681032
681032
681032
681032
681032
681032
681032
681032
681032
681032
681032
681032
681032
681032
681032
681032
681032
682276
682276
682276
682276
682276
679002
679002
679002
679002
679002
679002
679002
679002
679002
679002
679002
679002
679002
679002
679002...

result:

ok 1001 lines

Test #16:

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

input:

1000 1000
76312 85088 66287 101457 27652 113578 8522 27466 987 58477 35566 78626 108889 44590 16599 47446 67053 39487 52617 87121 78483 19460 4800 15209 108770 6107 94056 36407 4650 86935 13645 2732 4654 88828 32502 62313 15892 31506 81748 52589 103711 76765 98121 40569 110053 46753 8316 22781 54642...

output:

195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202
195202...

result:

wrong answer 101st lines differ - expected: '197923', found: '194709'

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%