QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#578344 | #9322. Segments Removal | Afterlife# | WA | 2ms | 9892kb | C++20 | 4.3kb | 2024-09-20 18:24:36 | 2024-09-20 18:24:36 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
const ll inf=1e18;
const int N=500050;
int n,m,c[N];
ll s[N],dp[N];
struct Range{
int l,r,p,w;
}a[N];
vector<int> v[N];
multiset<int> S;
inline int lowbit(int x){
return x&(-x);
}
struct BIT2{
ll b[N];
void init(int n,ll o){
for(int i=1;i<=n;++i){
b[i]=o;
}
}
inline void Add(int x,ll d){
while(x<=m){
b[x]+=d,x+=lowbit(x);
}
}
inline ll Ask(int x){
ll ans=0;
while(x){
ans+=b[x],x-=lowbit(x);
}
return ans;
}
}C,E;
struct BIT1{
ll b[N];
void init(int n,ll o){
for(int i=1;i<=n;++i){
b[i]=o;
}
}
inline void Add(int x,ll d){
while(x<=m){
b[x]=max(b[x],d),x+=lowbit(x);
}
}
inline ll Ask(int x){
ll ans=-inf;
while(x){
ans=max(ans,b[x]),x-=lowbit(x);
}
return ans;
}
}A,B;
struct T{
int ls,rs,l,r;
int tag,mx;
}t[N*2+1];
void setv(int x,int v)
{
t[x].tag+=v;
t[x].mx+=v;
}
void update(int x)
{
t[x].mx=max(t[t[x].ls].mx,t[t[x].rs].mx);
}
void pushdown(int x)
{
if(t[x].tag!=0)
{
setv(t[x].ls,t[x].tag);
setv(t[x].rs,t[x].tag);
t[x].tag=0;
}
}
int cnt;
int build(int l,int r)
{
int x=++cnt;
t[x].tag=0;
t[x].l=l,t[x].r=r;
if(l==r)
{
if(l!=0)
t[x].mx=-inf;
else
t[x].mx=0;
return x;
}
int mid=(l+r)>>1;
t[x].ls=build(l,mid);
t[x].rs=build(mid+1,r);
update(x);
return x;
}
void change(int x,int l,int r,int v)
{
if(l<=t[x].l&&t[x].r<=r)
{
setv(x,v);
return;
}
pushdown(x);
int mid=(t[x].l+t[x].r)>>1;
if(l<=mid)
change(t[x].ls,l,r,v);
if(r>mid)
change(t[x].rs,l,r,v);
update(x);
}
int qmx(int x,int l,int r)
{
if(l<=t[x].l&&t[x].r<=r)
return t[x].mx;
int mid=(t[x].l+t[x].r)>>1;
pushdown(x);
int ret=-inf;
if(l<=mid)
ret=max(ret,qmx(t[x].ls,l,r));
if(r>mid)
ret=max(ret,qmx(t[x].rs,l,r));
return ret;
};
void Solve(){
cin>>n>>m;
for(int i=1;i<=m+1;++i)v[i].clear();
for(int i=1;i<=n;++i){
cin>>a[i].l>>a[i].r>>a[i].w>>a[i].p;
v[a[i].l].push_back(i);
v[a[i].r+1].push_back(i);
}
S.clear();
for(int i=1;i<=m;++i){
for(auto id:v[i]){
if(a[id].l==i){
S.insert(a[id].w);
}
else{
S.erase(S.find(a[id].w));
}
}
c[i]=S.empty()?0:*S.rbegin();
}
for(int i=1;i<=m;++i){
s[i]=s[i-1]+c[i];
}
ll ans=-inf;
sort(a+1,a+n+1,[&](Range x,Range y){
return x.r==y.r?x.l>y.l:x.r<y.r;
});
// A.init(m,-inf),B.init(m,-inf),C.init(m,0);
// E.init(m,0);
ll now=-inf;
cnt=0;
build(0,m);
vector<vector<pair<int,int> > >ch(m+1);
for(int i=1;i<=n;i++)
{
ch[a[i].l].push_back({a[i].r,a[i].p});
}
for(int i=1;i<=m;i++)
{
for(auto [r,p]:ch[i])
{
change(1,r,m,p);
int mx=qmx(1,0,r-1)+p;
int o=qmx(1,r,r);
if(mx>o)
change(1,r,r,mx-o);
}
change(1,i,m,-c[i]);
ans=max(ans,qmx(1,i,i));
}
// for(int i=1;i<=n;++i){
// now+=a[i].p;
// ll W=now-C.Ask(a[i].l-1);
// dp[i]=-(s[a[i].r]-s[a[i].l-1]);
// dp[i]=max(dp[i],A.Ask(a[i].l-1)-s[a[i].r]+E.Ask(a[i].l-1));
// dp[i]=max(dp[i],B.Ask(a[i].l-1)-(s[a[i].r]-s[a[i].l-1]));
// dp[i]+=W;
// A.Add(a[i].l,dp[i]+s[a[i].r]-now);
// B.Add(a[i].r,dp[i]);
// ans=max(ans,dp[i]);
// C.Add(a[i].l,a[i].p);
// // D.Add(a[i].l,-a[i].p);
// // D.Add(a[i].r,a[i].p);
// E.Add(a[i].l,a[i].p);
// }
for(int i=1;i<=n;++i){
ans-=a[i].p;
}
ans+=s[m];
cout<<ans<<'\n';
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin>>T;
while(T--)Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 2ms
memory: 9892kb
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:
11 2
result:
wrong answer 1st numbers differ - expected: '16', found: '11'