跳到正文

Wangyanzhen2011

773817

我太懒了

在洛谷打开
资料、奖项与版本

资料

编号
773817
抓取

奖项

2025 CSP-S
三等奖
2024 CSP-J
一等奖

这个人真的不懒,应该什么都写了吧……
5201314159265358979323845141919810

C++
/**
 * 题目名:#A. 调整
 * 做法:
 * 得分:100pts
 */
#include<iostream>
#include<iomanip>
#include<climits>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;

const int INF=0x3f3f3f3f,BINF=0x3f,KINF=1e9;
const ll LINF=1e18;

const int N=25,M=100;
ll d[4*M+5],b[4*M+5];
/*懒标记下传*/
void pushdown(int p,int l,int r){
    int mid=(l+r)/2;
    b[p*2]+=b[p];
    b[p*2+1]+=b[p];
    d[p*2]+=b[p]*(mid-l+1);
    d[p*2+1]+=b[p]*(r-mid);
    b[p]=0;
}
/*将l~r加上k*/
void update(int p,int s,int t,int l,int r,ll k){
    if(l<=s&&t<=r){
        b[p]+=k;
        d[p]+=k*(t-s+1);
        return;
    }
    int mid=(s+t)/2;
    pushdown(p,s,t);
    if(l<=mid)
        update(p*2,s,mid,l,r,k);
    if(mid<r)
        update(p*2+1,mid+1,t,l,r,k);
    d[p]=d[p*2]+d[p*2+1];
}
/*求l-r区间和*/
ll getsum(int p,int s,int t,int l,int r){
    if(l<=s&&t<=r)
        return d[p];
    int mid=(s+t)/2;
    ll sum=0;
    pushdown(p,s,t);
    if(l<=mid)
        sum+=getsum(p*2,s,mid,l,r);
    if(mid<r)
        sum+=getsum(p*2+1,mid+1,t,l,r);
    return sum;
}
struct qode{
    int s,t,c;
}q[N];
struct oode{
    int a,b,p,m;
}o[N];
int a[M+5];
int n,m;
int ans=INF;
bool check(){
    for(int i=1;i<=n;i++)
        for(int j=q[i].s;j<=q[i].t;j++){
            if(getsum(1,1,M,j,j)<q[i].c)
                return false;
        }
    return true;
}
void dfs(int r,int cnt){
    if(r==m+1){
        if(check())
            ans=min(ans,cnt);
        return;
    }
    dfs(r+1,cnt);
    update(1,1,M,o[r].a,o[r].b,o[r].p);
    dfs(r+1,cnt+o[r].m);
    update(1,1,M,o[r].a,o[r].b,-o[r].p);
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    
    cin>>n>>m;
    for(int i=1;i<=n;i++)
        cin>>q[i].s>>q[i].t>>q[i].c;
    for(int i=1;i<=m;i++)
        cin>>o[i].a>>o[i].b>>o[i].p>>o[i].m;
    dfs(1,0);
    cout<<ans<<endl;
    return 114514;
}

还没有收录这位用户的文章。