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 ...
随机推荐
- 如何在Ubuntu上在多个PHP版本之间切换 (for swoole)
摘要: 之前一直用Php7.0,今天想用7.2试下一些特性,安装完之后,切换回7.0却不能再使用7.0的swoole了,原来是切换方式出现了问题 一 从PHP 7.0 切换到 PHP 7.2 Apac ...
- html元素标签时间格式化
<fmt:formatDate value="${user.loginTime}" pattern="yyyy-MM-dd HH:mm:ss"/>
- vue-cli设置引入目录
打开build/webpack.base.conf.js 找到module.exports下的resolve这行 刚开始是这样的 resolve: { extensions: ['.js', '.vu ...
- ceph对接openstack
一.使用rbd方式提供存储如下数据: (1)image(glance):保存glanc中的image: (2)volume(cinder)存储:保存cinder的volume:保存创建虚拟机时选择创建 ...
- Service_Worker XSS
0x00 简介 Service Worker 是 Chrome 团队提出和力推的一个 WEB API,用于给 web 应用提供高级的可持续的后台处理能力.该 WEB API 标准起草于 2013 年, ...
- 找不到javax.
https://blog.csdn.net/q343509740/article/details/79515911 idea导入java工程 file --> new -->存在的工程
- ubuntu 配置smb后无法访问
配置如下 [/gscloud] path = /gscloud browseable = yes writable = yes guest ok = yes read only = no create ...
- Python开发WebService--使用soaplib库
Python开发WebService--使用soaplib库 使用soaplib开发基于Python语言的WebService主要有以下四个步骤:一.准备环境 S1:下载插件Python.s ...
- cm日志哪里看
root@d001:/home/centos# find / |grep cloudera-scm-agent.log/opt/cm-5.13.0/log/cloudera-scm-agent/clo ...
- ESP8266--WIFI热点扫描
现在,通常,为了让手机连上一个WiFi热点,基本上都是打开手机设置里面的WiFi设置功能,然后会看到里面有个WiFi热点列表,然后选择你要的连接上. 基本上你只要打开手机连接WiFi功能,都会发现附近 ...