zoukankan      html  css  js  c++  java
  • Codeforces Round #197 (Div. 2) : D

    这题也是一个线段树的水题;

    不过开始题目没看明白,害得我敲了一个好复杂的程序。蛋疼啊。。。。

    最后十几分钟的时候突然领悟到了题意,但是还是漏掉一个细节,老是过不去。。。

    以后比赛的时候不喝啤酒了,再也不喝了。。。。

    贴上代码:

     1 #include<cstdio>
     2 #include<cstring>
     3 #define maxn 262200
     4 using namespace std;
     5 
     6 struct tree
     7 {
     8     int num;
     9     int l,r;
    10     tree *left,*right;
    11 } tr[maxn];
    12 int nodecount=0,a;
    13 
    14 void update(tree *root,int ok)
    15 {
    16     if(ok)
    17         root->num=(root->left->num)|(root->right->num);
    18     else root->num=(root->left->num)^(root->right->num);
    19 }
    20 
    21 void build(tree *root,int l,int r,int ok)
    22 {
    23     root->l=l;
    24     root->r=r;
    25     if(root->l==root->r)
    26     {
    27         scanf("%d",&a);
    28         root->num=a;
    29         return;
    30     }
    31     nodecount++;
    32     root->left=tr+nodecount;
    33     nodecount++;
    34     root->right=tr+nodecount;
    35     int mid=(root->l+root->r)/2;
    36     build(root->left,l,mid,ok^1);
    37     build(root->right,mid+1,r,ok^1);
    38     update(root,ok);
    39 }
    40 
    41 void change(tree *root,int i,int p,int ok)
    42 {
    43     if(root->l==i&&root->r==i)
    44     {
    45         root->num=p;
    46         return;
    47     }
    48     int mid=(root->r+root->l)/2;
    49     if(i<=mid) change(root->left,i,p,ok^1);
    50     else change(root->right,i,p,ok^1);
    51     update(root,ok);
    52 }
    53 
    54 
    55 int main()
    56 {
    57     int x,y,n,m,ans=0;
    58     scanf("%d%d",&n,&m);
    59     build(tr,1,1<<n,n&1);
    60     for(int i=0; i<m; i++)
    61     {
    62         ans=0;
    63         scanf("%d%d",&x,&y);
    64         change(tr,x,y,n&1);
    65         printf("%d
    ",tr[0].num);
    66     }
    67     return 0;
    68 }
    View Code
  • 相关阅读:
    Spring IOC(二)
    Spring组件注册
    第六章:随机数和expect
    第二十一节:异常处理
    第二十节:基础知识阶段复习
    LVM逻辑卷管理
    第十九节:类的装饰器和数据描述符的应用
    第十八节:上下文管理协议
    第十七节:数据描述符
    第十六节:内置函数补充
  • 原文地址:https://www.cnblogs.com/yours1103/p/3284252.html
Copyright © 2011-2022 走看看