题目链接: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. bzoj2800

    这题好难,翻了一下波兰文的题解……这好像是当年唯一没人A的题目 首先区间修改不难想到差分,我们令d1=x1,dn+1=-xn,di=xi-xi-1 注意Σdi=0,这样对于[l,r]的修改(比如+a) ...

  2. Java Web编程的主要组件技术——Struts入门

    参考书籍:<J2EE开源编程精要15讲> Struts是一个开源的Java Web框架,很好地实现了MVC设计模式.通过一个配置文件,把各个层面的应用组件联系起来,使组件在程序层面联系较少 ...

  3. HDU 2433 Travel (最短路,BFS,变形)

    题意: 给出一个图的所有边,每次从图中删除一条边,求任意点对的路径总和(求完了就将边给补回去).(有重边) 思路: #include <bits/stdc++.h> using names ...

  4. <六>面向对象分析之UML核心元素之业务实体

    一:基本概念

  5. IPy的使用

    IPy - class and tools for handling of IPv4 and IPv6 addresses and networks. Website: https://github. ...

  6. order by调优的一些测试

    表结构信息:mysql> show create table tb\G*************************** 1. row *************************** ...

  7. [Papers]NSE, $u_3$, Lebesgue space [NNP, QM, 2002; Zhou, JMPA, 2005]

    $$\bex u_3\in L^p(0,T;L^q(\bbR^3)),\quad \frac{2}{p}+\frac{3}{q}=\frac{1}{2},\quad 6< q\leq \inft ...

  8. HDU-4882 ZCC Loves Codefires

    http://acm.hdu.edu.cn/showproblem.php?pid=4882 ZCC Loves Codefires Time Limit: 2000/1000 MS (Java/Ot ...

  9. BLOCK 死循环

    __weak typeof(self) weakSelf = self; myObj.myBlock =  ^{     __strong typeof(self) strongSelf = weak ...

  10. OpenGL超级宝典第5版&&缓冲区

    缓冲区有很多用途:可以保存顶点数据,像素数据,纹理数据,着色器处理的输入,不同着色器阶段的输出. 缓冲区保存在GPU内存中,提供高速有效的访问.   像素缓冲区对象: GLuint pixBuffer ...