1. 程式人生 > >(WAWAWAWAWAWAW) G. Periodic RMQ Problem

(WAWAWAWAWAWAW) G. Periodic RMQ Problem

什麽 ole math oot log define code gis temp

沒有聯通門 : 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