QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#578385#9322. Segments RemovalAfterlifeWA 39ms17972kbC++202.5kb2024-09-20 18:46:382024-09-20 18:46:38

Judging History

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

  • [2024-09-20 18:46:38]
  • 评测
  • 测评结果:WA
  • 用时:39ms
  • 内存:17972kb
  • [2024-09-20 18:46:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
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;

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=0;
    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=0;
    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';
}
int 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: 100
Accepted
time: 0ms
memory: 17972kb

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: 3ms
memory: 17956kb

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: 39ms
memory: 15852kb

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:

85
40
18
14
41
213
81
260
17
157
189
13
43
182
48
148
68
2
177
196
167
94
205
150
59
306
269
117
0
166
118
20
79
142
189
54
70
33
176
7
41
21
183
27
35
32
45
0
243
216
50
51
54
203
141
18
0
60
171
2
246
236
113
8
182
0
0
74
154
12
173
92
42
86
22
83
59
270
144
59
22
153
145
26
56
0
90
44
63
18
129
0...

result:

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