日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

HDU 4391 Paint The Wall 段树(水

發布時間:2025/6/15 编程问答 55 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HDU 4391 Paint The Wall 段树(水 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

意甲冠軍:

特定n多頭排列。m操作

以下是各點的顏色

以下m一種操縱:

1 l r col 染色

2 l r col 問間隔col色點


== 通的操作+區間內最大最小顏色數的優化,感覺非常不科學。。。

==感覺能夠卡掉這樣的寫法。。反正就是不科學嘛?



#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> #include <vector> using namespace std; #define L(x) tree[x].l #define R(x) tree[x].r #define Len(x) tree[x].len #define Lazy(x) tree[x].lazy #define M(x) tree[x].minn #define W(x) tree[x].maxx #define Lson(x) (x<<1) #define Rson(x) (x<<1|1) const int N = 100010; struct node{int l, r, len, lazy, minn, maxx; }tree[N<<2]; int col[N]; void push_up(int id){if(Lazy(Lson(id)) == Lazy(Rson(id)))Lazy(id) = Lazy(Lson(id));else Lazy(id) = -1;M(id) = min(M(Lson(id)), M(Rson(id)));W(id) = max(W(Lson(id)), W(Rson(id))); } void push_down(int id){if(Lazy(id) != -1){Lazy(Lson(id)) = Lazy(Rson(id)) = Lazy(id);M(Lson(id)) = W(Lson(id)) = Lazy(id);M(Rson(id)) = W(Rson(id)) = Lazy(id);} } void build(int l, int r, int id){L(id) = l; R(id) = r;Len(id) = r-l+1;Lazy(id) = -1;if(l == r){Lazy(id) = col[l];W(id) = M(id) = col[l];return ;}int mid = (l+r)>>1;build(l, mid, Lson(id));build(mid+1, r, Rson(id));push_up(id); } void updata(int l, int r,int val, int id){if(l == L(id) && R(id) == r){Lazy(id) = val;W(id) = M(id) = val;return ;}push_down(id);int mid = (L(id) + R(id)) >>1;if(mid < l)updata(l, r, val, Rson(id));else if(r <= mid)updata(l, r, val, Lson(id));else {updata(l, mid, val, Lson(id));updata(mid+1, r, val, Rson(id));}push_up(id); } int query(int l, int r, int col, int id){if(!(M(id)<=col && col<=W(id))) return 0;if(Lazy(id)!=-1){if(Lazy(id) == col)return r-l+1;else return 0;}push_down(id);int mid = (L(id) + R(id)) >>1;if(mid < l)return query(l, r, col, Rson(id));else if(r <= mid)return query(l, r, col, Lson(id));elsereturn query(l, mid, col, Lson(id)) + query(mid+1, r, col, Rson(id)); } int n, que;int main() {while (cin>>n>>que) {for(int i = 1; i <= n; i++)scanf("%d", &col[i]);build(1, n, 1);while(que--){int type, l, r, color;scanf("%d %d %d %d", &type, &l, &r, &color);l++; r++;if(type == 1)updata(l, r, color, 1);elseprintf("%d\n", query(l, r, color, 1));}}return 0; } /* 5 12 1 2 3 4 0 2 1 3 3 1 1 3 1 2 1 3 3 2 0 3 1 2 3 4 1 1 0 4 0 2 0 4 0 2 0 4 2000000000 1 0 0 1 1 4 4 2 2 0 4 1 2 0 4 2*/

版權聲明:本文博客原創文章。博客,未經同意,不得轉載。

總結

以上是生活随笔為你收集整理的HDU 4391 Paint The Wall 段树(水的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。