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 ...
随机推荐
- caffe数据集LMDB的生成
本文主要介绍如何在caffe框架下生成LMDB.其中包含了两个任务的LMDB生成方法,一种是分类,另外一种是检测. 分类任务 第一步 生成train.txt和test.txt文件文件 对于一个监督学 ...
- Spring学习之设计模式,动态代理和gclib动态代理
传统的代理模式是静态代理,也就是在方法区域中写入方法. 而动态代理的作用是,不修改实现类的代码,能够在代码的前后或者抛出异常的前后执行某个方法. 动态代理类的实现 //Interface public ...
- (转) MiniUI使用
来源于https://my.oschina.net/yunsy/blog/542597 1.MiniUI页签定位 <body> <input name = "bizType ...
- 机器学习四 SVM
目录 引言 SVM 线性可分SVM 线性不可分SVM Hinge Loss 非线性SVM 核函数 总结 参考文献 引言 在深度神经网终(Deep Neural Network, DNN) 大热之前, ...
- Codeforces 981 共同点路径覆盖树构造 BFS/DP书架&最大值
A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_bac ...
- webpack 热更新
1.安装webpack npm install webpack -g //全局安装 npm install webpack --save-dev //开发环境 2.使用webpack 创建一个we ...
- web性能优化--减少客户端请求数(一)
多图标合并,用css分隔 设置较长时间的过期时间 合并多个css文件 合并多个js文件 根据域名划分内容 首先介绍一款速度测试工具:webpagetest(填上url,username,passwor ...
- 【ZJOJ5186】【NOIP2017提高组模拟6.30】tty's home
题目 分析 如果直接求方案数很麻烦. 但是,我们可以反过来做:先求出所有的方案数,在减去不包含的方案数. 由于所有的路径连在一起, 于是\(设f[i]表示以i为根的子树中,连接到i的方案数\) 则\( ...
- spark数据倾斜与解决方法
一.数据倾斜 数据倾斜一般发生在对数据进行重新划分以及聚合的处理过程中.执行Spark作业时,数据倾斜一般发生在shuffle过程中,因为Spark的shuffle过程需要进行数据的重新划分处理.在执 ...
- 【leetcode】1220. Count Vowels Permutation
题目如下: Given an integer n, your task is to count how many strings of length n can be formed under the ...