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] = '\0';
    }
    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\n", ((long long)n * (long long)(n - 1) - solve(a, b) - solve(b, c) - solve(c, a)) >> 1); 
    return 0;
}
View Code

 

转载于:https://www.cnblogs.com/19992147orz/p/7965934.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值