[LOJ] 分块九题 6
单点插入,单点查询。
优化了的链表。
链表老写错,干脆用vector,也不算慢。
注意链表退化的问题,及时(比如操作根号n次)就重新建块,实测速度可以提高一倍,这还是数据随机的情况,若涉及大量同一位置插入,会让分块大大退化。
build没必要写两个。
//Stay foolish,stay hungry,stay young,stay simple
#include<iostream>
#include<cmath>
#include<cstring>
#include<cctype>
#include<vector>
#define vit vector<int>::iterator
using namespace std;
const int MAXN=500005;
inline int read_d(){
int ret=0,f=1;char c;
while(c=getchar(),!isdigit(c)) f=c=='-'?-1:1;
while(isdigit(c)){
ret=ret*10+c-'0';
c=getchar();
}
return ret*f;
}
int n;
int block,num;
vector<int> lis[1000];
int a[MAXN];
void build(int pos){
block=sqrt(n);
num=n/block;
if(n%block) num++;
for(int i=1;i<=num;i++){
for(vit it=lis[i].begin();it!=lis[i].end();it++)
a[++pos]=*it;
lis[i].clear();
}
for(int i=1;i<=num;i++)
for(int j=(i-1)*block+1;j<=i*block&&j<=n;j++)
lis[i].push_back(a[j]);
}
int query(int x){
int pos=1,siz=0;
while(siz+lis[pos].size()<x) siz+=lis[pos++].size();
return lis[pos][x-siz-1];
}
int tim;
void updata(int x,int w){
int pos=1,siz=0;tim++;n++;
while(siz+lis[pos].size()<x) siz+=lis[pos++].size();
lis[pos].insert(lis[pos].begin()+x-siz-1,w);
if(tim>block) build(0),tim=0;
}
int main(){
n=read_d();
for(int i=1;i<=n;i++) a[i]=read_d();
build(n);
int T=n;
for(int i=1;i<=T;i++){
int q=read_d(),x=read_d(),y=read_d(),z=read_d();
if(q==0) updata(x,y);
else printf("%d\n",query(y));
}
return 0;
}
[LOJ] 分块九题 6的更多相关文章
- [LOJ] 分块九题 4
https://loj.ac/problem/6280 区间修改,区间求和. 本来线段树的活. //Stay foolish,stay hungry,stay young,stay simple #i ...
- [LOJ] 分块九题 3
https://loj.ac/problem/6279 区间修改,区间查询前驱. TLE无数,我觉得这代码最精髓的就是block=1000. 谜一样的1000. 两个启示: 块内可以维护数据结构,比如 ...
- [LOJ] 分块九题 2
https://loj.ac/problem/6278 区间修改,查询区间第k大. 块内有序(另存),块内二分. 还是用vector吧,数组拷贝排序,下标搞不来.. //Stay foolish,st ...
- [LOJ] 分块九题 1
https://loj.ac/problem/6277 区间修改,单点查询. //Stay foolish,stay hungry,stay young,stay simple #include< ...
- [LOJ] 分块九题 8
区间查询数值+整体赋值 维护tag代表整个区间被赋成了tag[i] 用pushdown操作,而不是修改了再check. 不压缩代码了,调起来心累,长点有啥不好. //Stay foolish,stay ...
- [LOJ] 分块九题 7
区间加法,区间乘法,单点查询. 洛谷线段树2 屡清加法乘法的关系,定义答案为 a*mut+add 对于整块: 新的乘w,mut和add都要乘w 新的加w,add加w //Stay foolish,st ...
- [LOJ] 分块九题 5
区间开平方,区间查询. lazy标记改为区间是否全是1或者0,这样的区间是没有更新价值的. //Stay foolish,stay hungry,stay young,stay simple #inc ...
- 数列分块总结——题目总版(hzwer分块九题及其他题目)(分块)
闲话 莫队算法似乎还是需要一点分块思想的......于是我就先来搞分块啦! 膜拜hzwer学长神犇%%%Orz 这九道题,每一道都堪称经典,强力打Call!点这里进入 算法简述 每一次考试被炸得体无完 ...
- hzwer分块九题(暂时持续更新)
hzwer分块9题 分块1:区间加法,单点查询 Code #include<bits/stdc++.h> #define in(i) (i=read()) using namespace ...
随机推荐
- bzoj 4197: [Noi2015]寿司晚宴【状压dp】
一个数内可能多个的质因数只有小于根号n的,500内这样的数只有8个,所以考虑状压 把2~n的数处理出小于根号500的质因数集压成s,以及大质数p(没有就是1),然后按p排序 根据题目要求,拥有一个质因 ...
- Codeforces732D Exams
显然要二分答案,然后对于一个天数,我们来判断是否可以通过所有考试,这里就贪心来安排就好了. 首先我们希望每门课的考试时间越晚越好,然后就是先复习最早开始的考试. #include <bits/s ...
- springboot(十二) SpringBoot 性能优化
代码地址:https://github.com/showkawa/springBoot_2017/tree/master/spb-demo springboot优化主要有三类优化:1.包扫描优化 2. ...
- P1228-重叠的图像
一道很水的topsort,唉?怎么交了14遍...(某人用我的代码刚好卡过,我怎么过不去...[鄙视][鄙视][鄙视]) #include <bits/stdc++.h> using na ...
- wordpress模板安装
wordpress的模板安装方法是: 1.把下载好的模板的目录整体复制到wordpress\wp-content\themes下面,不需要单独复制哪个文件 2.到后台的"外观"中选 ...
- 为什么wait,notify和notifyAll要与synchronized一起使用?
https://blog.csdn.net/qq_39907763/article/details/79301813 Object.wait(),Object.notify(),Object.noti ...
- 题解报告:hdu 2141 Can you find it?(二分)
Problem Description Give you three sequences of numbers A, B, C, then we give you a number X. Now yo ...
- 微信小程序生成分享图片,保存到本地
1.页面 <canvas canvas-id="shareCanvas" style="width:600px;height:900px">< ...
- HDU 4366 Successor 分块做法
http://acm.hdu.edu.cn/showproblem.php?pid=4366 今日重新做了这题的分块,果然是隔太久了,都忘记了.. 首先,用DFS序变成一维的问题 关键是它有两个权值, ...
- pip 安装管理失败解决
问题: pip install ansible 错误: src/hash_template.c:361: warning: implicit declaration of function ‘Py_F ...