p3863 序列
分析
按照时间为下标分块
块内按照大小排序
每次整块整体修改
半块暴力重构即可
代码
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define int long long
priority_queue<pair<int,int> >p;
int n,m,bl[],a[],cnt1,cnt2,b,ans[];
int val[],w[],L[],R[],tag[];
struct upd{
int le,ri,x,t;
};
upd d[];
struct ask{
int pl,x,t,id;
};
ask q[];
inline bool cmp(const upd x,const upd y){
if(x.le==y.le)return x.t<y.t;
return x.le<y.le;
}
inline bool cmp2(const ask x,const ask y){
if(x.pl==y.pl)return x.t<y.t;
return x.pl<y.pl;
}
inline void work(int le,int ri,int x){
int i,j,k;
if(bl[le]==bl[ri]){
for(i=le;i<=ri;i++)val[i]+=x;
k=bl[le];
for(i=L[k];i<=R[k];i++)w[i]=val[i];
sort(w+L[k],w+R[k]+);
return;
}
for(i=le;i<=R[bl[le]];i++)val[i]+=x;
for(i=L[bl[le]];i<=R[bl[le]];i++)w[i]=val[i];
sort(w+L[bl[le]],w+R[bl[le]]+);
for(i=L[bl[ri]];i<=ri;i++)val[i]+=x;
for(i=L[bl[ri]];i<=R[bl[ri]];i++)w[i]=val[i];
sort(w+L[bl[ri]],w+R[bl[ri]]+);
for(i=bl[le]+;i<bl[ri];i++)tag[i]+=x;
}
inline int go(int wh,int x){
int k=lower_bound(w+L[wh],w+R[wh]+,x)-w;
if(k==R[wh]+)return ;
return R[wh]-k+;
}
inline int que(int pl,int x){
int i,j,k,res=;
for(i=;i<bl[pl];i++)res+=go(i,x-tag[i]);
for(i=L[bl[pl]];i<=pl;i++)if(val[i]>=x-tag[bl[pl]])res++;
return res;
}
signed main(){
int i,j,k;
scanf("%lld%lld",&n,&m);m++;
for(i=;i<=n;i++)scanf("%lld",&a[i]);
for(i=;i<=m;i++){
scanf("%lld",&k);
if(k==){
++cnt2;
scanf("%lld%lld%lld",&d[cnt2].le,&d[cnt2].ri,&d[cnt2].x);
d[cnt2].t=i;
}else {
++cnt1;
scanf("%lld%lld",&q[cnt1].pl,&q[cnt1].x);
q[cnt1].t=i;
q[cnt1].id=cnt1;
}
}
b=sqrt((n+));j=;
for(i=;i<=m;i++)bl[i]=(i-)/b+;
int sum=bl[m];
for(i=;i<=sum;i++)L[i]=R[i-]+,R[i]=R[i-]+b;
R[sum]=min(R[sum],m);
sort(d+,d+cnt2+,cmp);
sort(q+,q+cnt1+,cmp2);
for(i=;i<=cnt1;i++){
while(!p.empty()&&-p.top().fi<q[i].pl){
int x=p.top().se;
work(d[x].t,m,-d[x].x);
p.pop();
}
if(q[i].pl!=q[i-].pl){
work(,m,a[q[i].pl]);
work(,m,-a[q[i-].pl]);
}
while(j<=cnt2&&d[j].le<=q[i].pl){
if(d[j].ri<q[i].pl){j++;continue;}
work(d[j].t,m,d[j].x);
p.push(mp(-d[j].ri,j));
j++;
}
ans[q[i].id]=que(q[i].t-,q[i].x);
}
for(i=;i<=cnt1;i++)printf("%lld\n",ans[i]);
return ;
}
p3863 序列的更多相关文章
- 【夯实PHP基础】UML序列图总结
原文地址 序列图主要用于展示对象之间交互的顺序. 序列图将交互关系表示为一个二维图.纵向是时间轴,时间沿竖线向下延伸.横向轴代表了在协作中各独立对象的类元角色.类元角色用生命线表示.当对象存在时,角色 ...
- Windows10-UWP中设备序列显示不同XAML的三种方式[3]
阅读目录: 概述 DeviceFamily-Type文件夹 DeviceFamily-Type扩展 InitializeComponent重载 结论 概述 Windows10-UWP(Universa ...
- 软件工程里的UML序列图的概念和总结
俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习! 软件工程的一般开发过程:愿景分析.业务建模,需求分析,健壮性设计,关键设计,最终设计,实现…… 时序图也叫序列图(交互图),属于软件 ...
- python序列,字典备忘
初识python备忘: 序列:列表,字符串,元组len(d),d[id],del d[id],data in d函数:cmp(x,y),len(seq),list(seq)根据字符串创建列表,max( ...
- BZOJ 1251: 序列终结者 [splay]
1251: 序列终结者 Time Limit: 20 Sec Memory Limit: 162 MBSubmit: 3778 Solved: 1583[Submit][Status][Discu ...
- 最长不下降序列nlogn算法
显然n方算法在比赛中是没有什么用的(不会这么容易就过的),所以nlogn的算法尤为重要. 分析: 开2个数组,一个a记原数,f[k]表示长度为f的不下降子序列末尾元素的最小值,tot表示当前已知的最长 ...
- [LeetCode] Sequence Reconstruction 序列重建
Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...
- [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列
Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...
- [LeetCode] Repeated DNA Sequences 求重复的DNA序列
All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...
随机推荐
- LOCATE()和FIND_IN_SET()
locate(substr,str) 查找substr在str中第一次出现的位置,为空时返回0 SELECT login_name, LOCATE('ning',login_name) FROM us ...
- CentOS下配置Apache HTTPS
一.安装Apache支持SSL/TLS yum install mod_ssl openssl 二.创建证书 证书(Cerificate)的基本作用是将一个公钥和安全个体(个人.公司.组织等)的名字绑 ...
- Unicode字符集,utf8编码,base64编码简单了解
Unicode字符集,utf8编码,base64编码简单了解 Unicode字符集,ASCII,GB2312编码集合等,类似于不同的字典,不同的字符的编码,类似于字典中的字在哪一个页哪一排. 当不同系 ...
- Struts2.5以上版本There is no Action mapped for namespace [/] and action name [userAction_login] associated with context path []
分析:Struts2在2.5版本后添加strict-method-invocation(严格方法访问),默认为true,不能使用动态方法调用功能,故需设为false struts.xml设置如下: & ...
- Windows PyCharm QtDesigner/pyuic5配置
QtDesigner 配置成功截图如下: C:\ProgramData\Anaconda3\Library\bin\designer.exe $FileDir$ pyuic5 配置成功截图如下: C: ...
- hier - 文件系统描述
DESCRIPTION 描述 一个典型的Linux系统具有以下几个目录: / 根目录,是所有目录树开始的地方. /bin 此目录下包括了单用户方式及系统启动或修复所用到的所有执行程序. /boot 包 ...
- Ansible批量部署工具
Ansible:自动化运维工具 你需要在一台机器上yum install 一个包,这时候有一个需求,比如现在有5台机同时需要装apache这个包,那么100台呢,ssh上去就太慢了,这时候就借助到了a ...
- python_实现选课系统
校园管理系统 角色: 学校.学员.课程.讲师 要求: 1. 创建北京.上海 2 所学校 2. 创建linux , python , go 3个课程 , linux\py 在北京开, go 在上海开 3 ...
- HDU - 1024 Max Sum Plus Plus 最大m段子段和+滚动数组优化
给定n个数字,求其中m段的最大值(段与段之间不用连续,但是一段中要连续) 例如:2 5 1 -2 2 3 -1五个数字中选2个,选择1和2 3这两段. dp[i][j]从前j个数字中选择i段,然后根据 ...
- 对请求的request添加一些参数
- (NSURLRequest *)addHeaderRequestWithUrl:(NSString *)urlStr{ NSMutableURLRequest *mutableRequest ...