CodeVs——T 4919 线段树练习4
给你N个数,有两种操作
1:给区间[a,b]内的所有数都增加X
2:询问区间[a,b]能被7整除的个数
第一行一个正整数n,接下来n行n个整数,再接下来一个正整数Q,表示操作的个数. 接下来Q行每行若干个整数。如果第一个数是add,后接3个正整数a,b,X,表示在区间[a,b]内每个数增加X,如果是count,表示统计区间[a,b]能被7整除的个数
对于每个询问输出一行一个答案
3
2 3 4
6
count 1 3
count 1 2
add 1 3 2
count 1 3
add 1 3 3
count 1 3
0
0
0
1
10%:1<N<=10,1<Q<=10
30%:1<N<=10000,1<Q<=10000
100%:1<N<=100000,1<Q<=100000
#include <algorithm>
#include <cstdio> using namespace std; const int N(+);
int n,x,y,z,q; #define lc (now<<1)
#define rc (now<<1|1)
#define mid (l+r>>1)
struct AC_Tree
{
int val[],flag;
}tree[N<<];
inline void pushup(int now)
{
for(int i=;i<;i++)
tree[now].val[i]=tree[lc].val[i]+tree[rc].val[i];
}
inline void pushdown(int now)
{
int temp[],flag=tree[now].flag; tree[now].flag=;
tree[lc].flag+=flag; tree[rc].flag+=flag;
for(int i=;i<;i++) temp[i]=tree[lc].val[i];
for(int i=;i<;i++) tree[lc].val[((i+flag)%)]=temp[i];
for(int i=;i<;i++) temp[i]=tree[rc].val[i];
for(int i=;i<;i++) tree[rc].val[((i+flag)%)]=temp[i];
}
void Build(int now,int l,int r)
{
if(l==r)
{
scanf("%d",&x);
tree[now].val[x%]++;
return ;
}
Build(lc,l,mid);
Build(rc,mid+,r);
pushup(now);
}
void Change(int now,int l,int r,int L,int R,int x)
{
if(l==L&&r==R)
{
int temp[];
tree[now].flag+=x;
for(int i=;i<;i++) temp[i]=tree[now].val[i];
for(int i=;i<;i++) tree[now].val[(i+x)%]=temp[i];
return ;
}
if(tree[now].flag) pushdown(now);
if(R<=mid) Change(lc,l,mid,L,R,x);
else if(L>mid) Change(rc,mid+,r,L,R,x);
else Change(lc,l,mid,L,mid,x),Change(rc,mid+,r,mid+,R,x);
pushup(now);
}
int Query(int now,int l,int r,int L,int R)
{
if(l==L&&r==R) return tree[now].val[];
if(tree[now].flag) pushdown(now);
if(R<=mid) return Query(lc,l,mid,L,R);
else if(L>mid) return Query(rc,mid+,r,L,R);
else return Query(lc,l,mid,L,mid)+Query(rc,mid+,r,mid+,R);
} int main()
{
scanf("%d",&n);
Build(,,n);
scanf("%d",&q);
for(char s[];q--;)
{
scanf("%s%d%d",s,&x,&y);
if(s[]=='a')
{
scanf("%d",&z);
Change(,,n,x,y,z);
}
else printf("%d\n",Query(,,n,x,y));
}
return ;
}
CodeVs——T 4919 线段树练习4的更多相关文章
- codevs 4919 线段树练习4
线段树水题.我是ziliuziliu,我是最强的#include<iostream> #include<cstdio> #include<cstring> #inc ...
- 4163 hzwer与逆序对 (codevs + 权值线段树 + 求逆序对)
题目链接:http://codevs.cn/problem/4163/ 题目:
- codevs 1690 开关灯 线段树+延迟标记
1690 开关灯 时间限制: 1 s 空间限制: 128000 KB 题目描述 Description YYX家门前的街上有N(2<=N<=100000)盏路灯,在晚上六点之前,这 ...
- codevs 1690 开关灯 线段树区间更新 区间查询Lazy
题目描述 Description YYX家门前的街上有N(2<=N<=100000)盏路灯,在晚上六点之前,这些路灯全是关着的,六点之后,会有M(2<=m<=100000)个人 ...
- Codevs 4373 窗口(线段树 单调队列 st表)
4373 窗口 时间限制: 1 s 空间限制: 256000 KB 题目等级 : 黄金 Gold 题目描述 Description 给你一个长度为N的数组,一个长为K的滑动的窗体从最左移至最右端,你只 ...
- 【codevs】1082 线段树练习 3 <区间修改+区间和>
题目连接 http://codevs.cn/problem/1082/ Description 给你N个数,有两种操作: 1:给区间[a,b]的所有数增加X 2:询问区间[a,b]的数的和. In ...
- COdeVS——T 1082 线段树练习 3 (分块练习)
http://codevs.cn/problem/1082/ 时间限制: 3 s 空间限制: 128000 KB 题目等级 : 大师 Master 题解 题目描述 Descriptio ...
- codevs 1690 开关灯 线段树水题
没什么好说的,标记put表示开关是否开着. #include<cstdio> #include<cstring> #include<algorithm> using ...
- AC日记——线段树练习4 codevs 4919
4919 线段树练习4 时间限制: 1 s 空间限制: 128000 KB 题目等级 : 黄金 Gold 题解 查看运行结果 题目描述 Description 给你N个数,有两种操作 ...
随机推荐
- vue 常用ui组件库
vux github ui demo:https://github.com/airyland/vux Mint UI 项目主页:http://mint-ui.github.io/#!/zh-cn de ...
- Cocos2d-x怎样控制动作速度
基本动作和组合动作实现了针对精灵的各种运动和动画效果的改变.但这种改变速度匀速的.线性的.通过ActionEase及其的派生类和Speed 类我们能够使精灵以非匀速或非线性速度运动,这样看起了效果更加 ...
- leetcode: Maximum Depth of Binary Tree
Given a binary tree, find its maximum depth. The maximum depth is the number of nodes along the long ...
- 9.9递归和动态规划(六)——打印n对括号的所有有效组合(即左右括号正确配对)
/** * 功能:打印n对括号的所有有效组合(即左右括号正确配对). */ 两种方法: 方法一: /** * 思路:在括号的最前面或者原有的每对括号中面插入一对括号. 至于其它任何位置.比方字符串的 ...
- jquery2.0.3 全部源码
/*! * Includes Sizzle.js 选择器,独立的库 * http://sizzlejs.com/ */ (function( window, undefined ) { //" ...
- android framework 02
Android底层开发1.安装Ubuntu系统2.Ubuntu配置开发环境: sudo apt-get install git-core gnupg flex bison gperf zip sudo ...
- 45. Express 框架 静态文件处理
转自:http://www.runoob.com/nodejs/nodejs-express-framework.html Express 提供了内置的中间件 express.static 来设置静态 ...
- 浏览器加载渲染HTML、DOM、CSS、 JAVASCRIPT、IMAGE、FLASH、IFRAME、SRC属性等资源的顺序总结
页面响应加载的顺序: 1.域名解析->加载html->加载js和css->加载图片等其他信息 DOM详细的步骤如下: 解析HTML结构. 加载外部脚本和样式表文件. 解析并执行脚 ...
- linux环境下禅道搭建
1.下载禅道安装包,根据操作系统的版本: 2.上传包到linux的opt目录中: 3.解压包: cd /opt tar xzvf 禅道包名称,如:tar xzvf ZenTaoPMS.8.1.3.zb ...
- 自己增删改查Razor页面
AccountContext db = new AccountContext(); public ActionResult Index() { return View(db.SysUsers); } ...