Codeforces Round #250 (Div. 1) D. The Child and Sequence (线段树)
题目链接: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 (线段树)的更多相关文章
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- Codeforces Round #271 (Div. 2) F. Ant colony (RMQ or 线段树)
题目链接:http://codeforces.com/contest/474/problem/F 题意简而言之就是问你区间l到r之间有多少个数能整除区间内除了这个数的其他的数,然后区间长度减去数的个数 ...
- 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 ...
- Codeforces Round #271 (Div. 2) F题 Ant colony(线段树)
题目地址:http://codeforces.com/contest/474/problem/F 由题意可知,最后能够留下来的一定是区间最小gcd. 那就转化成了该区间内与区间最小gcd数相等的个数. ...
- 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 ...
- 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 ...
随机推荐
- bzoj2351 2462
我没写hash,写了一些奇怪的做法,好像被hash随便操了…… 如果没有多测,那么这道题是白书上的例题 把询问矩阵当作a个模板串,建成一个ac自动机 把一开始的矩阵当作n个串放到自动机上匹配,找到a个 ...
- attachEvent,addEventListener事件绑定
兼容各主流浏览器的事件绑定(在同一个事件上添加多个处理函数). 1.绑定方法: //IE attachEvent(事件名, 函数) oBtn.attachEvent('onclick', aaa); ...
- JavaScript闭包示例
在下面的例子中,为什么点击所有的段落p输出都是5,而不是alert出对应的0,1,2,3,4. <html> <head> <meta charset="utf ...
- UVA 11806 Cheerleaders (容斥原理)
题意 一个n*m的区域内,放k个啦啦队员,第一行,最后一行,第一列,最后一列一定要放,一共有多少种方法. 思路 设A1表示第一行放,A2表示最后一行放,A3表示第一列放,A4表示最后一列放,则要求|A ...
- ti processor sdk linux am335x evm /bin/create-sdcard.sh hacking
#!/bin/bash # # ti processor sdk linux am335x evm /bin/create-sdcard.sh hacking # 说明: # 本文主要对TI的sdk中 ...
- UVA 10537 The Toll! Revisited 过路费(最短路,经典变形)
题意:给一个无向图,要从起点s运送一批货物到达终点e,每个点代表城镇/乡村,经过城镇需要留下(num+19)/20的货物,而经过乡村只需要1货物即可.现在如果要让p货物到达e,那么从起点出发最少要准备 ...
- Mac下开发常用目录
1:Snippets Xcode 代码段的文件表示 ~/Library/Developer/Xcode/UserData/CodeSnippets/ 2: Services 可以添加workf ...
- JavaScript备忘录-闭包
var arr = new Array(); function Person() { for (var i = 0; i < 10; i++) { //要记住,这个属性函数申明,只有立即执行才会 ...
- java AES加密算法
package com.siro.tools; import javax.crypto.Cipher;import javax.crypto.spec.IvParameterSpec;import j ...
- [转] C#操作EXCEL,生成图表的全面应用
gailzhao 原文 关于C#操作EXCEL,生成图表的全面应用 近来我在开发一个运用C#生成EXCEL文档的程序,其中要根据数据生成相应的图表,该图表对颜色和格式都有严格的要求,在百度和谷歌中搜索 ...