小椛椛的板子们2

感觉前上一篇的内容有些太多了,剩下的放在这里吧。

小椛椛的板子们   <- 这是上一篇

二分图匹配

#include <cstdio>
#include <iostream>
#include <queue>
#include <cstring>
#define INF 1e9
#define rg register
#define Max 100008
const int BUF = 12312313; char Buf[BUF], *buf = Buf;
inline void read (int &n)
{
    for (n = 0; !isdigit (*buf); ++ buf);
    for (; isdigit (*buf); n = n * 10 + *buf - ‘0‘, ++ buf);
}
inline int min (int a, int b) { return a < b ? a : b; }
int _v[Max << 5], _n[Max << 5], _f[Max << 5], list[Max], C = 1, d[Max], S, T, _th[Max];
int Flowing (int n, int f)
{
    if (f <= 0 || n == T) return f;
    int r = 0, p, v;
    for (int &i = _th[n]; i; i = _n[i])
    {
        if (!_f[i] || d[v = _v[i]] != d[n] + 1) continue;
        p = Flowing (v, min (_f[i], f));
        _f[i ^ 1] += p, _f[i] -= p, r += p, f -= p; if (f <= 0) return r;
    }
    if (r != f) d[n] = -1; return r;
}
bool Bfs ()
{
    std :: queue <int> Q; Q.push (S); rg int n, i, v;
    memset (d, -1, sizeof d); d[S] = 0;
    for (; !Q.empty (); Q.pop ())
        for (n = Q.front (), i = list[n]; i; i = _n[i])
            if (_f[i] && d[v = _v[i]] < 0)
            { d[v] = d[n] + 1; if (v == T) return true; Q.push (v); }
    return d[T] != -1;
}
inline void In (int x, int y)
{
    _v[++ C] = y, _n[C] = list[x], list[x] = C, _f[C] = 1;
    _v[++ C] = x, _n[C] = list[y], list[y] = C;
}
int main (int argc, char *argv[])
{
    fread (buf, 1, BUF, stdin);
    int N, M, E, x, y, s = 0; read (N), read (M), read (E); rg int i, j;
    for (i = 1, T = M + N + 1; i <= E; ++ i)
    {
        read (x), read (y);    if (x > M || y > M) continue;
        In (x, y + N);
    }
    for (i = 1; i <= N; ++ i) In (S, i);
    for (i = 1; i <= M; ++ i) In (N + i, T);
    for (; Bfs (); )
    {
        for (i = 0; i <= T; ++ i) _th[i] = list[i];
        s += Flowing (S, INF);
    }
    printf ("%d", s); return 0;
}

平衡树

二次联通门 : 数组splay ------ luogu P3369 【模板】普通平衡树(Treap/SBT)

二次联通门 : 指针splay ------ LibreOJ #107. 维护全序集

二次联通门 : 替罪羊树 ------ luogu P3369 【模板】普通平衡树(Treap/SBT)

二次联通门 : 红黑树 ------ luogu P3369 【模板】普通平衡树(Treap/SBT)

二次联通门 : fhq treap ------ luogu P3369 【模板】普通平衡树(Treap/SBT)

二逼平衡树

#include <cstdio>

#define Max 4000005
#define INF 1e9

void read (int &now)
{
    register char word = getchar ();
    int temp = 0;
    for (now = 0; word < ‘0‘ || word > ‘9‘; word = getchar ())
        if (word == ‘-‘)
            temp = 1;
    for (; word >= ‘0‘ && word <= ‘9‘; now = now * 10 + word - ‘0‘, word = getchar ());
    if (temp)
        now = -now;
}

int data[Max];

struct S_D
{
    S_D *child[2], *father;

    int size, weigth;
    int key;

    S_D ()
    {
        this->child[0] = this->child[1] = NULL;
        this->father = NULL;

        this->size = this->weigth = 1;
        this->key = 0;
    }

    void Clear ()
    {
        this->child[0] = this->child[1] = NULL;
        this->father = NULL;
    }

    int Get_Pos ()
    {
        return this->father->child[1] == this;
    }

    inline void Updata ()
    {
        this->size = this->weigth;
        if (this->child[0])
            this->size += this->child[0]->size;
        if (this->child[1])
            this->size += this->child[1]->size;
    }
};

int Maxn = -INF;

inline int max (int a, int b)
{
    return a > b ? a : b;
}

inline int min (int a, int b)
{
    return a < b ? a : b;
}

struct X_D
{
    X_D *Left, *Right;

    int l, r;
    int Mid;

    X_D (int __l, int __r) : l (__l), r (__r)
    {
        Left = Right = NULL;
        Mid = __l + __r >> 1;
    }
};

int Answer;

class Splay_Tree_Type
{

    private :

        S_D *Root;

        void Rotate (S_D *now)
        {
            S_D *Father = now->father;
            int pos = now->Get_Pos () ^ 1;
            Father->child[pos ^ 1] = now->child[pos];
            if (now->child[pos])
                now->child[pos]->father = Father;
            if ((now->father = Father->father) != NULL)
                now->father->child[now->father->child[1] == Father] = now;

            Father->father = now;
            now->child[pos] = Father;

            Father->Updata ();
            now->Updata ();
        }

        void Splay (S_D *now)
        {
            for (S_D *Father; Father = now->father; this->Rotate (now))
                if (Father->father)
                    this->Rotate (now->Get_Pos () == Father->Get_Pos () ? Father : now);
        }

    public :

        void Insert (int x)
        {
            if (Root == NULL)
            {
                Root = new S_D ;
                Root->key = x;
                return ;
            }
            S_D *now = Root, *Father;
            for (; ; Father = now, now = now->child[x > now->key])
            {
                if (now == NULL)
                {
                    now = new S_D;
                    now->father = Father;
                    now->key = x;
                    Father->child[x > Father->key] = now;
                    this->Splay (now);
                    Root = now;
                    return ;
                }
                if (now->key == x)
                {
                    now->weigth ++;
                    this->Splay (now);
                    Root = now;
                    return ;
                }
            }
        }

        int Find_Rank (int x)
        {
            S_D *now = Root;
            int Answer = 0;
            for (; ; )
            {
                if (now == NULL)
                    return Answer;
                if (now->key == x)
                    return (now->child[0] ? now->child[0]->size : 0) + Answer;
                else if (now->key < x)
                {
                    Answer += (now->child[0] ? now->child[0]->size : 0) + now->weigth;
                    now = now->child[1];
                }
                else if (now->key > x)
                    now = now->child[0];

            }
        }

        void Find (int x)
        {
            S_D *now;
            for (now = Root; (now != NULL && x != now->key); now = now->child[x > now->key]);

            this->Splay (now);
            Root = now;
            return ;
        }

        void Delete ()
        {
            S_D *now = Root;
            if (now->weigth > 1)
            {
                now->weigth --;
                now->size --;
                return ;
            }
            if (now->child[0] == NULL && now->child[1] == NULL)
            {
                 Root = NULL;
                 now->Clear ();
                 return ;
            }
            S_D *res;
            if (now->child[1] == NULL)
            {
                res = now;
                now->child[0]->father = NULL;
                Root = now->child[0];
                res->Clear ();
                return ;
            }
            if (now->child[0] == NULL)
            {
                res = now;
                now->child[1]->father = NULL;
                Root = now->child[1];
                res->Clear ();
                return ;
            }

            res = Root;
            S_D *res_pre = Find_Prefix_Pos ();
            this->Splay (res_pre);
            Root = res_pre;
            Root->child[1] = res->child[1];
            res->child[1]->father = Root;
            res->Clear ();
            Root->Updata ();
            return;
        }

        S_D *Find_Prefix_Pos ()
        {
            S_D *now = Root;
            for (now = now->child[0]; now->child[1]; now = now->child[1]);

            return now;
        }

        int Ask_Prefix (int x)
        {
            S_D *now = Root;
            for (; now;)
            {
                if (now->key < x)
                {
                    if (Answer < now->key)
                        Answer = now->key;
                    now = now->child[1];
                }
                else
                    now = now->child[0];
            }
            return Answer;
        }

        int Ask_Suffix (int x)
        {
            S_D *now = Root;
            for (; now; )
            {
                if (now->key > x)
                {
                    if (Answer > now->key)
                        Answer = now->key;
                    now = now->child[0];
                }
                else
                    now = now->child[1];
            }
            return Answer;
        }
};

Splay_Tree_Type Splay[Max];

class Segment_Tree_Type
{

    private :

        X_D *Root;
        void __Build_ (X_D *&now, int l, int r)
        {
            now = new X_D (l, r);
            if (l == r)
                return ;
            __Build_ (now->Left, l, now->Mid);
            __Build_ (now->Right, now->Mid + 1, r);
        }

        void __Insert_ (X_D *&now, int pos, int x, int _in)
        {
            Splay[_in].Insert (x);

            if (now->l == now->r)
                return ;
            if (pos <= now->Mid)
                __Insert_ (now->Left, pos, x, _in << 1);
            else
                __Insert_ (now->Right, pos, x, _in << 1 | 1);
        }

        void __Query_Rank_ (X_D *&now, int l, int r, int k, int _in)
        {
            if (l <= now->l && now->r <= r)
            {
                Answer += Splay[_in].Find_Rank (k);
                return ;
            }

            if (l <= now->Mid)
                __Query_Rank_ (now->Left, l, r, k, _in << 1);
            if (now->Mid  < r)
                __Query_Rank_ (now->Right, l, r, k, _in << 1 | 1);
        }

        void __Change_ (X_D *&now, int pos, int x, int _in)
        {
            Splay[_in].Find (data[pos]);
            Splay[_in].Delete ();
            Splay[_in].Insert (x);

            if (now->l == now->r)
                return ;

            if (pos <= now->Mid)
                __Change_ (now->Left, pos, x, _in << 1);
            else
                __Change_ (now->Right, pos, x, _in << 1 | 1);
        }

        void __Query_Prefix_ (X_D *&now, int l, int r, int x, int _in)
        {
            if (l <= now->l && now->r <= r)
            {
                Answer = max (Answer, Splay[_in].Ask_Prefix (x));
                return ;
            }

            if (l <= now->Mid)
                __Query_Prefix_ (now->Left, l, r, x, _in << 1);
            if (now->Mid < r)
                __Query_Prefix_ (now->Right, l, r, x, _in << 1 | 1);
        }

        void __Query_Suffix_ (X_D *&now, int l, int r, int x, int _in)
        {
            if (l <= now->l && now->r <= r)
            {
                Answer = min (Answer, Splay[_in].Ask_Suffix (x));
                return ;
            }

            if (l <= now->Mid)
                __Query_Suffix_ (now->Left, l, r, x, _in << 1);
            if (r > now->Mid)
                __Query_Suffix_ (now->Right, l, r, x, _in << 1 | 1);
        }

    public :

        void Build (int l, int r)
        {
            __Build_ (Root, l, r);
            return ;
        }

        void Insert (int pos, int x)
        {
            __Insert_ (Root, pos, x, 1);
            return ;
        }

        int Query_Suffix (int l, int r, int k)
        {
            Answer = INF;
            __Query_Suffix_ (Root, l, r, k, 1);
            return Answer;
        }

        int Query_kth_number (int l, int r, int x)
        {
            int L, R, Mid;
            for (L = 0, R = Maxn + 1, Mid; L != R; )
            {
                Mid = L + R >> 1;
                Answer = 0;
                this->Query_Rank (l, r, Mid);

                if (Answer < x)
                    L = Mid + 1;
                else
                    R = Mid;
            }
            return L - 1;
        }

        int Query_Rank (int l, int r, int k)
        {
            Answer = 0;
            __Query_Rank_(Root, l, r, k, 1);
            return Answer;
        }

        int Query_Prefix (int l, int r, int k)
        {
            Answer = 0;
            __Query_Prefix_ (Root, l, r, k, 1);
            return Answer;
        }

        void Change (int pos, int x)
        {
            __Change_ (Root, pos, x, 1);
            return ;
        }
};

Segment_Tree_Type Seg;

int main (int argc, char *argv[])
{
    int N, M;
    read (N);
    read (M);

    Seg.Build (1, N);
    for (int i = 1; i <= N; i ++)
    {
        read (data[i]);

        Maxn = max (data[i], Maxn);
        Seg.Insert (i, data[i]);
    }

    for (int type, x, y, z; M --; )
    {
        read (type);
        if (type == 1)
        {
            read (x);
            read (y);
            read (z);

            printf ("%d\n", Seg.Query_Rank (x, y, z) + 1);
        }
        else if (type == 2)
        {
            read (x);
            read (y);
            read (z);

            printf ("%d\n", Seg.Query_kth_number (x, y, z));
        }
        else if (type == 3)
        {
            read (x);
            read (z);

            Seg.Change (x, z);
            data[x] = z;
            Maxn = max (Maxn, x);
        }
        else if (type == 4)
        {
            read (x);
            read (y);
            read (z);

            printf ("%d\n", Seg.Query_Prefix (x, y, z));
        }
        else
        {
            read (x);
            read (y);
            read (z);

            printf ("%d\n", Seg.Query_Suffix (x, y, z));
        }
    }
    return 0;
}
时间: 2024-11-10 06:13:13

小椛椛的板子们2的相关文章

小椛椛的板子们

实在不愿意再做题了,这几天写写板子. Lucas #include <cstdio> #include <iostream> #define rg register inline void read (long long &n) { rg char c = getchar (); for (n = 0; !isdigit (c); c = getchar ()); for (; isdigit (c); n = n * 10 + c - '0', c = getchar (

(转载)图像处理(卷积)

图像处理-线性滤波-1 基础(相关算子.卷积算子.边缘效应) 这里讨论利用输入图像中像素的小邻域来产生输出图像的方法,在信号处理中这种方法称为滤波(filtering).其中,最常用的是线性滤波:输出像素是输入邻域像素的加权和. 1.相关算子(Correlation Operator) 定义:,  即 ,其中h称为相关核(Kernel). 步骤: 1)滑动核,使其中心位于输入图像g的(i,j)像素上 2)利用上式求和,得到输出图像的(i,j)像素值 3)充分上面操纵,直到求出输出图像的所有像素值

关于卷积的血腥实例、本质及物理意义

作为一名苦逼工科生,<信号与系统>+<数字信号处理>是绕不过去的坎,各种让人头疼的概念与数学公式:傅里叶变化.拉普拉斯变化.Z变换.卷积.循环卷积.自相关.互相关.离散傅里叶变化.离散傅里叶时间变化-- 前一段时间在知乎发现一个有趣例子,生动形象地解释了卷积的物理意义,且解释的较为准确,下面,正文来了: 比如说你的老板命令你干活,你却到楼下打台球去了,后来被老板发现,他非常气愤,扇了你一巴掌(注意,这就是输入信号,脉冲),于是你的脸上会渐渐地(贱贱地)鼓起来一个包,你的脸就是一个系

卷积的物理意义

原文链接:http://www.cnblogs.com/ylhome/archive/2010/01/07/1641121.html 卷积这个东东是“信号与系统”中论述系统对输入信号的响应而提出的.因为是对模拟信号论述的,所以常常带有繁琐的算术推倒,很简单的问题的本质常常就被一大堆公式淹没了,那么卷积究竟物理意义怎么样呢? 卷积表示为y(n) = x(n)*h(n).使用离散数列来理解卷积会更形象一点,我们把y(n)的序列表示成y(0),y(1),y(2) and so on; 这是系统响应出来

学会放弃,勇于追求

13年大学毕业,带着激情与追求踏上了寻梦之路,一呆就是三年,同一个城市同一个单位同一个部门.想想当年的三年规划也已经实现,而接下来的五年怎么走却还是带有迷茫. 三年里总结出来八个字:学会放弃,勇于追求. 社会的分工越来越明细,需求也越来越明确,简单的来说社会需要在某一领域钻研较深的人才.这与我13年毕业的想法是完全不同,毕业的想法是希望自己是个'全才',现在听起来都觉得有点'虚'的感觉,但那确确实实是自己的想法.大学四年学自动化,实验室呆了三年,跟着老师做点单片机的小项目,画画板子,而我确希望三

卷积的本质及物理意义(全面理解卷积)

卷积的本质及物理意义(全面理解卷积) 卷积的本质及物理意义 提示:对卷积的理解分为三部分讲解1)信号的角度2)数学家的理解(外行)3)与多项式的关系 1 来源 卷积其实就是为冲击函数诞生的.“冲击函数”是狄拉克为了解决一些瞬间作用的物理现象而提出的符号.古人曰:“说一堆大道理不如举一个好例子”,冲量这一物理现象很能说明“冲击函数”.在t时间内对一物体作用F的力,倘若作用时间t很小,作用力F很大,但让Ft的乘积不变,即冲量不变.于是在用t做横坐标.F做纵坐标的坐标系中,就如同一个面积不变的长方形,

超详细介绍 图像处理(卷积)(转)

图像处理(卷积)作者太棒了 原文 http://blog.sina.com.cn/s/blog_4bdb170b01019atv.html 图像处理-线性滤波-1 基础(相关算子.卷积算子.边缘效应) 这里讨论利用输入图像中像素的小邻域来产生输出图像的方法,在信号处理中这种方法称为滤波(filtering).其中,最常用的是线性滤波:输出像素是输入邻域像素的加权和. 1.相关算子(Correlation Operator) 定义:,  即 ,其中h称为相关核(Kernel). 步骤: 1)滑动核

图像处理(卷积)作者太棒了

转自:http://blog.sina.com.cn/s/blog_4bdb170b01019atv.html 图像处理-线性滤波-1 基础(相关算子.卷积算子.边缘效应) 这里讨论利用输入图像中像素的小邻域来产生输出图像的方法,在信号处理中这种方法称为滤波(filtering).其中,最常用的是线性滤波:输出像素是输入邻域像素的加权和. 1.相关算子(Correlation Operator) 定义:,  即 ,其中h称为相关核(Kernel). 步骤: 1)滑动核,使其中心位于输入图像g的(

卷积的幽默解释

今天又把卷积给忘了...然后就发现了这么个有才的文章! 信号与挨板子~哈哈哈哈! 谈起卷积分当然要先说说冲击函数----这个倒立的小蝌蚪,卷积其实就是为它诞生的.“冲击函数”是狄拉克为了解决一些瞬间作用的物理现象而提出的符号.古人曰:“说一堆大道理不如举一个好例子”,冲量这一物理现象很能说明“冲击函数”.在t时间内对一物体作用F的力,我们可以让作用时间t很小,作用力F很大,但让Ft的乘积不变,即冲量不变.于是在用t做横坐标.F做纵坐标的坐标系中,就如同一个面积不变的长方形,底边被挤的窄窄的,高度