zoukankan      html  css  js  c++  java
  • bzoj 1831

    思路:随便猜一猜填的数字是不下降的,反证很好证明,然后就没了。。

    #include<bits/stdc++.h>
    #define LL long long
    #define fi first
    #define se second
    #define mk make_pair
    #define PII pair<int, int>
    #define PLI pair<LL, int>
    #define ull unsigned long long
    using namespace std;
    
    const int N = 1e4 + 7;
    const int inf = 0x3f3f3f3f;
    const LL INF = 0x3f3f3f3f3f3f3f3f;
    const int mod = 1e9 + 7;
    
    int n, k, a[N];
    struct Bit {
        int a[101];
        void modify(int x, int val) {
            for(int i = x; i <= 100; i += i & -i)
                a[i] += val;
        }
        int sum(int x) {
            int ans = 0;
            for(int i = x; i; i -= i & -i)
                ans += a[i];
            return ans;
        }
        int query(int l, int r) {
            if(l > r) return 0;
            return sum(r) - sum(l-1);
        }
    } b1, b2;
    
    int main() {
        scanf("%d%d", &n, &k);
        for(int i = 1; i <= n; i++)
            scanf("%d", &a[i]);
        for(int i = n; i >= 1; i--)
            if(~a[i]) b2.modify(a[i], 1);
    
        LL ans = 0;
        for(int i = 1; i <= n; i++) {
            if(~a[i]) {
                b2.modify(a[i], -1);
                b1.modify(a[i], 1);
                ans += b1.query(a[i]+1, 100);
            } else {
                int ret = inf;
                for(int j = 1; j <= 100; j++) {
                    ret = min(ret, b1.query(j+1, 100) + b2.query(1, j-1));
                }
                ans += ret;
            }
        }
        printf("%lld
    ", ans);
        return 0;
    }
    
    /*
    */
  • 相关阅读:
    记第一场cf比赛(Codeforces915)
    Uva11468:Substring
    Uva11732:"strcmp()" Anyone?
    Uva1014:Remember the Word
    洛谷P2502:[HAOI2006]旅行
    bzoj3677: [Apio2014]连珠线
    bzoj4906: [BeiJing2017]喷式水战改
    海上孤独的帆
    Treap基本用法总结
    noip2017考前基础复习——数论数学
  • 原文地址:https://www.cnblogs.com/CJLHY/p/9757315.html
Copyright © 2011-2022 走看看