开了个小号做,C题一开始看错范围,D题看了半小时才看懂,居然也升到了div1,囧。

C - Xenia and Weights

给出一串字符串,第i位如果是1的话,表示有重量为i的砝码,如果有该种砝码的话,数量有无限多个。

现在往天平的两侧放入,每次放入的要求:

1.每次放入时和上次放入的砝码的重量不能一样。

2.放入的那端天平必须必另一端重。

问能否放入n次,能的话,求放入方式。

分析:

  比赛时看到很多人写的是贪心,但是想不到有什么好的数据叉掉他们,囧。

  我写的是直接dfs爆搜。代码略吧。

D - Xenia and Bit Operations

这题挺有意思的。只不过比赛时纠结了半个小时的题意,看懂了之后也秒出了。

题目大意:

给出一个原始数列a[1]...a[2^n]。

V值的定义如下:

第一次时,第2*i项与第2*i-1项位或,剩余2^(n-1)项。

第二次时,第2*i项与第2*i-1项异或,剩余2^(n-2)项。

。。。

异或和位或相隔操作。

现在给出n组操作:

把a[p]项变为b,求变化之后的V值。

分析:我们考虑变化的a[p]项,考虑他可能会影响的部分,这时发现其实可以构造一棵线段树,修改p节点时直接从叶子节点往上一直到根节点,同时相应的进行更新操作即可。

#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm> using namespace std; typedef long long ll;
typedef unsigned long long ull; #define debug puts("here")
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define REP(i,a,b) for(int i=a;i<=b;i++)
#define foreach(i,vec) for(unsigned i=0;i<vec.size();i++)
#define pb push_back
#define RD(n) scanf("%d",&n)
#define RD2(x,y) scanf("%d%d",&x,&y)
#define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define RD4(x,y,z,w) scanf("%d%d%d%d",&x,&y,&z,&w)
#define All(vec) vec.begin(),vec.end()
#define MP make_pair
#define PII pair<int,int>
#define PQ priority_queue
#define cmax(x,y) x = max(x,y)
#define cmin(x,y) x = min(x,y)
#define Clear(x) memset(x,0,sizeof(x))
/* #pragma comment(linker, "/STACK:1024000000,1024000000") int size = 256 << 20; // 256MB
char *p = (char*)malloc(size) + size;
__asm__("movl %0, %%esp\n" :: "r"(p) ); */ /******** program ********************/ const int MAXN = 2e5+5; struct segTree{
int l,r,val;
inline int mid(){
return (l+r)>>1;
}
}tree[MAXN<<2];
int a[MAXN]; void update(int rt,int ok){
if(ok)
tree[rt].val = tree[rt<<1].val | tree[rt<<1|1].val;
else
tree[rt].val = tree[rt<<1].val ^ tree[rt<<1|1].val;
} void build(int l,int r,int rt,int ok){
tree[rt].l = l;
tree[rt].r = r;
if(l==r){
tree[rt].val = a[l];
return;
}
int mid = tree[rt].mid();
build(l,mid,rt<<1,ok^1);
build(mid+1,r,rt<<1|1,ok^1); update(rt,ok);
} void modify(int pos,int c,int rt,int ok){
if(tree[rt].l==tree[rt].r){
tree[rt].val = c;
return;
}
int mid = tree[rt].mid();
if(pos<=mid)modify(pos,c,rt<<1,ok^1);
else modify(pos,c,rt<<1|1,ok^1);
update(rt,ok);
} int main(){ #ifndef ONLINE_JUDGE
freopen("sum.in","r",stdin);
//freopen("sum.out","w",stdout);
#endif int n,m,t;
while(cin>>t>>m){
n = 1<<t;
rep1(i,n)
RD(a[i]);
build(1,n,1,t&1);
int p,x;
while(m--){
RD2(p,x);
modify(p,x,1,t&1);
printf("%d\n",tree[1].val);
}
} return 0;
}

  

Codeforces Round #197 (Div. 2) C,D两题的更多相关文章

  1. 线段树 Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    题目传送门 /* 线段树的单点更新:有一个交叉更新,若rank=1,or:rank=0,xor 详细解释:http://www.xuebuyuan.com/1154895.html */ #inclu ...

  2. Codeforces Round #524 (Div. 2)(前三题题解)

    这场比赛手速场+数学场,像我这样读题都读不大懂的蒟蒻表示呵呵呵. 第四题搞了半天,大概想出来了,但来不及(中途家里网炸了)查错,于是我交了两次丢了100分.幸亏这次没有掉rating. 比赛传送门:h ...

  3. Codeforces Round #197 (Div. 2) : E

    看了codeforces上的大神写的题解之后,才知道这道题水的根本! 不过相对前面两题来说,这道题的思维要难一点: 不过想到了水的根本,这题也真心不难: 方法嘛,就像剥洋葱一样,从外面往里面剥: 所以 ...

  4. [置顶] Codeforces Round #197 (Div. 2)(完全)

    http://codeforces.com/contest/339/ 这场正是水题大放送,在家晚上限制,赛后做了虚拟比赛 A,B 乱搞水题 C 我是贪心过的,枚举一下第一个拿的,然后选使差值最小的那个 ...

  5. Codeforces Round #197 (Div. 2) (A、B、C、D、E五题合集)

    A. Helpful Maths 题目大意 给一个连加计算式,只包含数字 1.2.3,要求重新排序,使得连加的数字从小到大 做法分析 把所有的数字记录下来,从小到大排序输出即可 参考代码 #inclu ...

  6. Codeforces Round #197 (Div. 2) D. Xenia and Bit Operations

    D. Xenia and Bit Operations time limit per test 2 seconds memory limit per test 256 megabytes input ...

  7. Codeforces Round #197 (Div. 2)

    A.Helpful Maths 分析:将读入的字符转化为数字,直接排个序就可以了. #include <cstdlib> #include <cstring> #include ...

  8. Codeforces Round #197 (Div. 2) : C

    哎....这次的比赛被安叔骂的好惨! 不行呢,要虐回来: 这道搜索,老是写错,蛋疼啊! 果然是基础没打好! #include<cstdio> using namespace std; ], ...

  9. Codeforces Round #197 (Div. 2) : D

    这题也是一个线段树的水题: 不过开始题目没看明白,害得我敲了一个好复杂的程序.蛋疼啊.... 最后十几分钟的时候突然领悟到了题意,但是还是漏掉一个细节,老是过不去... 以后比赛的时候不喝啤酒了,再也 ...

随机推荐

  1. 学习C++的一些问题总结

    C++ 问题 (一) int main() { int i,j,m,n; i=8; j=10; m=++i+j++;  //++i是先递加再使用,j++是先使用再递加,故:9+10=19 n=++i+ ...

  2. EasyMock 使用方法与原理剖析

    from:http://www.ibm.com/developerworks/cn/opensource/os-cn-easymock/ Mock 方法是单元测试中常见的一种技术,它的主要作用是模拟一 ...

  3. Binary Search

    Binary Search                              [原文见:http://www.topcoder.com/tc?module=Static&d1=tuto ...

  4. Java常见排序算法之归并排序

    在学习算法的过程中,我们难免会接触很多和排序相关的算法.总而言之,对于任何编程人员来说,基本的排序算法是必须要掌握的. 从今天开始,我们将要进行基本的排序算法的讲解.Are you ready?Let ...

  5. jQuery hover事件鼠标滑过图片半透明标题文字滑动显示隐藏

    1.效果及功能说明 hover事件制作产品图片鼠标滑过图片半透明,标题文字从左到右滑动动画移动显示隐藏 2.实现原理 首先把效果都隐藏,然后定义一个伪类来触发所有的效果,接下来当触发伪类后会有一个遍历 ...

  6. Robot Instructions

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  7. 用python写makefile

    温馨提示:阅读本文的同学最好能了解makefile和python的编写规则. 不懂的同学能够先保存在收藏夹.以便日后查看. 事实上之前我一直非常懒,我不想了解makefile规则.由于在linux下开 ...

  8. 【C语言】模拟实现库函数strcat函数

    //模拟实现库函数strcat函数 #include <stdio.h> #include <string.h> #include <assert.h> char ...

  9. Android ListView标题置顶效果实现

    一. 有图有真相     二.实现: 1. 基于ListView分类效果 2. TitleView即标题的处理(创建) 3. 处理TitleView的三种状态 三.源码: 例子下载 实现可以看代码,具 ...

  10. [Angular 2 Router] Configure Your First Angular 2 Route

    Using the Angular 2 router requires defining routes, passing them in to the RouterModule.forRoot and ...