QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694822#9322. Segments Removallytqwq#WA 0ms34596kbC++142.4kb2024-10-31 18:44:182024-10-31 18:44:21

Judging History

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

  • [2024-10-31 18:44:21]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:34596kb
  • [2024-10-31 18:44:18]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=5e5+10;
int t,n,x;
long long ans[N<<2],tag[N<<2],ff[N];
long long qian[N];
struct d{
	int l,r,w,p;
};
vector<d> kel[N],kel2[N];
int ls(int x){
	return x<<1;
}
int rs(int x){
	return x<<1|1;
}
void push_up(int x){
	ans[x]=max(ans[ls(x)],ans[rs(x)]);
}
void f(int p,int l,int r,long long v){
	ans[p]+=v;
	tag[p]+=v;
}
void push_down(int p,int l,int r){
	int mid=(l+r)>>1;
	f(ls(p),l,mid,tag[p]);
	f(rs(p),mid+1,r,tag[p]);
	tag[p]=0;
}
void build(int p,int l,int r){
	tag[p]=0;
	if(l==r){
		ans[p]=qian[l-1];
		return ;
	}
	int mid=(l+r)>>1;
	build(ls(p),l,mid);
	build(rs(p),mid+1,r);
	push_up(p);
}
void update(int nl,int nr,int l,int r,int p,long long v){
	if(nl<=l&&r<=nr){
		f(p,l,r,v);
		return ;
	}
	push_down(p,l,r);
	int mid=(l+r)>>1;
	if(nl<=mid){
		update(nl,nr,l,mid,ls(p),v);
	}
	if(mid+1<=nr){
		update(nl,nr,mid+1,r,rs(p),v);
	}
	push_up(p);
}
long long query(int nl,int nr,int l,int r,int p){
	if(nl>nr)return -1e18;
	if(nl<=l&&r<=nr){
		return ans[p];
	}
	push_down(p,l,r);
	int mid=(l+r)>>1;
	long long nowans=0;
	if(nl<=mid){
		nowans=max(nowans,query(nl,nr,l,mid,ls(p)));
	}
	if(mid+1<=nr){
		nowans=max(nowans,query(nl,nr,mid+1,r,rs(p)));
	}
	return nowans;
}
multiset<int> dk;
int val[N];
int main(){
	scanf("%d",&t);
	while(t--){
		scanf("%d%d",&n,&x);
		dk.clear();
		for(int i=1;i<=x;i++){
			kel[i].clear();
			kel2[i].clear();
		}
		long long ss=0;
		for(int i=1;i<=n;i++){
			d now;
			scanf("%d%d%d%d",&now.l,&now.r,&now.w,&now.p);
			ss-=now.p; 
			kel[now.r].push_back(now);
			kel2[now.l].push_back(now);
		}
		for(int i=1;i<=x;i++){
			for(auto j:kel2[i]){
				dk.insert(j.w);
			}
			if(dk.begin()==dk.end()){
				val[i]=0;
			}
			else{
				multiset<int>::iterator it=dk.end();
				it--;
				val[i]=(*it);
			}
			qian[i]=qian[i-1]+val[i];
			for(auto j:kel[i]){
				dk.erase(dk.find(j.w));
			}
		}
		ss+=qian[x];
		long long anss=0;
		build(1,1,x+1);
		for(int i=1;i<=x;i++){
			for(auto j:kel[i]){
				update(1,j.l,1,x+1,1,j.p);
			}
			ff[i]=max(ff[i-1],-qian[i]+query(1,i-1,1,x+1,1));
			anss=max(anss,ff[i]);
			update(i,i,1,x+1,1,ff[i]);
		}
		printf("%lld\n",ss+anss);
	}
}
/*
4
3 8
 3 7 3 2
 5 8 2 1
 1 3 2 2
 2 5
 1 3 2 7
 3 5 3 4
 3 8
 3 7 3 2
 5 8 2 1
 1 3 2 2
 2 5
 1 3 2 7
 3 5 3 4
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2
3 8
3 7 3 2
5 8 2 1
1 3 2 2
2 5
1 3 2 7
3 5 3 4

output:

16
2

result:

ok 2 number(s): "16 2"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 32504kb

input:

5
3 7
3 7 8 6
2 4 6 8
3 3 8 3
3 6
1 3 7 6
2 2 6 6
4 5 4 6
4 6
2 4 7 4
2 6 5 3
2 3 4 6
1 1 3 6
4 7
1 3 2 5
1 6 3 3
5 5 8 5
1 6 5 1
1 4
2 2 8 8

output:

29
11
15
19
0

result:

wrong answer 3rd numbers differ - expected: '18', found: '15'