QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#455589 | #7973. 括号 | NKheyuxiang | 0 | 5ms | 26328kb | C++14 | 4.9kb | 2024-06-26 16:36:13 | 2024-06-26 16:36:14 |
Judging History
answer
#include<bits/stdc++.h>
#define N 200005
using namespace std;
const int inf=1e9+5;
struct node{int val,id;};
node max(node a,node b){
if(b.val>a.val) a=b;
return a;
}
node min(node a,node b){
if(b.val<a.val) a=b;
return a;
}
struct sgt1{
node mx[N*4],mn[N*4];
void build(int q,int l,int r){
mx[q].val=-inf;
mn[q].val=inf;
mx[q].id=mn[q].id=l;
if(l==r) return;
int mid=(l+r)/2;
build(q*2,l,mid);
build(q*2+1,mid+1,r);
}
void erase(int q,int l,int r,int x){
if(l==r){
mx[q].val=-inf;
mn[q].val=inf;
return;
}
int mid=(l+r)/2;
if(x<=mid) erase(q*2,l,mid,x);
else erase(q*2+1,mid+1,r,x);
mx[q]=max(mx[q*2],mx[q*2+1]);
mn[q]=min(mn[q*2],mn[q*2+1]);
}
void modify(int q,int l,int r,int x,int y){
if(l==r){
mn[q].val=mx[q].val=y;
return;
}
int mid=(l+r)/2;
if(x<=mid) modify(q*2,l,mid,x,y);
else modify(q*2+1,mid+1,r,x,y);
mx[q]=max(mx[q*2],mx[q*2+1]);
mn[q]=min(mn[q*2],mn[q*2+1]);
}
node qrymx(int q,int l,int r,int x,int y){
if(x<=l&&r<=y) return mx[q];
int mid=(l+r)/2;
if(y<=mid) return qrymx(q*2,l,mid,x,y);
if(mid<x) return qrymx(q*2+1,mid+1,r,x,y);
return max(qrymx(q*2,l,mid,x,y),qrymx(q*2+1,mid+1,r,x,y));
}
node qrymn(int q,int l,int r,int x,int y){
if(x<=l&&r<=y) return mn[q];
int mid=(l+r)/2;
if(y<=mid) return qrymn(q*2,l,mid,x,y);
if(mid<x) return qrymn(q*2+1,mid+1,r,x,y);
return min(qrymn(q*2,l,mid,x,y),qrymn(q*2+1,mid+1,r,x,y));
}
}T0,T1;
struct sgt2{
node mxl[N*4],mxr[N*4];
int lz[N*4];
void build(int q,int l,int r){
lz[q]=0;
mxl[q].val=mxr[q].val=0;
mxl[q].id=l,mxr[q].id=r;
if(l==r) return;
int mid=(l+r)/2;
build(q*2,l,mid);
build(q*2+1,mid+1,r);
}
void update(int q,int x){
mxl[q].val+=x;
mxr[q].val+=x;
lz[q]+=x;
}
void push_down(int q){
if(lz[q]!=0){
update(q*2,lz[q]);
update(q*2+1,lz[q]);
lz[q]=0;
}
}
void modify(int q,int l,int r,int x,int y,int z){
// if(q==1) cout<<"mdf "<<x<<" "<<y<<" "<<z<<endl;
if(x<=l&&r<=y){
update(q,z);
return;
}
push_down(q);
int mid=(l+r)/2;
if(x<=mid) modify(q*2,l,mid,x,y,z);
if(mid<y) modify(q*2+1,mid+1,r,x,y,z);
mxl[q]=max(mxl[q*2],mxl[q*2+1]);
mxr[q]=max(mxr[q*2+1],mxr[q*2]);
}
node qrymxl(int q,int l,int r,int x,int y){
if(x<=l&&r<=y){
// cout<<l<<" "<<r<<" "<<mxl[q].val<<" "<<mxl[q].id<<endl;
return mxl[q];
}
push_down(q);
int mid=(l+r)/2;
if(y<=mid) return qrymxl(q*2,l,mid,x,y);
if(mid<x) return qrymxl(q*2+1,mid+1,r,x,y);
return max(qrymxl(q*2,l,mid,x,y),qrymxl(q*2+1,mid+1,r,x,y));
}
node qrymxr(int q,int l,int r,int x,int y){
if(x<=l&&r<=y) return mxr[q];
push_down(q);
int mid=(l+r)/2;
if(y<=mid) return qrymxr(q*2,l,mid,x,y);
if(mid<x) return qrymxr(q*2+1,mid+1,r,x,y);
return max(qrymxr(q*2+1,mid+1,r,x,y),qrymxr(q*2,l,mid,x,y));
}
}T2;
int n,m,len,a[N],b[N],op[3*N],ch[3*N];
long long an[3*N],ans;
void init(){
ans=0;
T0.build(1,1,len);
T1.build(1,1,len);
T2.build(1,1,len);
}
void add(int x,int v){
// cout<<"add "<<x<<" "<<v<<endl;
T0.erase(1,1,len,x);
T1.modify(1,1,len,x,v);
T2.modify(1,1,len,1,x,1);
ans+=(b[x]=v);
}
void del(int x){
// cout<<"del "<<x<<endl;
T0.modify(1,1,len,x,b[x]);
T1.erase(1,1,len,x);
T2.modify(1,1,len,1,x,-1);
ans-=b[x];b[x]=-1;
}
void ADD(int x,int v){
// cout<<"ADD "<<x<<endl;
node pre=T2.qrymxr(1,1,len,1,x);
// cout<<x<<" "<<pre.val<<" "<<pre.id<<" "<<ans<<endl;
if(pre.val<0) return add(x,v);
node mx=T1.qrymx(1,1,len,pre.id,len);
// cout<<mx.val<<" "<<v<<endl;
if(mx.val>v) del(mx.id),add(x,v);
}
void DEL(int x){
if(b[x]==-1) return;
// cout<<"DEL "<<x<<endl;
node suf;suf.val=-1;
if(x<len) suf=T2.qrymxl(1,1,len,x+1,len);
// cout<<x<<" "<<suf.id<<" "<<suf.val<<endl;
if(suf.val<0) suf.id=len+1;
node mn=T0.qrymn(1,1,len,1,suf.id-1);
// cout<<mn.id<<" "<<mn.val<<endl;
if(mn.val<inf) add(mn.id,mn.val);
del(x);
}
int pre[N];
char s[N];
void calc(){
for(int i=1;i<=2*n;i++) pre[i]=pre[i-1]+((s[i]=='(')?1:-1);
for(int i=1;i<=2*n;i++) pre[i]=min(pre[i],pre[i-1]);
init();
for(int i=1;i<=2*n;i++){
if(pre[i]<pre[i-1]&&(-pre[i])%2==1)
T2.modify(1,1,len,1,i,-1);
}
for(int i=1;i<=2*n;i++) b[i]=-1;
for(int i=1;i<=2*n;i++)
if(s[i]==')') T0.modify(1,1,len,i,a[i]);
for(int i=1;i<=2*n;i++)
if(s[i]==')') ADD(i,a[i]);
an[0]+=ans;
for(int i=1;i<=m;i++){
if(s[op[i]]==')'){
DEL(op[i]);
ADD(op[i],ch[i]);
}
an[i]+=ans;
}
}
int main(){
// freopen("brackets3.in","r",stdin);
// freopen("my.out","w",stdout);
scanf("%d%d",&n,&m);len=2*n;
for(int i=1;i<=2*n;i++) scanf("%d",&a[i]);
scanf("%s",s+1);
for(int i=1;i<=m;i++) scanf("%d%d",&op[i],&ch[i]);
calc();
for(int i=1;i<=n;i++) swap(s[i],s[2*n+1-i]),swap(a[i],a[2*n+1-i]);
for(int i=1;i<=2*n;i++) s[i]^=1;
for(int i=1;i<=m;i++) op[i]=2*n+1-op[i];
calc();
for(int i=0;i<=m;i++) printf("%lld\n",an[i]);
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 26324kb
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 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 1938040724 193...
result:
wrong answer 50th lines differ - expected: '1427120609', found: '1324138116'
Subtask #2:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 0ms
memory: 26328kb
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 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2784207960 2800727160 2800727160 2800727160 2800727160 280...
result:
wrong answer 142nd lines differ - expected: '2782124286', found: '2765605086'
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 5ms
memory: 24384kb
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 13320035 13308967 13292781 13292781 13292781 13292781 13292781 13277198 13260704 13260704 13260704 13257649 13249130 13269887 13253687 13263256 13263256 13275664 13275664 13275664 13275664 13263080 132...
result:
wrong answer 12th lines differ - expected: '13349826', found: '13320035'
Subtask #5:
score: 0
Skipped
Dependency #3:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%