zoukankan      html  css  js  c++  java
  • bzoj4430

    bit+容斥原理

    我不会cdq分治只能用这个做法

    考虑什么情况下不满足,至少有一个顺序不对就不行了,那么不满足的总有两对属性形成逆序对,那么我们用总方案数*2=n*(n-1)减去不符合的*2再/2就是答案

    似乎进rank前200了

    #include<bits/stdc++.h>
    using namespace std;
    const int N = 2e5 + 5;
    namespace IO 
    {
        const int Maxlen = N * 50;
        char buf[Maxlen], *C = buf;
        int Len;
        inline void read_in()
        {
            Len = fread(C, 1, Maxlen, stdin);
            buf[Len] = '';
        }
        inline void fread(int &x) 
        {
            x = 0;
            int f = 1;
            while (*C < '0' || '9' < *C) { if(*C == '-') f = -1; ++C; }
            while ('0' <= *C && *C <= '9') x = (x << 1) + (x << 3) + *C - '0', ++C;
            x *= f;
        }
        inline void fread(long long &x) 
        {
            x = 0;
            long long f = 1;
            while (*C < '0' || '9' < *C) { if(*C == '-') f = -1; ++C; }
            while ('0' <= *C && *C <= '9') x = (x << 1) + (x << 3) + *C - '0', ++C;
            x *= f;
        }
        inline void read(int &x)
        {
            x = 0;
            int f = 1; char c = getchar();
            while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
            while(c >= '0' && c <= '9') { x = (x << 1) + (x << 3) + c - '0'; c = getchar(); }
            x *= f;
        }
        inline void read(long long &x)
        {
            x = 0;
            long long f = 1; char c = getchar();
            while(c < '0' || c > '9') { if(c == '-') f = -1; c = getchar(); }
            while(c >= '0' && c <= '9') { x = (x << 1ll) + (x << 3ll) + c - '0'; c = getchar(); }
            x *= f;
        } 
    } using namespace IO;
    int n;
    int t[N], a[N], b[N], c[N], pos[N];
    void update(int x, int d)
    {
        for(; x <= n; x += x & -x) t[x] += d;    
    } 
    int query(int x)
    {
        int ret = 0;
        for(; x; x -= x & -x) ret += t[x];
        return ret;
    }
    long long solve(int *a, int *b)
    {
        long long ret = 0;
        for(int i = 1; i <= n; ++i) 
        {
            pos[a[i]] = i;
            t[i] = 0;
        }
        for(int i = n; i; --i) 
        {
            ret += query(pos[b[i]]);
            update(pos[b[i]], 1);
        }
        return ret;
    }
    int main()
    {
        read_in();
        fread(n);
        for(int i = 1; i <= n; ++i) fread(a[i]);
        for(int i = 1; i <= n; ++i) fread(b[i]);
        for(int i = 1; i <= n; ++i) fread(c[i]);
        printf("%lld
    ", ((long long)n * (long long)(n - 1) - solve(a, b) - solve(b, c) - solve(c, a)) >> 1); 
        return 0;
    }
    
    View Code
  • 相关阅读:
    美丽的姑娘,你何时才能重现?
    成功三步曲:有勇、有谋、有德
    比目标远一点点,结果也许令你惊讶
    走别人的路,让别人无路可走!
    白领们注意啦:“过劳死”27个危险信号!
    企业发展靠创新,还是靠美女?
    学会和同事相处的30个原则
    上海雄联机械配件有限公司
    C# Keywords>Access Keywords
    Feature event receviers
  • 原文地址:https://www.cnblogs.com/19992147orz/p/7965934.html
Copyright © 2011-2022 走看看