FZU 2105-Digits Count(线段树延时标记)
题意:
每次操作区间每个数进行一种(&或|、或^ )给定的一个数,到sum时统计给定区间的和。
分析:
这个题让我觉得我的思维很不活跃,对懒惰标记理解,还远远不够,通过这道题我对懒惰标记加深了不少。
经过各种操作和区间会变成相同数都相邻的情况,若在操作会变成另一个相同数。
选区间内相同数字为懒惰标记进行更新。
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<1|1
#define All 1,N,1
#define N 1000100
#define read freopen("in.txt", "r", stdin)
const ll INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod = ;
int same[N*],n,q,a[N];
void pushup(int rt){
if(same[rt<<]==same[rt<<|]&&same[rt<<]!=-){
same[rt]=same[rt<<];
}
}
void pushdown(int rt){
if(same[rt]!=-){
same[rt<<]=same[rt<<|]=same[rt];
same[rt]=-;
}
}
void build(int l,int r,int rt){
same[rt]=-;
if(l==r){
same[rt]=a[l];
return;
}
int m=(l+r)>>;
build(lson);
build(rson);
pushup(rt);
}
void update(int op,int opn,int L,int R,int l,int r,int rt){
if(L<=l&&R>=r&&same[rt]!=-){
if(op==)
same[rt]&=opn;
else if(op==)
same[rt]|=opn;
else
same[rt]^=opn;
return;
}
pushdown(rt);
int m=(l+r)>>;
if(L<=m)update(op,opn,L,R,lson);
if(R>m)update(op,opn,L,R,rson);
pushup(rt);
}
int query(int L,int R,int l,int r,int rt){
if(L<=l&&R>=r&&same[rt]!=-){
return (r-l+)*same[rt];
}
pushdown(rt);
int num=;
int m=(l+r)>>;
if(L<=m)num+=query(L,R,lson);
if(R>m)num+=query(L,R,rson);
pushup(rt);
return num;
}
int main()
{
int t;
scanf("%d",&t);
char ans[];
while(t--){
scanf("%d%d",&n,&q);
for(int i=;i<=n;++i)
scanf("%d",&a[i]);
build(,n,);
int x,y,p;
while(q--){
scanf("%s",ans);
if(ans[]=='A'){
scanf("%d%d%d",&p,&x,&y);
update(,p,x+,y+,,n,);
}
else if(ans[]=='O'){
scanf("%d%d%d",&p,&x,&y);
update(,p,x+,y+,,n,);
}
else if(ans[]=='X'){
scanf("%d%d%d",&p,&x,&y);
update(,p,x+,y+,,n,);
}
else{
scanf("%d%d",&x,&y);
printf("%d\n",query(x+,y+,,n,));
}
}
}
return ;
}
FZU 2105-Digits Count(线段树延时标记)的更多相关文章
- FZU 2105 Digits Count(线段树)
Problem 2105 Digits Count Accept: 302 Submit: 1477 Time Limit: 10000 mSec Memory Limit : 262144 KB P ...
- fzu 2105 Digits Count ( 线段树 ) from 第三届福建省大学生程序设计竞赛
http://acm.fzu.edu.cn/problem.php?pid=2105 Problem Description Given N integers A={A[0],A[1],...,A[N ...
- ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】
FZU 2105 Digits Count Time Limit:10000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
- FZU 2105 Digits Count
Problem 2105 Digits Count Accept: 444 Submit: 2139 Time Limit: 10000 mSec Memory Limit : 2621 ...
- FZU 2105 Digits Count(按位维护线段树)
[题目链接] http://acm.fzu.edu.cn/problem.php?pid=2105 [题目大意] 给出一个序列,数字均小于16,为正数,每次区间操作可以使得 1. [l,r]区间and ...
- FZU 2105 Digits Count(位数计算)
Description 题目描述 Given N integers A={A[0],A[1],...,A[N-1]}. Here we have some operations: Operation ...
- POJ3468 A Simple Problem with Integers(线段树延时标记)
题目地址http://poj.org/problem?id=3468 题目大意很简单,有两个操作,一个 Q a, b 查询区间[a, b]的和 C a, b, c让区间[a, b] 的每一个数+c 第 ...
- Codeforces Round #312 (Div. 2) E. A Simple Task 线段树 延时标记
E. A Simple Task time limit per test5 seconds memory limit per test512 megabytes inputstandard input ...
- hdu-3397 Sequence operation 线段树多种标记
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3397 题目大意: 0 a b表示a-b区间置为0 1 a b表示a-b区间置为1 2 a b表示a- ...
随机推荐
- Unity3d之Http通讯GET方法和POST方法
(一)GET方法 IEnumerator SendGet(string _url) { WWW getData = new WWW(_url); yield return getData; if(ge ...
- 一个有意思的js实例,你会吗??[原创]
首先,看看下面一个js例子,你觉得会输出什么呢? function fn(a){ a(); function a(){ console.log(2); } var a = function(){ co ...
- 机器学习基石的泛化理论及VC维部分整理(第六讲)
第六讲 第五讲主要讲了机器学习可能性,两个问题,(1)\(E_{in} 要和 E_{out}\) 有很接近,(2)\(E_{in}\)要足够小. 对于第一个假设,根据Hoefding's Inequa ...
- 然爸读书笔记(2013-5)----Rework(重来)
(1)你没有必要耗尽你一生的积蓄,承担财务风险. (2)你可以一边继续日常工作,一边开始创业,这样随时都能有现金满足需要.你甚至不需要办公室. 现在可以在家工作,和从未见面离你千里之外的人合作. (3 ...
- 1015: [JSOI2008]星球大战starwar - BZOJ
Description 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治者整个星系.某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝国的超级武器,并攻下了星系中几乎所有的星球.这些星球通过 ...
- 解决服务器断电导致mysql数据库无法启动
1.找到mysql数据库目录下的*.ini这个配置文件2.复制配置文件到桌面,当作备份3.打开配置文件,在配置文件里加上innodb_force_recovery=6这句,保存,然后重启服务器4重启完 ...
- java、js的编码、解码
如果在地址栏挂载参数,特别是包含中文,往往要进行编码,取值时再解码,以下是java和js中编码.解码的各自方法. java: @Test public void test3() throws Unsu ...
- Spring 声明式事务,propagation属性列表及isolation(隔离级别)
Spring 声明式事务,propagation属性列表 TransactionDefinition接口中定义,共有7种选项可用: PROPAGATION_REQUIRED:支持当前事务,如果当前没有 ...
- [转载]jquery获取元素索引值index()方法:
jquery的index()方法 搜索匹配的元素,并返回相应元素的索引值,从0开始计数. 如果不给 .index() 方法传递参数,那么返回值就是这个jQuery对象集合中第一个元素相对于其同辈元素的 ...
- windows8 64位 IIS8 PHP5.5 安装 Imagemagick 组件
为什么这里一定要说 windows 系统是64位呢,因为如果是系统是64位,那么PHP5.5 一般都会选择64的, Imagemagick 组件也会选择64位的, 但是操蛋的是 64位的Imagema ...