CF Round #439 (Div 2)

A、B

额,,A、B题没什么难度吧,就不写了。。。
然而我的B题竟然FST了。。。

C.The Intriguing Obsession

Description

有三种颜色的群岛,数量分别为 a , b , c ,可以在两个不同颜色的岛之间连边,并且要满足不存在一个岛连了两个相同颜色的岛,求连边的方案数。

Solution

发现a、b和a、c以及b、c的关系是独立的,可以先只考虑a和b之间连边的方案数:假设 ab 则方案数为 Pab=1+ai=1Cia×Aib ,所以答案为 PabPbcPac

Code

#include
typedef long long LL;
#define For(i , j , k) for (LL i = (j) , _##end_ = (k) ; i <= _##end_ ; ++ i)
#define Fordown(i , j , k) for (LL i = (j) , _##end_ = (k) ; i >= _##end_ ; -- i)
#define Set(a , b) memset(a , b , sizeof(a))
#define pb push_back
#define Mod (998244353)
#ifdef hany01
#define debug(...) fprintf(stderr , __VA_ARGS__)
#else
#define debug(...)
#endif 
using namespace std;

inline void file()
{
#ifdef hany01 
    freopen("a.in" , "r" , stdin);
    freopen("a.out" , "w" , stdout);
#endif
}

char c_;
LL _ , __;
inline LL read() { for (_ = 0 , __ = 1 , c_ = getchar() ; !isdigit(c_) ; c_ = getchar()) if (c_ == '-') __ = -1; for ( ; isdigit(c_) ; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48); return _ * __; }

LL a[4] , Max , C[5001][5001] , AA , Ans , Ans1;

int main()
{
    file();
    For(i , 1 , 3)
    {
        a[i] = read();
        if (a[i] > Max)
            Max = a[i];
    }
    For(i , 1 , 2)
        For(j , i + 1 , 3)
            if (a[i] > a[j])
                swap(a[i] , a[j]);
    For(i , 0 , Max)
    {
        C[i][0] = C[i][i] = 1;
        For(j , 1 , i - 1)
            C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % Mod;
    }
    Ans = 1;
    For(i , 1 , 2)
        For(j , i + 1 , 3)
        {
            AA = 1;
            Ans1 = 1;
            For(k , 1 , a[i])
            {
                AA = (AA * (a[j] - k + 1)) % Mod;
                (Ans1 += (C[a[i]][k] * AA) % Mod) %= Mod;
            }
            (Ans *= Ans1) %= Mod;
        }
    cout << Ans << endl;
    return 0;
}

D.The Overdosing Ubiquity

全场只有一个人做对的题。。
待填坑~

E.The Untended Antiquity

Description

n×m 的方阵内摆放和撤走一些矩形的屏障,并询问是否可以由一点不跨过障碍地走到另一点

Solution

可以用二维线段树或四叉树做,这里考虑二维树状数组,每次修改时根据坐标随机一个值加上,撤走的时候用原来的值减去即可,时间复杂度 O(m×log22n)

Code

//Author: Hany01
//Task: E
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define For(i , j , k) for (int i = (j) , _##end_ = (k) ; i <= _##end_ ; ++ i)
#define Fordown(i , j , k) for (int i = (j) , _##end_ = (k) ; i >= _##end_ ; -- i)
#define Set(a , b) memset(a , b , sizeof(a))
#define pb push_back
#define INF (0x3f3f3f3f)
#define Mod (1000000007)
using namespace std;
typedef long long LL;

template <typename T> inline bool chkmax(T &a , T b) { return a < b ? (a = b , 1) : 0; }
template <typename T> inline bool chkmin(T &a , T b) { return b < a ? (a = b , 1) : 0; }

int _ , __;
char c_;
inline int read()
{
    for (_ = 0 , __ = 1 , c_ = getchar() ; !isdigit(c_) ; c_ = getchar()) if (c_ == '-') __ = -1;
    for ( ; isdigit(c_) ; c_ = getchar()) _ = (_ << 1) + (_ << 3) + (c_ ^ 48);
    return _ * __;
}

inline void file()
{
#ifndef ONLINE_JUDGE
    freopen("tmp.in" , "r" , stdin);
    freopen("tmp.out" , "w" , stdout);
#endif
}

const int maxn = 2501;

int n , m , T , r1 , r2 , r3 , r4;
LL c[maxn][maxn];

inline int lowbit(int x) { return x & -x; }

inline void updatey(int x , int y , int dt)
{
    for ( ; y <= m ; y += lowbit(y))
        c[x][y] += dt;
}

inline void updatex(int x , int y , int dt)
{
    for ( ; x <= n ; x += lowbit(x))
        updatey(x , y , dt);
}

inline void update(int xa , int ya , int xb , int yb , int type)
{
    LL dt = r1 * (LL)xa + r2 * (LL)ya + r3 * (LL)xb + r4 * (LL)yb;
    if (type == 2)
        dt = - dt;
    updatex(xa , ya , dt);
    updatex(xb + 1 , yb + 1 , dt);
    updatex(xa , yb + 1 , - dt);
    updatex(xb + 1 , ya , - dt);
}

inline LL queryy(int x , int y)
{
    LL sum = 0;
    for ( ; y ; y -= lowbit(y))
        sum += c[x][y];
    return sum;
}

inline LL queryx(int x , int y)
{
    LL sum = 0;
    for ( ; x ; x -= lowbit(x))
        sum += queryy(x , y);
    return sum;
}

inline LL query(int x , int y)
{
    return queryx(x , y);
}

int main()
{
    int type , xa , ya , xb , yb;
    srand(1248);
    file();
    r1 = rand();
    r2 = rand();
    r3 = rand();
    r4 = rand();
    n = read();
    m = read();
    T = read();
    while (T --)
    {
        type = read();
        xa = read();
        ya = read();
        xb = read();
        yb = read();
        if (type == 3)
            query(xa , ya) == query(xb , yb) ? puts("Yes") : puts("No");
        else
            update(xa , ya , xb , yb , type);
    }
    return 0;
}

你可能感兴趣的:(总结,Codeforces,排列组合,树状数组)