[cf453e]Little Pony and Lord Tirek

时间:2022-08-30 09:15:53

来自FallDream的博客,未经允许,请勿转载,谢谢。


更博客= =

有n个数,每个数字都有一个初始大小ai和最大值mi,然后每秒会增加ri,你需要回答m个发生时间依此增大的询问,每次询问区间和并且将区间的所有数字变成0.

n,m<=10^5

考虑直接用set维护颜色段,这样操作到的段数是O(n)的。然后特殊处理开始的情况,就变成了若干个询问,每次询问一个区间的数全部从0开始,一定时间之后的和。

将这些询问排序,并且将所有数字到达最大值的时间排序,用两棵线段树来模拟就行了,复杂度O(nlogn)

#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<set>
#define MN 100000
#define N 131072
using namespace std;
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
struct data{int l,r,t,x;
data(int _l,int _r,int _t,int _x){l=_l;r=_r;t=_t;x=_x;}
data(int k){l=k;r=;}
bool operator <(const data&b)const{return l==b.l?r<b.r:l<b.l;}
};
set<data> s;long long Ans[MN+],T1[N*+],T2[N*+];
int n,m,top,a[MN+],mx[MN+],R[MN+],rk[MN+],tms[MN+];
struct ques{int l,r,t,id;}q[MN*+];
int Calc(int t,int x,int r,int m){return (int)min((long long)m,x+1LL*r*t);}
bool cmp(const ques&a,const ques&b){return a.t<b.t;}
bool cmp2(int x,int y){return tms[x]<tms[y];}
void Renew(long long*T,int x,int v){for(T[x+=N]+=v;x>>=;)T[x]=T[x<<]+T[x<<|];}
long long Query(long long*T,int l,int r)
{
long long sum=;
for(l+=N-,r+=N+;l^r^;l>>=,r>>=)
{
if(~l&) sum+=T[l+];
if( r&) sum+=T[r-];
}
return sum;
}
int main()
{
n=read();
for(int i=;i<=n;++i)
{
a[i]=read();mx[i]=read();R[i]=read();tms[i]=R[i]?(int)ceil((double)mx[i]/R[i]):2e9;
s.insert(data(i,i,,a[i])); rk[i]=i;
}
m=read();
for(int i=;i<=m;++i)
{
int t=read(),l=read(),r=read();
set<data>::iterator it=s.lower_bound(data(l));
for(;it!=s.end()&&it->l<=r;it=s.lower_bound(data(l)))
{
if(it->r>r) s.insert(data(r+,it->r,it->t,it->x));
if(it->r==it->l) Ans[i]+=Calc(t-it->t,it->x,R[it->r],mx[it->r]);
else q[++top]=(ques){it->l,min(it->r,r),t-it->t,i};
s.erase(it);
}
for(;it!=s.begin()&&(--it)->r>=l;it=s.lower_bound(data(l)))
{
if(it->r>r) s.insert(data(r+,it->r,it->t,it->x));
if(it->l<l) s.insert(data(it->l,l-,it->t,it->x));
q[++top]=(ques){max(it->l,l),min(r,it->r),t-it->t,i};
s.erase(it);
}
s.insert(data(l,r,t,));
}
sort(rk+,rk+n+,cmp2);
sort(q+,q+top+,cmp);
for(int i=;i<=n;++i) Renew(T1,i,R[i]);
for(int i=,j=;i<=top;)
if(j<=n&&tms[rk[j]]<=q[i].t)
{
Renew(T1,rk[j],-R[rk[j]]);
Renew(T2,rk[j],mx[rk[j]]);
++j;
}
else
{
Ans[q[i].id]+=1LL*q[i].t*Query(T1,q[i].l,q[i].r)+Query(T2,q[i].l,q[i].r);
++i;
}
for(int i=;i<=m;++i) printf("%lld\n",Ans[i]);
return ;
}

[cf453e]Little Pony and Lord Tirek的更多相关文章

  1. Codeforces 453E - Little Pony and Lord Tirek(二维线段树&plus;ODT)

    Codeforces 题目传送门 & 洛谷题目传送门 一道难度 *3100 的 DS,而且被我自己搞出来了! 不过我终究还是技不如人,因为这是一个 \(n\log^2n\) + 大常数的辣鸡做 ...

  2. 2021record

    2021-10-14 P2577 [ZJOI2004]午餐 2021-10-13 CF815C Karen and Supermarket(小小紫题,可笑可笑) P6748 『MdOI R3』Fall ...

  3. CF数据结构练习

    1. CF 438D The Child and Sequence 大意: n元素序列, m个操作: 1,询问区间和. 2,区间对m取模. 3,单点修改 维护最大值, 取模时暴力对所有>m的数取 ...

  4. CF453&lpar;Div1 简单题解&rpar;

    A .Little Pony and Expected Maximum pro:给定M,N,表示一个M面的骰子,甩N次,问出现的最大的数的期望. sol:容斥,f(i)表示最大数<=i的期望,那 ...

  5. CF453C Little Pony and Summer Sun Celebration (DFS)

    http://codeforces.com/contest/456  CF454E Codeforces Round #259 (Div. 1) C Codeforces Round #259 (Di ...

  6. CF453B Little Pony and Harmony Chest (状压DP)

    CF453B CF454D Codeforces Round #259 (Div. 2) D Codeforces Round #259 (Div. 1) B D. Little Pony and H ...

  7. codeforces 374A Inna and Pink Pony 解题报告

    题目链接:http://codeforces.com/problemset/problem/374/A 题目意思:给出一个 n 行  m 列 的棋盘,要将放置在坐标点为(i, j)的 candy 移动 ...

  8. CodeForces 454C Little Pony and Expected Maximum

    Little Pony and Expected Maximum Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I6 ...

  9. Codeforces Round &num;259 &lpar;Div&period; 2&rpar; C - Little Pony and Expected Maximum (数学期望)

    题目链接 题意 : 一个m面的骰子,掷n次,问得到最大值的期望. 思路 : 数学期望,离散时的公式是E(X) = X1*p(X1) + X2*p(X2) + …… + Xn*p(Xn) p(xi)的是 ...

随机推荐

  1. 1877&colon; &lbrack;SDOI2009&rsqb;晨跑

    1877: [SDOI2009]晨跑 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 2007  Solved: 1085[Submit][Status][ ...

  2. poj 2019 二维rmq &ast;

    题目大意:给出一个N*N矩形,每个格子上有一个价值.询问一个b*b的矩形在左上角的位置(x,y),(x+b-1,y+b-1)这一部分的最大值-最小值是多少. 模板题 #include <stdi ...

  3. LeetCode Pow&lpar;x&comma; n&rpar; (水题)

    题意: 求浮点型x的n次幂结果. 思路: logN直接求,注意n可能为负数!!!当n=-2147483648的时候,千万别直接n=-n,这样的结果是多少?其他求法大同小异. class Solutio ...

  4. 一个鼠标键盘控制两台甚至多台主机的方法--Synergy

    在多台主机,不同系统中操作.避免了更换键鼠的麻烦.即使下面图中的功能. 鼠标同时在三台或者多台主机之间进行移动,而且是无缝滑动,鼠标直接从左滑倒右,而且支持,这台电脑复制,另一台黏贴.非常的方便实用. ...

  5. iOS开发:自定义tableViewCell处理的问题

    还在适配iOS6,索性下一个版本不适配了~~~~~ 问题: *** Assertion failure in -[ PCDiaryDetailReplyCell layoutSublayersOfLa ...

  6. Timus 1796&period; Amusement Park 聪明题

    On a sunny Sunday, a group of children headed by their teacher came to an amusement park. Aunt Frosy ...

  7. auto property synthesis will not synthesize proterty &semi;it will be implementedby its superclass&comma; use &commat;

    Auto property synthesis will not synthesize property 'title'; it will be implemented by its supercla ...

  8. 我的Spring学习记录(三)

    学习了AOP之后就可以应用一下了,所以这次我们了解一下Spring的声明式事务. 事务在我们的很多方面都可以体现,就拿我们平时的买卖活动,或者是银行的转账来说,这些活动要么是成功,要么是失败,比如:张 ...

  9. django restframework 跨域访问

    场景介绍: 在Django开发过程中,使用前后端分离设计的站点越来越多,如Django+VUE.Django+Angular.在使用DjangoRestFramework开发API的过程中,由于前端站 ...

  10. spring cloud config svn仓库配置

    之前快速入门了一下spring cloud config 但是仓库用的别人博客上的git仓库,公司用的是svn项目管理中心,下面这个自己配置的时候出现的错误 You need to configure ...