QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#715264 | #9529. Farm Management | ucup-team5271# | ML | 1ms | 5716kb | C++17 | 2.3kb | 2024-11-06 11:10:08 | 2024-11-06 11:10:08 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
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,int p)
{
int l,r;
split_s(rt,p - 1,l,r);
split_s(r,1,p,r);
long long res = t[l].valL + t[r].valL,S = m - t[l].Ls - t[r].Ls;
if(t[l].xs <= S)
{
S -= t[l].xs;
res += t[l].valx + (S * a[p].w);
}else{
int L,R;
split_x(l,S,L,R);
res += t[L].valx;
S -= t[L].xs;
int M;
split_s(R,1,M,R);
res += t[M].w * S;
r = merge(merge(L,M),R);
}
rt = merge(merge(l,p),r);
return res;
}
signed 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 = 0;
for(int i = 1;i <= n;i++)
ans = max(ans,Solve(root,i));
cout << ans;
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5716kb
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: -100
Memory Limit Exceeded
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