QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#715075 | #9529. Farm Management | ucup-team5271# | WA | 1ms | 5852kb | C++17 | 2.3kb | 2024-11-06 10:17:52 | 2024-11-06 10:17:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
mt19937 Rnd(time(0));
typedef struct{
int l,r,w;
}AD;
bool cmp(AD A,AD B)
{
return A.w > B.w;
}
AD a[100011];
typedef struct{
int key,ls,rs,siz;
long long Ls,xs,valL,valx;
int l,x,w;
}Tree;
Tree t[100011];
int root;
void push_up(int p)
{
t[p].Ls = t[t[p].ls].Ls + t[t[p].rs].Ls + t[p].l;
t[p].xs = t[t[p].ls].xs + t[t[p].rs].xs + t[p].x;
t[p].valL = t[t[p].ls].valL + t[t[p].rs].valL + 1ll * t[p].l * t[p].w;
t[p].valx = t[t[p].ls].valx + t[t[p].rs].valx + 1ll * t[p].x * t[p].w;
t[p].siz = t[t[p].ls].siz + 1 + t[t[p].rs].siz;
}
int merge(int x,int y)
{
if(!x || !y) return x|y;
if(t[x].key < t[y].key)
return t[x].rs = merge(t[x].rs,y),push_up(x),x;
return t[y].ls = merge(x,t[y].ls),push_up(y),y;
}
void split_x(int p,long long k,int& l,int& r)
{
if(!p) return l = r = 0,void();
if(t[t[p].ls].xs + t[p].x <= k)
return l = p,split_x(t[p].rs,k - t[t[p].ls].xs - t[p].x,t[p].rs,r),push_up(p);
return r = p,split_x(t[p].ls,k,l,t[p].ls),push_up(p);
}
void split_s(int p,int k,int& l,int& r)
{
if(!p) return l = r = 0,void();
if(t[t[p].ls].siz + 1 <= k)
return l = p,split_s(t[p].rs,k - t[t[p].ls].siz - 1,t[p].rs,r),push_up(p);
return r = p,split_s(t[p].ls,k,l,t[p].ls),push_up(p);
}
int n;
long long m;
long long Solve(int& rt)
{
if(t[rt].Ls + t[rt].xs < m)
return 0;
long long S = m - t[rt].Ls,res = t[rt].valL;
int l,p = 0,r;
split_x(rt,S,l,r);
res += t[l].valx;
S -= t[l].xs;
if(r)
split_s(r,1,p,r),res += t[p].w * S;
rt = merge(merge(l,p),r);
return res;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> m;
for(int i = 1;i <= n;i++)
cin >> a[i].w >> a[i].l >> a[i].r;
sort(a + 1,a + n + 1,cmp);
for(int i = 1;i <= n;i++)
{
t[i] = {(int)Rnd(),0,0,1,0,0,0,0,a[i].l,a[i].r - a[i].l,a[i].w};
push_up(i);
root = merge(root,i);
}
long long ans = Solve(root);
for(int i = 1;i <= n;i++)
{
int l,p,r;
split_s(root,i - 1,l,r);
split_s(r,1,p,r);
root = merge(l,r);
ans = max(ans,Solve(root));
split_s(root,i - 1,l,r);
root = merge(merge(l,p),r);
}
cout << ans;
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3672kb
input:
5 17 2 3 4 6 1 5 8 2 4 4 3 3 7 5 5
output:
109
result:
ok single line: '109'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5852kb
input:
12 62 503792 9 10 607358 1 3 600501 10 10 33249 4 4 774438 6 6 197692 3 6 495807 8 8 790225 5 9 77272 3 8 494819 4 9 894779 3 9 306279 5 6
output:
35204500
result:
ok single line: '35204500'
Test #3:
score: -100
Wrong Answer
time: 1ms
memory: 5848kb
input:
15 32 835418 2 3 178262 1 3 527643 2 2 519710 1 1 774544 3 3 82312 1 1 808199 1 1 809396 1 3 255882 1 3 80467 1 3 874973 1 3 813965 1 2 198275 1 2 152356 1 3 802055 1 1
output:
17015002
result:
wrong answer 1st lines differ - expected: '22000255', found: '17015002'