UESTC--1730
原题链接:http://acm.uestc.edu.cn/problem.php?pid=1730
分析:线段树单点更新,区间求和。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#define maxn 500005
#define mod 1000007
using namespace std;
int sum[maxn<<];
int x[maxn];
void build(int l,int r,int rt)
{
if(l==r)
{
sum[rt]=x[l];
return;
}
int m=(l+r)>>;
build(l,m,rt<<);
build(m+,r,rt<<|);
sum[rt]=sum[rt<<]^sum[rt<<|];
}
void update(int l,int r,int rt,int ii,int v)
{
if(l==r&&l==ii){
sum[rt]=v;
return;
}
int m=(l+r)>>;
if(ii<=m)update(l,m,rt<<,ii,v);
else update(m+,r,rt<<|,ii,v);
sum[rt]=sum[rt<<]^sum[rt<<|];
}
int get_sum(int L,int R,int l,int r,int rt)
{
if(L<=l&&r<=R)return sum[rt];
int m=(l+r)>>;
int res=;
if(L<=m)res^=get_sum(L,R,l,m,rt<<);
if(R>=m+)res^=get_sum(L,R,m+,r,rt<<|);
return res;
}
int main()
{
int n,m;
cin>>n>>m;
for(int i=;i<=n;i++)
scanf("%d",&x[i]);
build(,n,);
int i,j;char op[];
while(m--)
{
scanf("%s %d %d",op,&i,&j);
if(op[]=='Q')
{
printf("%d\n",get_sum(i,j,,n,));
}
else update(,n,,i,j);
}
return ;
}
UESTC--1730的更多相关文章
- ACM:UESTC - 649 括号配对问题 - stack
UESTC - 649 括号配对问题 Time Limit: 1000MS Memory Limit: 65535KB 64bit IO Format: %lld & %llu ...
- UESTC 1015 Lweb and pepper --前,后缀最值
题意: n种食物,每种含花椒的概率为Pi,现在已经选择了[L,R]这个区间(下标)的食物,要再选一个,使总的食物只有一种含花椒的概率最大,问选哪个最好,相同的选下标小的. 解法: 就不写解法了.此处有 ...
- UESTC 1852 Traveling Cellsperson
找规律水题... Traveling Cellsperson Time Limit: 1000ms Memory Limit: 65535KB This problem will be judged ...
- UESTC 1851 Kings on a Chessboard
状压DP... Kings on a Chessboard Time Limit: 10000ms Memory Limit: 65535KB This problem will be judged ...
- UESTC 30 最短路,floyd,水
最短路 Time Limit: 3000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Submit Statu ...
- uestc oj 1218 Pick The Sticks (01背包变形)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1218 给出n根木棒的长度和价值,最多可以装在一个长 l 的容器中,相邻木棒之间不允许重叠,且两边上的木棒,可 ...
- uestc oj 1217 The Battle of Chibi (dp + 离散化 + 树状数组)
题目链接:http://acm.uestc.edu.cn/#/problem/show/1217 给你一个长为n的数组,问你有多少个长度严格为m的上升子序列. dp[i][j]表示以a[i]结尾长为j ...
- bzoj 3196 Tyvj 1730 二逼平衡树(线段树套名次树)
3196: Tyvj 1730 二逼平衡树 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1807 Solved: 772[Submit][Stat ...
- 2015 CCPC D- Pick The Sticks(UESTC 1218) (01背包变形)
http://acm.uestc.edu.cn/#/problem/show/1218 既然二维dp表示不了,就加一维表示是否在边界放置,放置一个,两个.有一个trick就是如果只放一根,那么多长都可 ...
- 2015 CCPC-C-The Battle of Chibi (UESTC 1217)(动态规划+树状数组)
赛后当天学长就说了树状数组,结果在一个星期后赖床时才有了一点点思路…… 因为无法提交,不确定是否正确..嗯..有错希望指出,谢谢... 嗯..已经A了..提交地址http://acm.uestc.ed ...
随机推荐
- leetcode个人题解——#49 Group Anograms
思路:利用c++ stl的map来实现关键字匹配, 遍历strs容器类,对其中每一个string进行按字典序排序后,查找是否存在这样一个键,如不存在,存储该键,并将str[i]作为键映射的第一个元素: ...
- hibernate.hbm.xml文件配置入门小结(1)
在Hibernate中,各表的映射文件xxx.hbm.xml可以通过工具生成,例如在使用MyEclipse开发时,它提供了自动生成映射文件的工具. hibernate.hbm.xml文件的基本结构如下 ...
- 3.openldap生成LDAP用户
1.用migrationtools生成用户 #yum install migrationtools -y #vim /usr/share/migrationtools/migrate_common.p ...
- Python坑系列:可变对象与不可变对象
在之前的文章 http://www.cnblogs.com/bitpeng/p/4748148.html 中,大家看到了ret.append(path) 和ret.append(path[:])的巨大 ...
- LeetCode 206. Reverse Linked List(C++)
题目: Reverse a singly linked list. Example: Input: 1->2->3->4->5->NULL Output: 5->4 ...
- rsyslog配置文件详解(rsyslog.conf)
# rsyslog configuration file # For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html # ...
- iOS界面设计之基础控件的学习 --- UITextField
学习iOS界面设计也有段时间了,每次写到一些基础控件(如:UILable . UITextField)的时候就深觉应该总结一个函数来实现这些基础控件的属性设置,所以下面就是我对UITextField的 ...
- 【beta】Scrum站立会议第7次....11.9
小组名称:nice! 组长:李权 成员:于淼 刘芳芳韩媛媛 宫丽君 项目内容:约跑app(约吧) 时间:2016.11.9 12:00——12:30 地点:传媒西楼220室 本次对beta阶段 ...
- Android自定义XML属性以及遇到的命名空间的问题
转载请注明出处:http://www.cnblogs.com/kross/p/3458068.html 最近在做一些UI,很蠢很蠢的重复写了很多代码,比如一个自定义的UI Tab,由一个ImageVi ...
- json 和 pickle
用于序列化的两个模块 json:用于字符串和python数据类型间进行转换 pickle:用于python特有的类型和python的数据类型间进行转换 json模块提供了四个功能:dumps dump ...