• HDU 6186 CS Course


    保存前缀后缀。

    保存一下前缀和后缀,去掉第$i$个位置,就是$L[i-1]$和$R[i+1]$进行运算。

    #include<bits/stdc++.h>
    using namespace std;
    
    const int maxn = 100000 + 10;
    int Land[maxn], Rand[maxn];
    int Lor[maxn], Ror[maxn];
    int Xor;
    int a[maxn];
    int n, p;
    
    int main() {
      while(~scanf("%d%d", &n, &p)) {
        Xor = 0;
        for(int i = 1; i <= n; i ++) {
          scanf("%d", &a[i]);
        }
        Land[1] = Lor[1] = Xor = a[1];
        for(int i = 2; i <= n; i ++) {
          Land[i] = Land[i - 1] & a[i];
          Lor[i] = Lor[i - 1] | a[i];
          Xor = Xor ^ a[i];
        }
        Rand[n] = Ror[n] = a[n];
        for(int i = n - 1; i >= 1; i --) {
          Rand[i] = Rand[i + 1] & a[i];
          Ror[i] = Ror[i + 1] | a[i];
        }
        for(int i = 1; i <= p; i ++) {
          int pos;
          scanf("%d", &pos);
          if(pos == 1) {
            printf("%d %d %d
    ", Rand[2], Ror[2], Xor ^ a[1]);
          } else if(pos == n) {
            printf("%d %d %d
    ", Land[n - 1], Lor[n - 1], Xor ^ a[n]);
          } else {
            printf("%d %d %d
    ", Land[pos - 1] & Rand[pos + 1], Lor[pos - 1] | Ror[pos + 1], Xor ^ a[pos]);
          }
        }
      }
      return 0;
    }
    

      

  • 相关阅读:
    table操作:边框-斑马线-多表头-焦点高亮-自动求和
    Pygame
    Struts+HIbernate+Spring
    java 中hashcode 与 equals的关系
    Testcase的编写
    Struts+Hibernate+Spring常见问题
    我的思考
    JSP-------<%@ %>
    Python yield
    Python:itertools模块
  • 原文地址:https://www.cnblogs.com/zufezzt/p/7492816.html
Copyright © 2020-2023  润新知