QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#694840#9322. Segments Removallytqwq#WA 74ms34500kbC++142.4kb2024-10-31 18:46:252024-10-31 18:46:34

Judging History

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

  • [2024-10-31 18:46:34]
  • 评测
  • 测评结果:WA
  • 用时:74ms
  • 内存:34500kb
  • [2024-10-31 18:46:25]
  • 提交

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,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: 34500kb

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: 0
Accepted
time: 0ms
memory: 30632kb

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
18
19
0

result:

ok 5 number(s): "29 11 18 19 0"

Test #3:

score: -100
Wrong Answer
time: 74ms
memory: 30544kb

input:

26334
4 21
15 16 5 10
7 7 14 46
5 7 9 10
11 18 17 49
4 22
4 17 8 30
5 12 11 35
8 11 3 21
12 16 1 10
5 8
1 1 8 27
5 7 1 26
7 8 3 34
1 6 13 34
6 7 18 13
4 9
6 8 7 31
5 9 14 21
8 9 16 50
2 8 7 49
5 9
5 5 12 19
1 5 5 22
4 6 14 18
7 9 10 40
2 6 11 7
5 24
9 22 14 4
17 21 11 37
12 23 2 26
7 9 19 12
8 22 20...

output:

117
40
14
0
8
213
98
260
17
157
189
13
124
182
48
148
68
0
177
196
167
94
205
150
59
306
269
117
0
166
118
0
79
142
189
7
73
33
176
7
41
17
183
27
31
18
0
0
243
216
50
45
54
203
149
18
0
60
171
2
246
236
113
8
182
20
0
74
154
12
136
92
42
86
22
83
59
270
144
45
18
186
145
0
56
0
90
37
63
18
129
0
10...

result:

wrong answer 1st numbers differ - expected: '85', found: '117'