[CF]292E. Copying Data 分块
来源:互联网 发布:餐饮软件 编辑:程序博客网 时间:2024/06/05 03:52
我想说这Round1是不是5道暴力啊!是不是暴力啊!是不是暴力!是不是!
不会写线段树,E在比赛的时候YY了一个分块一直WA,后来调的时候发现有个布尔值写反了?……
效果还可以……不算快但也不至于特别慢,毕竟数据范围和CF评测机在这里摆着呢,空间很小而且还可以压……
/* 按sqrt(n)分块 如果两端在同一块内就直接暴力,否则分别暴力所在块到一端这一段再暴力它们之间的块 唯一要注意的是如果一块被标记是成段修改的,在暴力内部之前要先循环赋值一下并且去掉标记 */#include <iostream>#include <cstdio>#include <cstring>#include <cmath>using namespace std;#define N 200000struct {int l,r,al,ar; bool c;} block [10000];int size,a[N],b[N];int getb(int x) {return 1+(x-1)/size;}void ext(int p) { if (!block[p].c) return; block[p].c=false; for (int i=block[p].l; i<=block[p].r; i++) b[i]=a[block[p].al+i-block[p].l];}int main() { int n,m; scanf("%d%d",&n,&m); for (int i=1; i<=n; i++) scanf("%d",&a[i]); for (int i=1; i<=n; i++) scanf("%d",&b[i]); size=(int)sqrt(n); int p=0,tot=0; while (p+size<n) { block[++tot].l=p+1; block[tot].r=(p+=size); block[tot].c=false; } block[++tot].l=p+1; block[tot].r=n; block[tot].c=false; for (int i=1; i<=m; i++) { int t; scanf("%d",&t); if (t==1) { int x,y,k,b1,b2; scanf("%d%d%d",&x,&y,&k); b1=getb(y); b2=getb(y+k-1); if (b1!=b2) { ext(b1); ext(b2); for (int i=y; i<=block[b1].r; i++) b[i]=a[x+i-y]; for (int i=b1+1; i<b2; i++) { block[i].c=true; block[i].al=x+block[i].l-y; block[i].ar=x+block[i].r-y; }for (int i=block[b2].l; i<y+k; i++) b[i]=a[x+i-y]; } else { ext(b1); for (int i=0; i<k; i++) b[y+i]=a[x+i]; } } else { int x; scanf("%d",&x); int gb=getb(x); if (block[gb].c) printf("%d\n",a[block[gb].al+x-block[gb].l]); else printf("%d\n",b[x]); } } //system("pause"); return 0;}
果然还是太弱了…………
- [CF]292E. Copying Data 分块
- CF 292E Copying Data
- codeforces 292E. Copying Data
- Codeforces 292E(Copying Data)
- CodeForces 292E Copying Data (线段树)
- codeforces 292E Copying Data(线段树)
- 线段树(区间更新)codeforces 292E Copying Data
- CF 813E 分块暴力
- CF-E. Holes(区间分块,二分思想)
- CF 13E Holes(分块处理)
- CF 342E Xenia and Tree(分块)
- 【分块】 CF 551 E GukiZ and GukiZiana
- CF 31E 分块,状态压缩
- CF#307-E. GukiZ and GukiZiana-分块法/平方分桶
- cf-e
- 线段树 Codeforces292E Copying Data
- CF292E Copying Data【线段树】
- Codeforce 785E(分块)
- Jquery导航条在项目中的应用
- 正则表达式(二)
- 计算机动画(一)
- [IOS ScrollView]--PSCollectionView
- cocos2d
- [CF]292E. Copying Data 分块
- 获取JSON格式字符的处理
- 详解使用PHP CURL访问HTTPS
- ZOJ 1951 Goldbach's Conjecture(素数打表)
- 排序算法之一插入排序
- 模板类
- [IOS 消息提醒]--状态栏FDStatusBarNotifierView
- printf的几种格式
- nyoj 257 郁闷的C小加(一)