题目链接:http://codeforces.com/problemset/problem/438/D

给你n个数,m个操作,1操作是查询l到r之间的和,2操作是将l到r之间大于等于x的数xor于x,3操作是将下标为k的数变为x。

注意成段更新的时候,遇到一个区间的最大值还小于x的话就停止更新。

 #include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
typedef __int64 LL;
const int MAXN = 1e5 + ;
struct segtree {
int l , r;
LL sum , Min;
}T[MAXN << ];
LL res; void init(int p , int l , int r) {
int mid = (l + r) >> ;
T[p].l = l , T[p].r = r;
if(l == r) {
scanf("%I64d" , &T[p].sum);
T[p].Min = T[p].sum;
return ;
}
init(p << , l , mid);
init((p << )| , mid + , r);
T[p].sum = T[p << ].sum + T[(p << )|].sum;
T[p].Min = (T[p << ].Min > T[(p << )|].Min ? T[p << ].Min : T[(p << )|].Min);
} void updata(int p , int l , int r , LL x) {
int mid = (T[p].l + T[p].r) >> ;
if(T[p].Min < x) {
return ;
}
if(T[p].l == T[p].r) {
T[p].Min %= x;
T[p].sum %= x;
return ;
}
if(r <= mid) {
updata(p << , l , r , x);
}
else if(l > mid) {
updata((p << )| , l , r , x);
}
else {
updata(p << , l , mid , x);
updata((p << )| , mid + , r , x);
}
T[p].sum = T[p << ].sum + T[(p << )|].sum;
T[p].Min = (T[p << ].Min > T[(p << )|].Min ? T[p << ].Min : T[(p << )|].Min);
} void updata2(int p , int index , LL x) {
int mid = (T[p].l + T[p].r) >> ;
if(T[p].l == T[p].r && T[p].l == index) {
T[p].sum = T[p].Min = x;
return ;
}
if(index <= mid) {
updata2(p << , index , x);
}
else {
updata2((p << )| , index , x);
}
T[p].sum = T[p << ].sum + T[(p << )|].sum;
T[p].Min = (T[p << ].Min > T[(p << )|].Min ? T[p << ].Min : T[(p << )|].Min);
} void query(int p , int l , int r) {
int mid = (T[p].l + T[p].r) >> ;
if(l == T[p].l && T[p].r == r) {
res += (LL)T[p].sum;
return ;
}
if(r <= mid) {
query(p << , l , r);
}
else if(l > mid) {
query((p << )| , l , r);
}
else {
query(p << , l , mid);
query((p << )| , mid + , r);
}
} int main()
{
int n , m , l , r , c;
LL x;
scanf("%d %d" , &n , &m);
init( , , n);
while(m--) {
scanf("%d" , &c);
if(c == ) {
scanf("%d %d" , &l , &r);
res = ;
query( , l , r);
printf("%I64d\n" , res);
}
else if(c == ) {
scanf("%d %d %I64d" , &l , &r , &x);
updata( , l , r , x);
//cout << query(1 , 4 , 4) << endl;
}
else {
scanf("%d %I64d" , &l , &x);
updata2( , l , x);
}
}
}

Codeforces Round #250 (Div. 1) D. The Child and Sequence (线段树)的更多相关文章

  1. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间取摸

    D. The Child and Sequence Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest ...

  2. Codeforces Round #250 (Div. 1) D. The Child and Sequence 线段树 区间求和+点修改+区间取模

    D. The Child and Sequence   At the children's day, the child came to Picks's house, and messed his h ...

  3. Codeforces Round #250 (Div. 1) D. The Child and Sequence(线段树)

    D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input st ...

  4. Codeforces Round #250 (Div. 1) D. The Child and Sequence

    D. The Child and Sequence time limit per test 4 seconds memory limit per test 256 megabytes input st ...

  5. Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)

    题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...

  6. Codeforces Round #332 (Div. 2) C. Day at the Beach 线段树

    C. Day at the Beach Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/599/p ...

  7. Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)

    题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...

  8. Codeforces Round #225 (Div. 2) E. Propagating tree dfs序+-线段树

    题目链接:点击传送 E. Propagating tree time limit per test 2 seconds memory limit per test 256 megabytes inpu ...

  9. Codeforces Round #343 (Div. 2) D. Babaei and Birthday Cake 线段树维护dp

    D. Babaei and Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/D Description As you ...

随机推荐

  1. 新浪实时股票数据接口http://hq.sinajs.cn/list=code

    股票数据的获取目前有如下两种方法可以获取:1. http/javascript接口取数据2. web-service接口 1.http/javascript接口取数据1.1Sina股票数据接口以大秦铁 ...

  2. Git使用简介

    git创建分支并直接切换到分支:git checkout -b name git提交分支到远程服务器: git push origin name/git push origin name:name   ...

  3. Mac下安装HBase及详解

    Mac下安装HBase及详解 1. 千篇一律的HBase简介 HBase是Hadoop的数据库, 而Hive数据库的管理工具, HBase具有分布式, 可扩展及面向列存储的特点(基于谷歌BigTabl ...

  4. 8天学通MongoDB——第八天 驱动实践

    作为系列的最后一篇,得要说说C#驱动对mongodb的操作,目前驱动有两种:官方驱动和samus驱动,不过我个人还是喜欢后者, 因为提供了丰富的linq操作,相当方便. 官方驱动:https://gi ...

  5. [原创]Android中LocationManager的简单使用,获取当前位置

    Android中LocationManager的提供了一系列方法来地理位置相关的问题,包括查询上一个已知位置:注册/注销来自某个 LocationProvider的周期性的位置更新:以及注册/注销接近 ...

  6. .frm文件

    http://www.cnblogs.com/jiangxu67/p/4755097.html MySQL]frm文件解析 MySQL 协议字节序 关于传输整数小大端的实现 http://hamilt ...

  7. UVa 11997 (优先队列 多路归并) K Smallest Sums

    考虑一个简单的问题,两个长度为n的有序数组A和B,从每个数组中各选出一个数相加,共n2中情况,求最小的n个数. 将这n2个数拆成n个有序表: A1+B1≤A1+B2≤... A2+B1≤A2+B2≤. ...

  8. BestCoder Round #35

    A 题意:给出n个黑球,m个白球,每次取1个球,取了n+m次以后,会生成一个随机的01串S, 如果第i次取出的是黑球,则s[i]=1,如果是白色的,那么s[i]=0, 问01串在S中出现的期望次数 大 ...

  9. BZOJ2086: [Poi2010]Blocks

    题解: 想了想发现只需要求出最长的一段平均值>k即可. 平均值的问题给每个数减去k,判断是否连续的一段>0即可. 然后我们发现如果i<j 且 s[i]<s[j],那么 j 对于 ...

  10. HDU 3746 Cyclic Nacklace 环形项链(KMP,循环节)

    题意: 给一个字符串,问:要补多少个字符才能让其出现循环?出现循环是指循环节与字符串长度不相等.比如abc要补多个变成abcabc.若已经循环,输出0. 思路: 根据最小循环节的公式,当len%(le ...