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- ...
随机推荐
- 【BZOJ 3098】 Hash Killer II
Description 这天天气不错,hzhwcmhf神犇给VFleaKing出了一道题:给你一个长度为N的字符串S,求有多少个不同的长度为L的子串.子串的定义是S[l].S[l + 1].... S ...
- 【BZOJ 2878】 [Noi2012]迷失游乐园
Description 放假了,小Z觉得呆在家里特别无聊,于是决定一个人去游乐园玩.进入游乐园后,小Z看了看游乐园的地图,发现可以将游乐园抽象成有n个景点.m条道路的无向连通图,且该图中至多有一个环( ...
- 在openwrt上初体验PostgreSQL数据库
要求 请确保在你的路由器shell 中有以下这些命令 adduser, deluser, addgroup, delgroup, su . 还需要熟悉su,chown ,opkg,mkdir,服务操作 ...
- c#用反射原理递归遍历复杂实体对象
之前在网上看到的都是遍历那种比较简单的实体对象,但是如果有实体嵌套,甚至是包含有List<XXInfo>这种属性的时候就没有办法处理了.通过递归遍历的方式可以完成对复杂实体对象的所有属性的 ...
- BZOJ 1589: [Usaco2008 Dec]Trick or Treat on the Farm 采集糖果
Description 每年万圣节,威斯康星的奶牛们都要打扮一番,出门在农场的N(1≤N≤100000)个牛棚里转悠,来采集糖果.她们每走到一个未曾经过的牛棚,就会采集这个棚里的1颗糖果. 农场不大, ...
- 利用手上的UI资源(附免费UI工具包)
http://www.uisdc.com/how-to-use-ui-kits# 大家都知道,UI工具包里有很多好看的资源:比如按钮.滑块.面包屑.播放器.表单,甚至是一个"赞!" ...
- PE 文件
一.PE文件基本结构 上图便是PE文件的基本结构.(注意:DOS MZ Header和部分PE header的大小是不变的:DOS stub部分的大小是可变的.) 二.Section 详解 一个PE文 ...
- (转)基于即时通信和LBS技术的位置感知服务(一):提出问题及解决方案
一.前言.提出问题 公司最近举行2011年度创新设计大赛,快年底了正打算写写2010年以来Android开发的心得与经验,正好同事出了个点子:假如A和B两个人分别在不同的地点,能不能实现这样的功能,让 ...
- Akka Stream文档翻译:Quick Start Guide: Reactive Tweets
Quick Start Guide: Reactive Tweets 快速入门指南: Reactive Tweets (reactive tweets 大概可以理解为“响应式推文”,在此可以测试下GF ...
- android 在一个scrollView里面嵌套一个需要滑动的控件(listView、gridView)
package cn.via.dageeeOrderFood.widget; import android.content.Context; import android.graphics.Point ...