(WAWAWAWAWAWAW) G. Periodic RMQ Problem

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了(WAWAWAWAWAWAW) G. Periodic RMQ Problem相关的知识,希望对你有一定的参考价值。

没有联通门 : Codeforces G. Periodic RMQ Problem

 

 

/*

    Codeforces G. Periodic RMQ Problem
    
    MMP
    什么动态开点线段树啊 

    。。。
    YY了个非常可行的做法
    码完后交一下发现RE了几个点。。
    
    就思考哪里有问题
    
    突然之间, 老泪纵横。。
    
    MMP  我写了这是个什么玩意啊
    
    仔细想想我TM不就是写了个全空间的主席树吗。。。。脑子有病啊。。 
    静言思之, 躬自悼矣。。反是不思,亦已焉哉
    
    不写啦! 
*/
#include <cmath>
#include <cstdio>

#define Max 100008
#define INF 1e8

void read (int &now)
{
    now = 0;
    register char word = getchar ();
    bool temp = false;
    while (word < 0 || word > 9)
    {
        if (word == -)
            temp = true;
        word = getchar ();
    }
    while (word >= 0 && word <= 9)
    {
        now = now * 10 + word - 0;
        word = getchar ();
    }
    if (temp)
        now = -now;
}

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

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

int N, K;

int number[Max];

struct Segment_Tree_Date
{
    Segment_Tree_Date *Left, *Right;
    
    int l, r;
    
    int Mid;
    int key;
    int Flandre;
    Segment_Tree_Date ()
    {
        Left = NULL;
        Right = NULL;
        key = 0;
        Flandre = 0;
    }
};

Segment_Tree_Date *Root;

int Size;
    
class Segment_Tree_Type
{
    public :
    
        void Build (Segment_Tree_Date *&now, int l, int r, int k)
        {
            if (l == r)
            {
                now->key = number[l - (k - 1) * N];
                return;
            }
            now->Mid = l + r >> 1;
            Build (now->Left, l, now->Mid, k);
            Build (now->Right, now->Mid + 1, r, k);
            now->key = min (now->Left->key, now->Right->key);
        }
        
        void Whole_Updata (Segment_Tree_Date *&now, int l, int r)
        {
            if (now->l == now->r)
                return ;
            if (now->Flandre)
            {
                now->Left->key = now->Flandre;
                now->Right->key = now->Flandre;
                
                now->Left->Flandre = now->Flandre;
                now->Right->Flandre = now->Flandre;
                
                now->Flandre = 0;
            }
            Whole_Updata (now->Left, l, now->Mid);
            Whole_Updata (now->Right, now->Mid + 1, r);
            now->key = min (now->Left->key, now->Right->key);
        }
        
        int Query (Segment_Tree_Date *&now, int l, int r)
        {
            if (l <= now->l && now->r <= r)
                return now->key;
            if (now->Flandre)
            {
                now->Left->key = now->Flandre;
                now->Right->key = now->Flandre;
                
                now->Left->Flandre = now->Flandre;
                now->Right->Flandre = now->Flandre;
                
                now->Flandre = 0;
            }
            now->key = min (now->Left->key, now->Right->key);
            int res = INF;
            if (l <= now->Mid)
                res = Query (now->Left, l, min (now->Mid, r));
            if (r > now->Mid)
                res = min (res, Query (now->Right, max (now->Mid + 1, l), r));
            return res;
        }
        
        void Change_Section_Maxn (Segment_Tree_Date *&now, int l, int r, int to)
        {
            if (l <= now->l && now->r <= r)
            {
                now->Flandre = to;
                now->key = to;
                return ;
            }
            if (now->Flandre)
            {
                now->Left->key = now->Flandre;
                now->Right->key = now->Flandre;
                
                now->Left->Flandre = now->Flandre;
                now->Right->Flandre = now->Flandre;
                
                now->Flandre = 0;
            }
            if (l <= now->Mid)
                Change_Section_Maxn (now->Left, l, min (now->Mid, r), to);
            if (r > now->Mid)
                Change_Section_Maxn (now->Right, max (now->Mid + 1, l), r, to);    
            now->key = min (now->Left->key, now->Right->key);
        }
};

Segment_Tree_Type Tree;

int M;
bool is_exist[Max];

int main (int argc, char *argv[])
{
    read (N);
    read (K);
    for (int i = 1; i <= N; i++)
        read (number[i]);
    int type, x, y, z;
    is_exist[1] = true;
    int now_1, now_2;
    Tree.Build (Root, 1, N, 1);
    register bool flag;
    for (read (M); M--; )
    {
        flag = false;
        read (type);
        read (x);
        read (y);
        if (type == 1)
        {
            read (z);
            now_1 = ceil (x * 1.0 / N);
            now_2 = ceil (y * 1.0 / N);
            for (int pos = now_1; pos <= now_2; pos++)
                if (!is_exist[pos])
                {
                    Tree.Build (Root, N * (pos - 1) + 1, N * pos, pos); 
                    flag = true;
                    is_exist[pos] = true;
                }
            if (flag)
                Tree.Whole_Updata (Root, N * (now_1 - 1) + 1, N * now_2); 
            Tree.Change_Section_Maxn (Root, x, y, z);
        }
        else
        {
            now_1 = ceil (x * 1.0 / N);
            now_2 = ceil (y * 1.0 / N);
            for (int pos = now_1; pos <= now_2; pos++)
                if (!is_exist[pos])
                {
                    Tree.Build (Root, N * (pos - 1) + 1, N * pos, pos);
                    flag = true;
                    is_exist[pos] = true;
                }
            if (flag)
                Tree.Whole_Updata (Root, N * (now_1 - 1) + 1, N * now_2); 
            printf ("%d\n", Tree.Query (Root, x, y));
        }
    }
    return 0;
}

 

以上是关于(WAWAWAWAWAWAW) G. Periodic RMQ Problem的主要内容,如果未能解决你的问题,请参考以下文章

G. 类常量

HDU - 1498 G.题解

G. 设置站点别名和目录别名

Codeforces G. Ant colony

Codefroces 852 G. Bathroom terminal

Codeforces G. Ciel the Commander