Codeforces Round #197 (Div. 2)(d线段树)
2014-03-09 09:50
260 查看
A - Helpful Maths
水题不多说
B - Xenia and Ringroad
明白题意明白了半天。。。
D - Xenia and Bit Operations
题意:从最后一层开始进行或运算,然后是异或,间断进行,然后修改某些点,问最后运算完后的那个数
思路:简单线段树
水题不多说
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<string> using namespace std; int main() { int a[105],n=0; string s; cin>>s; for(int i=0;i<s.size();i++) if(s[i]!='+')a[n++]=s[i]-'0'; sort(a,a+n); for(int i=0;i<n;i++) if(i!=n-1)cout<<a[i]<<"+"; else cout<<a[i]; return 0; }
B - Xenia and Ringroad
明白题意明白了半天。。。
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<string> using namespace std; int main() { long long n,m,x=1,now; long long sum=0; cin>>n>>m; for(int i=0;i<m;i++) { cin>>now; if(now<x)sum+=n+now-x; else sum+=now-x; x=now; } cout<<sum<<endl; return 0; }
D - Xenia and Bit Operations
题意:从最后一层开始进行或运算,然后是异或,间断进行,然后修改某些点,问最后运算完后的那个数
思路:简单线段树
#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int maxn=(1<<17); struct node { int l,r,num; }tree[maxn*4]; int a[maxn]; int n,m; void build(int o,int l,int r,int dep) { tree[o].l=l,tree[o].r=r; if(l==r){tree[o].num=a[l];return;} int mid=(l+r)/2; build(o*2,l,mid,dep-1); build(o*2+1,mid+1,r,dep-1); if(dep%2==1)tree[o].num=(tree[o*2].num|tree[o*2+1].num); else tree[o].num=(tree[o*2].num^tree[o*2+1].num); } void update(int pos,int x,int o,int l,int r,int dep) { if(l==r){tree[o].num=x;return;} int mid=(l+r)/2; if(pos<=mid)update(pos,x,o*2,l,mid,dep-1); else update(pos,x,o*2+1,mid+1,r,dep-1); if(dep%2==1) tree[o].num=(tree[o*2].num|tree[o*2+1].num); else tree[o].num=(tree[o*2].num^tree[o*2+1].num); } int main() { scanf("%d%d",&n,&m); for(int i=1;i<=(1<<n);i++) scanf("%d",&a[i]); build(1,1,1<<n,n); int pos,x; while(m--) { scanf("%d%d",&pos,&x); update(pos,x,1,1,(1<<n),n); printf("%d\n",tree[1].num); } return 0; }
相关文章推荐
- Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations - 线段树
- Codeforces Round #FF (Div. 2)__E. DZY Loves Fibonacci Numbers (CF447) 线段树
- Codeforces Round #271 (Div. 2) E. Pillars 线段树优化dp
- Codeforces Round #174 (Div. 2) Cows and Sequence(线段树)
- Codeforces Round #381 (Div. 1) C. Alyona and towers(线段树)
- Codeforces Round #222 (Div. 1) D. Developing Game 线段树有效区间合并
- Codeforces Round #179 (Div. 1) A题 线段树
- 【Codeforces Round 370 (Div 2) E】【线段树 等比数列 区间合并】Memory and Casinos 赌场区间[l,r] l进r先出的概率
- 线段树(待续)(区间每个数加上不同的斐波那契额数)Codeforces Round #FF (Div. 2)E
- Codeforces Round #200 (Div. 1) (树上的线段树)
- Codeforces Round #FF (Div. 2)E(线段树成段更新)
- 【Codeforces Round 333 (Div 2)D】【线段树 or ST-RMQ 初始化78msAC】Lipshitz Sequence 若干区间询问所有子区间的答案和
- Codeforces Round #197 (Div. 2) : A
- Codeforces Round #197 (Div. 2) (C~E)
- Codeforces Round #141 (Div. 2), problem: (D) Zigzag 线段树 整形变量注意溢出控制
- Codeforces Beta Round #75 (Div. 1 Only) B. Queue 线段树。单点更新
- Codeforces Round #225 (Div. 2)---E. Propagating tree(时间戳+线段树)
- Codeforces Round #343 (Div. 2) 629D. Babaei and Birthday Cake 线段树
- Codeforces Round #271 (Div. 2) F. Ant colony(线段树)
- 【Codeforces Round 271 (Div 2)E】【离散化线段树】Pillars 最长连续序列使得序列相邻的数差值至少为k