uva 12003 Array Transformer (块状数组)
来源:互联网 发布:阿里云如何搭建ssr 编辑:程序博客网 时间:2024/05/25 05:34
大白书上的393页。
一直在原数组上乱搞。其实要用另外一个数组记录块。
原数组是不能变的。
注意好原数组和块数组的关系,细心一点处理边界。还是不难的。
#include <cstdio>#include <iostream>#include <algorithm>#include <cstring>#define maxn 300005#define SIZE 600using namespace std;int a[maxn];int block[maxn];int b[maxn];void work(int p,int x){ int old=b[p]; b[p]=x; int BLOCK=p/SIZE; int pos=p; for(int i=BLOCK*SIZE;i<BLOCK*SIZE+SIZE;i++) { if(a[i]==old) { pos=i; a[i]=x; break; } } while(block[pos+1]==block[p] && a[pos+1]<a[pos]) { swap(a[pos+1],a[pos]); pos++; } while(pos-1>=0 && block[pos-1]==block[p] && a[pos-1]>a[pos]) { swap(a[pos-1],a[pos]); pos--; }}int main(){ int n,m,u; while(scanf("%d%d%d",&n,&m,&u)!=EOF) { memset(a,0x3f,sizeof a); memset(block,0x3f,sizeof block); for(int i=0;i<n;i++) { scanf("%d",&a[i]); b[i]=a[i]; block[i]=i/SIZE; } for(int i=0;i<(n-1)/SIZE;i++) { sort(a+i*SIZE,a+(i+1)*SIZE); } sort(a+((n-1)/SIZE*SIZE),a+n); while(m--) { int l,r,v,p; scanf("%d%d%d%d",&l,&r,&v,&p); l--,r--,p--; int ans=0; if(block[l]==block[r]) { for(int i=l;i<=r;i++) if(b[i]<v)ans++; } else { for(int i=l;block[i]==block[l];i++) { if(b[i]<v)ans++; } for(int i=r;block[i]==block[r];i--) if(b[i]<v)ans++; for(int i=SIZE*(l/SIZE+1);i<r/SIZE*SIZE;i+=SIZE) { ans+=lower_bound(a+i,a+i+SIZE,v)-(a+i); } } work(p,(long long)u*ans/(r-l+1)); } for(int i=0;i<n;i++) printf("%d\n",b[i]); } return 0;}/*10 3 510 9 8 7 6 5 4 3 2 12 5 9 42 9 6 54 10 5 6*/
0 0
- uva 12003 Array Transformer (块状数组)
- uva 12003 - Array Transformer(分块+树套树)
- UVA 12003Array Transformer (分块)
- UVA 12003 Array Transformer (分块)
- UVA 12003Array Transformer(树套树)
- UVA 12003 Array Transformer [分块]
- 【uva 12003 Array Transformer】【分块】
- 【分块】UVA 12003 Array Transformer 水题
- uvaoj 12003 - Array Transformer
- codefroce D. Powerful array[初识块状数组]
- 块状数组(hdu3207 Highway)
- UVa 11922 - Permutation Transformer (Splay)
- UVA 11922 Permutation Transformer(Splay Tree)
- 块状数组
- 初识块状数组/块状链表(讲解+ 例题)
- uva12003 Array Transformer 分块
- 【POJ 2887】Big String(块状数组)
- uva 11922 - Permutation Transformer
- 使用ExtJS禁止刷新页面
- 重构中对设计模式的反思
- ubuntu下的JDK和ant安装与环境变量的配置
- JFreechart图表ChartUtilities.writeChartAsJPEG(fos_jpg,100,chart,400,300,null);// 问题出在第二个参
- Android共享数据ContentProvider的使用
- uva 12003 Array Transformer (块状数组)
- UVA 699 The Falling Leaves
- 将WCF中的事务传播到Com+组件
- cocos2d-x3.0实现2048游戏
- 博客学习七——redis虚拟内存、mongodb分片
- 杭电 1312 Red and black 搜索题
- 【记录】nginx 源代码
- PHP学习实例—2(简易图形计算器)
- 算法导论——lec 08 线性时间排序