专栏文章
题解:P12194 [NOISG 2025 Prelim] Snacks
P12194题解参与者 1已保存评论 0
文章操作
快速查看文章及其快照的属性,并进行相关操作。
- 当前评论
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @mioxakq3
- 此快照首次捕获于
- 2025/12/03 02:40 3 个月前
- 此快照最后确认于
- 2025/12/03 02:40 3 个月前
本题是 STL 好练习题,标签诚不欺人。
提供一个非常简单的
map 做法。这题甚至不需要珂朵莉树(因为这题只关心值的大小而并不关心顺序),所以直接用
map 统计数目即可。容易注意到复杂度是 并且跑不满的。然后开好
long long 即可,注意中间会有计算过程也会爆 int,爆有符号整数在谷上是不会 RE 的,只会 WA,望周知。贴代码。
CPP#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(0),cin.tie(0);
int n,q;
cin>>n>>q;
map<int,int>mp;
long long ans=0;
for(int i=1;i<=n;i++)
{
int t;
cin>>t;
mp[t]++;
ans+=t;
}
cout<<ans<<'\n';
q++;
while(--q)
{
int l,r,x;
cin>>l>>r>>x;
int cnt=0;
auto lp=mp.lower_bound(l),rp=mp.upper_bound(r);
for(auto tp=lp;rp!=tp;tp++)
cnt+=tp->second,ans-=static_cast<long long>(tp->first)*tp->second;
mp.erase(move(lp),move(rp));
mp[x]+=cnt;
ans+=(long long)cnt*x;
cout<<ans<<'\n';
}
return 0;
}
相关推荐
评论
共 0 条评论,欢迎与作者交流。
正在加载评论...