题意:

每次操作区间每个数进行一种(&或|、或^ )给定的一个数,到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(线段树延时标记)的更多相关文章

  1. FZU 2105 Digits Count(线段树)

    Problem 2105 Digits Count Accept: 302 Submit: 1477 Time Limit: 10000 mSec Memory Limit : 262144 KB P ...

  2. 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 ...

  3. ACM: FZU 2105 Digits Count - 位运算的线段树【黑科技福利】

     FZU 2105  Digits Count Time Limit:10000MS     Memory Limit:262144KB     64bit IO Format:%I64d & ...

  4. FZU 2105 Digits Count

     Problem 2105 Digits Count Accept: 444    Submit: 2139 Time Limit: 10000 mSec    Memory Limit : 2621 ...

  5. FZU 2105 Digits Count(按位维护线段树)

    [题目链接] http://acm.fzu.edu.cn/problem.php?pid=2105 [题目大意] 给出一个序列,数字均小于16,为正数,每次区间操作可以使得 1. [l,r]区间and ...

  6. FZU 2105 Digits Count(位数计算)

    Description 题目描述 Given N integers A={A[0],A[1],...,A[N-1]}. Here we have some operations: Operation ...

  7. POJ3468 A Simple Problem with Integers(线段树延时标记)

    题目地址http://poj.org/problem?id=3468 题目大意很简单,有两个操作,一个 Q a, b 查询区间[a, b]的和 C a, b, c让区间[a, b] 的每一个数+c 第 ...

  8. 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 ...

  9. 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- ...

随机推荐

  1. cocos2dx之C++调用Lua

    原文地址:http://blog.csdn.net/dingkun520wy/article/details/49839701 1.引入头文件 #include "cocos2d.h&quo ...

  2. [转载]iframe跨域

    最近做的一个项目中需要ajax跨域取得数据,如果是在本域中确实没有问题,但是放到二级域和其他域下浏览器直接就弹出提示框:“该页正在访问其控制范围之外的数据,这有些危险,是否继续" 1.什么引 ...

  3. [machine learning] Loss Function view

    [machine learning] Loss Function view 有关Loss Function(LF),只想说,终于写了 一.Loss Function 什么是Loss Function? ...

  4. 编写你的第一个 Django 程序 第1部分

    原地址:http://django-chinese-docs.readthedocs.org/en/latest/intro/tutorial01.html 让我们通过例子来学习. 在本教程中,我们将 ...

  5. 学习记录:浏览器JAVASCRIPT里的WINDOWS,DOCUMNET

    看完以下这段话之后,就理解DOCUMNET.READY之类的说法了. 或是JAVASCRIPT的浏览器里更细致的操作DOCUMENT的东西了. DOCUMNET和WINDOWS谁大谁小, 立即执行的匿 ...

  6. 怎样配置spring aop

    1.spring aop配置如下: 1.aspect切面是一个具体类,里面包含各种执行的通知方法.切面类也要注册到ioc容器中. 2.切入点pointcut,可以在每个通知里单独配置,即每个通知可以指 ...

  7. SQLite入门与分析(二)---设计与概念

    写在前面:谢谢各位的关注,没想到会有这么多人关注.高兴的同时,也感到压力,因为我接触SQLite也就几天,也没在实际开发中用过,只是最近项目的需求才来研究它,所以我很担心自己的文章是否会有错误,误导别 ...

  8. C++创建一个动态链接库工程

    前话 在我们安装一些软件时,进入软件安装目录会经常看到.dll格式文件,系统system目录也存在许多dll文件 在软件游戏(window平台)更新的时候,很大部分是下载dll文件 所以会好奇这是什么 ...

  9. *IntelliJ IDEA配置Hibernate

    为IntelliJ IDEA安装Hibernate插件

  10. POJ3295——Tautology

    Tautology Description WFF 'N PROOF is a logic game played with dice. Each die has six faces represen ...