QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#546740#7973. 括号ASnown5 2ms6064kbC++144.3kb2024-09-04 12:47:522024-09-04 12:47:52

Judging History

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

  • [2024-09-04 12:47:52]
  • 评测
  • 测评结果:5
  • 用时:2ms
  • 内存:6064kb
  • [2024-09-04 12:47:52]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using uint=uint32_t;
template<typename T>
inline bool Max(T &x,T y) { return std::less<T>()(x,y)&&(x=y,true); }
template<typename T>
inline bool Min(T &x,T y) { return std::less<T>()(y,x)&&(x=y,true); }
void Solve();
const int INF = 0x3f3f3f3f;
const int N = 2e5+25;
int n,Q;
int a[N],b[N];
bool c[N],s[N]; // (1,)0
struct Brack {
   int num,data;
   friend inline bool operator<(Brack p,Brack q) {
      return p.data<q.data;
   }
};
namespace SGT {
struct Node {
   int smn,tag;
   Brack mn1,mn2;
} tr[N<<2];
#define ls (u<<1)
#define rs (ls|1)
#define mid ((L+R)>>1)
void pushup(int u) {
   tr[u].smn=min(tr[ls].smn,tr[rs].smn);
   tr[u].mn1=min(tr[ls].mn1,tr[rs].mn1);
   tr[u].mn2=min(tr[ls].mn2,tr[rs].mn2);
}
void clac(int u,int k) { tr[u].smn+=k,tr[u].tag+=k; }
void pushdown(int u) {
   if(tr[u].tag) {
      clac(ls,tr[u].tag);
      clac(rs,tr[u].tag);
      tr[u].tag=0;
   }
}
void build(int u,int L,int R) {
   if(L==R) {
      tr[u]=(L&1?Node{1,0,{L,0},{L,INF}}:Node{0,0,{L,INF},{L,0}});
      return ;
   }
   build(ls,L,mid),build(rs,mid+1,R);
   pushup(u);
}
void update1(int u,int L,int R,int l,int r,int k) {
   if(l<=L&&R<=r) return clac(u,k);
   pushdown(u);
   if(l<=mid) update1(ls,L,mid,l,r,k);
   if(r> mid) update1(rs,mid+1,R,l,r,k);
   pushup(u);
}
void update2(int u,int L,int R,int x,int a,int b) {
   if(L==R) {
      tr[u].mn1.data=a;
      tr[u].mn2.data=b;
      return ;
   }
   pushdown(u);
   if(x<=mid) update2(ls,L,mid,x,a,b);
   else update2(rs,mid+1,R,x,a,b);
   pushup(u);
}
int find1(int u,int L,int R,int x) {
   if(L==R) return tr[u].smn>1?-1:x;
   pushdown(u);
   if(x<=mid) {
      if(L==x) {
         if(tr[ls].smn>1) return find1(rs,mid+1,R,mid+1);
         else return find1(ls,L,mid,x);
      } else {
         int p=find1(ls,L,mid,x);
         if(!~p) return find1(rs,mid+1,R,mid+1);
         else return p;
      }
   } else return find1(rs,mid+1,R,x);
}
int find2(int u,int L,int R,int x) {
   if(L==R) return tr[u].smn>1?-1:x;
   pushdown(u);
   if(x> mid) {
      if(R==x) {
         if(tr[rs].smn>1) return find2(ls,L,mid,mid);
         else return find2(rs,mid+1,R,x);
      } else {
         int p=find2(rs,mid+1,R,x);
         if(!~p) return find2(ls,L,mid,mid);
         else return p;
      }
   } else return find2(ls,L,mid,x);
}
Brack query1(int u,int L,int R,int l,int r) {
   if(l<=L&&R<=r) return tr[u].mn1;
   pushdown(u);
   if(r<=mid) return query1(ls,L,mid,l,r);
   if(l> mid) return query1(rs,mid+1,R,l,r);
   return min(query1(ls,L,mid,l,r),query1(rs,mid+1,R,l,r));
}
Brack query2(int u,int L,int R,int l,int r) {
   if(l<=L&&R<=r) return tr[u].mn2;
   pushdown(u);
   if(r<=mid) return query2(ls,L,mid,l,r);
   if(l> mid) return query2(rs,mid+1,R,l,r);
   return min(query2(ls,L,mid,l,r),query2(rs,mid+1,R,l,r));
}
#undef ls
#undef rs
#undef mid
}
ll res=0;
void change(int x,int k) {
   Brack ds;
   int y,p,rst;
   if(c[x]!=s[x]) res+=k-a[x];
   a[x]=k,b[x]=(c[x]?a[x]:-a[x]);
   rst=(c[x]==s[x]?a[x]:-a[x]);
   if(s[x]) {
      p=SGT::find1(1,1,n,x+1); if(!~p) p=n+1;
      ds=SGT::query2(1,1,n,1,p-1);
   } else {
      p=SGT::find2(1,1,n,x-1); if(!~p) p=0;
      ds=SGT::query1(1,1,n,p+1,n);
   }
   y=ds.num,rst+=ds.data;
   if(rst<0) {
      res+=rst;
      if(s[x]) {
         s[x]=0,s[y]=1;
         SGT::update1(1,1,n,x,n,-2);
         SGT::update1(1,1,n,y,n,2);
         SGT::update2(1,1,n,x,INF,-b[x]);
         SGT::update2(1,1,n,y,b[y],INF);
      } else {
         s[x]=1,s[y]=0;
         SGT::update1(1,1,n,x,n,2);
         SGT::update1(1,1,n,y,n,-2);
         SGT::update2(1,1,n,x,b[x],INF);
         SGT::update2(1,1,n,y,INF,-b[y]);
      }
   } else {
      if(s[x]) SGT::update2(1,1,n,x,b[x],INF);
      else SGT::update2(1,1,n,x,INF,-b[x]);
   }
}
signed main() {
#ifndef ONLINE_JUDGE
#endif
   cin.tie(nullptr)->sync_with_stdio(false);
   Solve();
}
void Solve() {
   cin>>n>>Q,n<<=1;
   SGT::build(1,1,n);
   for(int i=1;i<=n;i++) cin>>b[i];
   for(int i=1;i<=n;i++) {
      char ch; cin>>ch;
      c[i]=ch=='(',s[i]=i&1;
   }
   for(int i=1;i<=n;i++) change(i,b[i]);
   printf("%lld\n",res);
   int x,d;
   while(Q--) {
      cin>>x>>d;
      change(x,d);
      printf("%lld\n",res);
   }
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

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

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
1592988282
1592988282
1592988282
1592988282
1592988282
1592988282
1592988282
1592988282
1592988282
1592988282
1592988282
1592988282
1592988282
1592988282
1592988282
1592988282
1592988282
1592988282
1592988282
1592988282
1596630895
1596630895
1596630895
1596630895
1596630895
1596630895
159...

result:

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

Subtask #2:

score: 0
Wrong Answer

Test #5:

score: 10
Accepted
time: 2ms
memory: 5944kb

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:

ok 1001 lines

Test #6:

score: 10
Accepted
time: 0ms
memory: 6052kb

input:

1000 1000
28321407 414472019 420792436 143985944 535669841 441577718 424567503 950335050 22026618 548046980 528330577 366602837 496034315 949896 61908611 265122119 642501627 142428473 178008027 417395845 669285134 784847019 974283538 706118853 910836282 895293511 612528954 138954924 632993525 257003...

output:

596032630
596032630
596032630
596032630
596032630
596032630
596032630
596032630
596032630
596032630
596032630
596032630
596032630
596032630
596032630
596032630
596032630
596032630
617635185
617635185
617635185
617635185
617635185
617635185
617635185
617635185
617635185
617635185
617635185
617635185
...

result:

ok 1001 lines

Test #7:

score: 10
Accepted
time: 2ms
memory: 5984kb

input:

1000 1000
910611297 551791906 756298953 161503217 929609402 969080309 971864996 583720039 575297111 791917027 329874901 144584384 793870252 482929295 679298604 258720774 193653026 976453308 750810644 840302093 88307871 337980381 876250090 990929257 256960743 561506222 910837823 815706266 375545013 5...

output:

1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
1302828551
130...

result:

ok 1001 lines

Test #8:

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

input:

1000 1000
87868477 984079086 755368982 252649419 323548963 160146410 182725998 807039612 423534896 35787072 836451933 217533223 91706187 596312474 928092377 915882941 81240913 884107071 618580552 336837269 580959536 891113744 778216643 570706952 308117913 227718932 504113983 123861387 781660014 5843...

output:

339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
339639846
...

result:

wrong answer 189th lines differ - expected: '969875100', found: '462881453'

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 5
Accepted

Test #14:

score: 5
Accepted
time: 2ms
memory: 5944kb

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: 2ms
memory: 5988kb

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: 5
Accepted
time: 2ms
memory: 6064kb

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:

ok 1001 lines

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%