我是靠谱客的博主 文静月光,这篇文章主要介绍D - Snuke Prime(大数差分),现在分享给大家,希望可以做个参考。

在这里插入图片描述
在这里插入图片描述

在这里插入图片描述
题目链接

思路:差分,但是由于数据很大所以需要使用map

#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
int arr[N],arr2[N];
#define int long long
map<int,int>mp;
void solve(){
    int n,C;
    cin>>n>>C;
    int a,b,c;
    for(int i =0;i<n;i++){
        cin>>a>>b>>c;
        mp[a] +=c;
        mp[b+1]-=c;
    }
    int ans = 0 ,temp = 0, s =0;
    for(auto mm :mp){
        ans+= (mm.first-temp)*min(s,C);
        temp = mm.first;
        s+=mm.second;
    }
    cout<<ans<<endl;
}


signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int _= 1;
    //cin>>_;
    while (_--) {
        solve();
    }
}

最后

以上就是文静月光最近收集整理的关于D - Snuke Prime(大数差分)的全部内容,更多相关D内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(145)

评论列表共有 0 条评论

立即
投稿
返回
顶部