zoukankan      html  css  js  c++  java
  • First One

    12269: First One

    时间限制: 2 Sec  内存限制: 128 MB
    提交: 4  解决: 2
    [提交] [状态] [命题人:外部导入]

    题目描述

    输入

    There are multiple test cases. The first line of input contains an integer T, indicating the number of test cases. For each test case:

    The first line contains an integer (1≤n≤105), the number of integers in the array.
    The next line contains n integers a1,a2,…,an (0≤ai≤105).

    输出

    For each test case, output the value.

    样例输入

    1
    2
    1 1

    样例输出

    12
    #include<bits/stdc++.h>
    
    using namespace std;
    
    
    const int maxn = 300060;
    typedef long long ll;
    
    int T, n;
    ll c[maxn];
    ll sum[maxn];
    
    int main() {
    #ifndef ONLINE_JUDGE
        freopen("1.txt", "r", stdin);
    #endif
        scanf("%d", &T);
        while (T--) {
            scanf("%d", &n);
            for (register int i = 1; i <= n; ++i) {
                scanf("%lld", &c[i]);
                sum[i] = sum[i - 1] + c[i];
            }
            ll res = 0;
            for (register int i = 1; i <= 36; ++i) {
                ll l = 1, r = 0;
                ll lmax = (1ll << (i - 1)), rmax = (1ll << i) - 1;
                if (i == 1)lmax = 0;
                for (register ll pos = 1; pos <= n; ++pos) {
                    l = max(l * 1ll, pos);
                    while (l <= n && sum[l] - sum[pos - 1] < lmax) {
                        ++l;
                    }
                    r = max(l - 1, r);
                    while (r + 1 <= n && sum[r + 1] - sum[pos - 1] >= lmax && sum[r + 1] - sum[pos - 1] <= rmax) {
                        ++r;
                    }
                    if (l > r)continue;
                    res += (i * (pos * (r - l + 1) + (r - l + 1) * (l + r) / 2));
                }
            }
            printf("%lld
    ", res);
        }
        return 0;
    }
     
  • 相关阅读:
    redis命令
    linux命令行任务管理
    tomcat修改内存
    Python调用shell
    取消myeclipse自动进入workspace
    解决Myeclipse编译不生成.class文件问题
    Manacher回文串算法学习记录
    青少年如何使用 Python 开始游戏开发
    对 Linux 专家非常有用的 20 个命令
    对中级 Linux 用户非常有用的 20 个命令
  • 原文地址:https://www.cnblogs.com/czy-power/p/11489590.html
Copyright © 2011-2022 走看看