分析

按照时间为下标分块

块内按照大小排序

每次整块整体修改
半块暴力重构即可

代码

#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 序列的更多相关文章

  1. 【夯实PHP基础】UML序列图总结

    原文地址 序列图主要用于展示对象之间交互的顺序. 序列图将交互关系表示为一个二维图.纵向是时间轴,时间沿竖线向下延伸.横向轴代表了在协作中各独立对象的类元角色.类元角色用生命线表示.当对象存在时,角色 ...

  2. Windows10-UWP中设备序列显示不同XAML的三种方式[3]

    阅读目录: 概述 DeviceFamily-Type文件夹 DeviceFamily-Type扩展 InitializeComponent重载 结论 概述 Windows10-UWP(Universa ...

  3. 软件工程里的UML序列图的概念和总结

    俗话说,自己写的代码,6个月后也是别人的代码……复习!复习!复习! 软件工程的一般开发过程:愿景分析.业务建模,需求分析,健壮性设计,关键设计,最终设计,实现…… 时序图也叫序列图(交互图),属于软件 ...

  4. python序列,字典备忘

    初识python备忘: 序列:列表,字符串,元组len(d),d[id],del d[id],data in d函数:cmp(x,y),len(seq),list(seq)根据字符串创建列表,max( ...

  5. BZOJ 1251: 序列终结者 [splay]

    1251: 序列终结者 Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 3778  Solved: 1583[Submit][Status][Discu ...

  6. 最长不下降序列nlogn算法

    显然n方算法在比赛中是没有什么用的(不会这么容易就过的),所以nlogn的算法尤为重要. 分析: 开2个数组,一个a记原数,f[k]表示长度为f的不下降子序列末尾元素的最小值,tot表示当前已知的最长 ...

  7. [LeetCode] Sequence Reconstruction 序列重建

    Check whether the original sequence org can be uniquely reconstructed from the sequences in seqs. Th ...

  8. [LeetCode] Binary Tree Longest Consecutive Sequence 二叉树最长连续序列

    Given a binary tree, find the length of the longest consecutive sequence path. The path refers to an ...

  9. [LeetCode] Repeated DNA Sequences 求重复的DNA序列

    All DNA is composed of a series of nucleotides abbreviated as A, C, G, and T, for example: "ACG ...

随机推荐

  1. KNN-机器学习算法

    ''' Created on Sep 16, 2010 kNN: k Nearest Neighbors Input: inX: vector to compare to existing datas ...

  2. OCR(光学字符识别)技术简介

    OCR技术起源 OCR最早的概念是由德国人Tausheck最先提出的,1966年他们发表了第一篇关于汉字识别的文章,采用了模板匹配法识别了1000个印刷体汉字.早在60.70年代,世界各国就开始有OC ...

  3. nginx的代理服务

    nginx的代理服务 正向代理和反向代理 正向代理服务器就是用来让局域网的客户端接入外网访问外网资源,反向代理就是让外网的客户端接入局域网中的站点以访问点中的资源 正向代理 我是一个用户,我访问不了某 ...

  4. 跨域 (2) cors

    html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...

  5. Canvas + WebSocket + Redis 实现一个视频弹幕

    原文出自:https://www.pandashen.com 页面布局 首先,我们需要实现页面布局,在根目录创建 index.html 布局中我们需要有一个 video 多媒体标签引入我们的本地视频, ...

  6. DRF介绍,DRF项目开发,DRF项目的视图类的dispatch源码解析

    目录 一.DRF介绍 1. 什么是DRF 2. 为什么要用DRF (1)使用DRF的原因 (2)站在开发者的角度来说用DRF的好处(暂时列举这么多) 二.用DRF开发后端项目 三.APIView请求生 ...

  7. 指数家族-Beta分布

    2. Beta分布 2.1 Beta分布 我们将由几个问题来得引出几个分布: 问题一:1:  2:把这个  个随机变量排序后得到顺序统计量  3:问  是什么分布 首先我们尝试计算  落在一个区间   ...

  8. C++ Arrays, std::array, std::vector 总结

    原文来自: https://shendrick.net/Coding%20Tips/2015/03/15/cpparrayvsvector.html @Seth Hendrick Original a ...

  9. Educational Codeforces round 78 A、B

    链接:https://codeforces.com/contest/1278 A:Shuffle Hashing 题意:对于一个字符串p可以执行一个"hash"操作,首先将p内的元 ...

  10. 14.django返回展示一张图片

    urlpatterns = [ path('admin/', admin.site.urls), # 使用django返回一张土图片的时候需要间接的访问一个中间接口,是html页面的中的img的src ...