QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#622458#7973. 括号ucup-team10040 3ms22608kbC++174.8kb2024-10-08 21:50:312024-10-08 21:50:32

Judging History

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

  • [2024-10-08 21:50:32]
  • 评测
  • 测评结果:0
  • 用时:3ms
  • 内存:22608kb
  • [2024-10-08 21:50:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include"debug.h"
#else
#define debug(...) void()
#endif
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
	return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
const int N=2e5+10;
int n,m,a[N],id[N];
char s[N];
ll ans;
struct Solver{
	int n,a[N],b[N];
	int push(int x){
		return a[++n]=x,n;
	}
	void chkmax(int x,int y){
		b[x]=max(b[x],y);
	}
	struct SegTree{
		int t[N<<2],laz[N<<2];
		void pushup(int rt){
			t[rt]=min(t[rt<<1],t[rt<<1|1])+laz[rt];
		}
		void pushlaz(int rt,int x){
			t[rt]+=x,laz[rt]+=x;
		}
		void update(int L,int R,int x,int l,int r,int rt){
			if(L<=l&&r<=R)return pushlaz(rt,x);
			int mid=(l+r)>>1;
			if(L<=mid)update(L,R,x,l,mid,rt<<1);
			if(mid<R)update(L,R,x,mid+1,r,rt<<1|1);
			pushup(rt);
		}
		int findpre(int x,int y,int l,int r,int rt){
			if(t[rt]>y)return 0;
			if(l==r)return l;
			int mid=(l+r)>>1,s=0;
			y-=laz[rt];
			if(mid<x)s=findpre(x,y,mid+1,r,rt<<1|1);
			if(s)return s;
			return findpre(x,y,l,mid,rt<<1);
		}
		int findnex(int x,int y,int l,int r,int rt){
			if(t[rt]>y)return 0;
			if(l==r)return l;
			int mid=(l+r)>>1,s=0;
			y-=laz[rt];
			if(x<=mid)s=findnex(x,y,l,mid,rt<<1);
			if(s)return s;
			return findnex(x,y,mid+1,r,rt<<1|1);
		}
	}S;
	void update(int l,int r,int x){
		S.update(l,r,x,1,n+1,1);
	}
	int findpre(int x){
		return S.findpre(x,0,1,n+1,1);
	}
	int findnex(int x){
		return S.findnex(x+1,0,1,n+1,1)-1;
	}
	struct SegTree1{
		int a[N],t[N<<2];
		int Min(int x,int y){
			return a[x]<a[y]?x:y;
		}
		void pushup(int rt){
			t[rt]=Min(t[rt<<1],t[rt<<1|1]);
		}
		void update(int x,int y,int l,int r,int rt){
			if(l==r)return t[rt]=y,void();
			int mid=(l+r)>>1;
			if(x<=mid)update(x,y,l,mid,rt<<1);
			else update(x,y,mid+1,r,rt<<1|1);
			pushup(rt);
		}
		int query(int L,int R,int l,int r,int rt){
			if(L<=l&&r<=R)return t[rt];
			int mid=(l+r)>>1;
			if(R<=mid)return query(L,R,l,mid,rt<<1);
			if(mid<L)return query(L,R,mid+1,r,rt<<1|1);
			return Min(query(L,R,l,mid,rt<<1),query(L,R,mid+1,r,rt<<1|1));
		}
	}A;
	struct SegTree2{
		int a[N],t[N<<2];
		int Max(int x,int y){
			return a[x]>a[y]?x:y;
		}
		void pushup(int rt){
			t[rt]=Max(t[rt<<1],t[rt<<1|1]);
		}
		void update(int x,int y,int l,int r,int rt){
			if(l==r)return t[rt]=y,void();
			int mid=(l+r)>>1;
			if(x<=mid)update(x,y,l,mid,rt<<1);
			else update(x,y,mid+1,r,rt<<1|1);
			pushup(rt);
		}
		int query(int L,int R,int l,int r,int rt){
			if(L<=l&&r<=R)return t[rt];
			int mid=(l+r)>>1;
			if(R<=mid)return query(L,R,l,mid,rt<<1);
			if(mid<L)return query(L,R,mid+1,r,rt<<1|1);
			return Max(query(L,R,l,mid,rt<<1),query(L,R,mid+1,r,rt<<1|1));
		}
	}B;
	void insert(int x){
		// debug("insert",x);
		A.update(x,0,1,n,1),B.update(x,x,1,n,1);
	}
	void erase(int x){
		// debug("erase",x);
		A.update(x,x,1,n,1),B.update(x,0,1,n,1);
	}
	bool check(int x){
		return !A.query(x,x,1,n,1);
	}
	void init(){
		for(int i=1;i<=n;i++)A.a[i]=B.a[i]=a[i];
		A.a[0]=1e9+1,B.a[0]=-1;
		for(int i=1;i<=n;i++)b[i]=max(b[i],b[i-1]);
		for(int i=n;i>=1;i--)b[i]-=b[i-1];
		// debug(ary(a,1,n),ary(b,1,n));
		priority_queue<pair<int,int>>q;
		for(int i=1;i<=n;i++){
			erase(i),q.push({-a[i],i});
			for(int x=b[i];x--;){
				if(q.top().second<i){
					update(q.top().second+1,i,1);
				}
				// debug(q.top().second,i);
				insert(q.top().second),ans-=q.top().first,q.pop();
			}
		}
		// for(int i=1;i<=n;i++)debug("status",i,check(i));
	}
	void modify(int x,int y){
		// debug("modify",x,y);
		if(!check(x)){
			a[x]=y,erase(x);
			int z=findpre(x),p=B.query(z,x,1,n,1);
			if(p&&a[p]>a[x]){
				ans+=a[x]-a[p];
				update(p+1,x,-1);
				insert(x),erase(p);
				x=p;
			}
			p=B.query(x,n,1,n,1);
			if(p&&a[p]>a[x]){
				ans+=a[x]-a[p];
				update(x+1,p,1);
				insert(x),erase(p);
			}
		}else{
			ans-=a[x],ans+=y,a[x]=y,insert(x);
			int z=findnex(x),p=A.query(x,z,1,n,1);
			// debug("OK",x,z);
			if(p&&a[p]<a[x]){
				ans+=a[p]-a[x];
				update(x+1,p,-1);
				insert(p),erase(x);
				x=p;
			}
			p=A.query(1,x,1,n,1);
			if(p&&a[p]<a[x]){
				ans+=a[p]-a[x];
				update(p+1,x,1);
				insert(p),erase(x);
			}
		}
	}
}L,R;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n+n;i++)scanf("%d",&a[i]);
	scanf("%s",s+1);
	for(int i=1;i<=n+n;i++)if(s[i]==')')id[i]=R.push(a[i]);
	for(int i=n+n;i>=1;i--)if(s[i]=='(')id[i]=L.push(a[i]);
	for(int i=1,l=0,r=0;i<=n+n;i++){
		(s[i]=='('?l:r)++,R.chkmax(r,(r-l+1)/2);
	}
	for(int i=n+n,l=0,r=0;i>=1;i--){
		(s[i]=='('?l:r)++,L.chkmax(l,(l-r+1)/2);
	}
	L.init(),R.init();
	for(int x,y;printf("%lld\n",ans),m--;){
		scanf("%d%d",&x,&y);
		if(s[x]=='(')L.modify(id[x],y);
		else R.modify(id[x],y);
	}
	return 0;
}
#ifdef DEBUG
#include"debug.hpp"
#endif

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: 18260kb

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 37th lines differ - expected: '1644236314', found: '1686365269'

Subtask #2:

score: 0
Wrong Answer

Test #5:

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

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
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2792631539
2810931294
2810931294
2810931294
2810931294
281...

result:

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

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Wrong Answer

Test #14:

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

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
13352661
13352661
13352661
13352661
13352661
13352661
13352661
13352661
13382805
13346045
13349826
13349826
13349826
13349826
13349826
13349826
13349826
13349826
13333475
13333475
13333475
13334201
13330206
13346439
13338758
13369084
13369084
13413141
13413141
13413141
13413141
13444210
134...

result:

wrong answer 2nd lines differ - expected: '13351991', found: '13352661'

Subtask #5:

score: 0
Skipped

Dependency #3:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%