zoukankan      html  css  js  c++  java
  • 牛客练习赛16 B求值

    题目描述 

    给定n个数字a1, a2, ..., an。
    定义f(l, r) = al | al+1| ... | ar。
    现在枚举(1 <= l <= r <= n),问不同的f值一共有多少个。

    输入描述:

    第一行一个整数n表示数组大小 (1 <= n <= 100,000);
    第二行n个整数满足0 <= ai <= 1000,000。

    输出描述:

    输出一个整数表示不同的f值一共有多少个。
    示例1

    输入

    3
    1 2 0

    输出

    4
    示例2

    输入

    10
    1 2 3 4 5 6 1 2 9 10

    输出

    11


    每输入一个数字,计算它与前面的数字进行或运算能产生多少值。滚动求值,求当前输入的值是建立在前面的基础上的。
     1 #include <bits/stdc++.h>
     2 using namespace std;
     3 const int N = 2e6+10;
     4 set<int> st[2];
     5 bool vis[N];
     6 int x, n, last, ans;
     7 int main() {
     8     cin >> n;
     9     for(int i = 1; i <= n; i ++) {
    10         cin >> x;
    11         last = 1 - last;
    12         st[last].clear();
    13         set<int> :: iterator it = st[1-last].begin();
    14         for(; it != st[1-last].end(); ++ it) {
    15             int y = (*it)|x;
    16             vis[y] = true;
    17             st[last].insert(y);
    18         }
    19         st[last].insert(x);
    20         vis[x] = true;
    21     }
    22     for(int i = 0; i < N; i ++) if(vis[i]) ans++;
    23     cout << ans << endl;
    24     return 0;
    25 }
  • 相关阅读:
    ssh 命令
    mtr 命令
    ping 命令
    curl 命令
    echo 命令
    cp 命令
    sftp服务器配置
    tomcat性能优化
    消息队列
    深度学习
  • 原文地址:https://www.cnblogs.com/xingkongyihao/p/8966843.html
Copyright © 2011-2022 走看看