QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#832807 | #9322. Segments Removal | hxhhxh | WA | 2ms | 7952kb | C++23 | 1.6kb | 2024-12-26 08:35:11 | 2024-12-26 08:35:12 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct SEG{
struct st{
int l,r,c,z;
}a[1048888];
void bt(int x,int l,int r){
a[x].l=l;
a[x].r=r;
a[x].c=a[x].z=0;
if(l<r){
bt(x<<1,l,(l+r>>1));
bt(x<<1|1,(l+r>>1)+1,r);
}
}
void ps(int x,int v){
a[x].c+=v,a[x].z+=v;
}
void xf(int x){
ps(x<<1,a[x].z),ps(x<<1|1,a[x].z);
a[x].z=0;
}
void add(int x,int l,int r,int v){
if(a[x].l==l&&a[x].r==r) return ps(x,v);
if(a[x].z) xf(x);
int mid=a[x].l+a[x].r>>1;
if(r<=mid) add(x<<1,l,r,v);
else if(l>mid) add(x<<1|1,l,r,v);
else add(x<<1,l,mid,v),add(x<<1|1,mid+1,r,v);
a[x].c=max(a[x<<1].c,a[x<<1|1].c);
}
int que(int x,int l,int r){
if(a[x].l==l&&a[x].r==r) return a[x].c;
if(a[x].z) xf(x);
int mid=a[x].l+a[x].r>>1;
if(r<=mid) return que(x<<1,l,r);
if(l>mid) return que(x<<1|1,l,r);
return max(que(x<<1,l,mid),que(x<<1|1,mid+1,r));
}
}T;
int n,V,w[500005],ans;
vector<int>e[500005];
vector<pair<int,int> >g[500005];
multiset<int>s;
void doing(){
scanf("%lld %lld",&n,&V);
T.bt(1,ans=0,V);
for(int i=1;i<=V;i++) e[i].clear(),g[i].clear();
for(int i=1,j,k,l,o;i<=n;i++){
scanf("%lld %lld %lld %lld",&j,&k,&l,&o);
e[j].push_back(l),e[k+1].push_back(-l);
g[k+1].push_back({j,o}),ans-=o;
}
s={0};
for(int i=1;i<=V;i++){
for(int j:e[i]) j>0?s.insert(j):s.erase(s.find(-j));
w[i]=*--s.end();
}
for(int i=1,l=0;i<=V;i++){
for(auto j:g[i]) T.add(1,0,j.first,j.second);
T.add(1,i,i,l=max(T.que(1,0,i-1),l+w[i]));
}
printf("%lld\n",ans+T.que(1,V,V));
}
signed main(){
int T;
cin>>T;
while(T--) doing();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 7952kb
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: 7908kb
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 13 15 19 8
result:
wrong answer 2nd numbers differ - expected: '11', found: '13'