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

歡迎訪問 生活随笔!

生活随笔

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

编程问答

ZOJ-1610-Count the Colors

發(fā)布時間:2024/4/17 编程问答 33 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ZOJ-1610-Count the Colors 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

鏈接:https://vjudge.net/problem/ZOJ-1610#author=0

題意:

給n個區(qū)間,是區(qū)間,對區(qū)間進行染色。

區(qū)間的范圍是1-8000。

求每種最后存在的顏色能看到的有幾段。

思路:

因為是區(qū)間,所以范圍變成(l+1, r)。

原數(shù)組直接延遲操作。

最后將查詢的位置對應到color數(shù)組上,統(tǒng)計答案。

代碼:

#include <iostream> #include <memory.h> #include <vector> #include <map> #include <algorithm> #include <cstdio>using namespace std;typedef long long LL;const int MAXN = 8000 + 10; int segment[MAXN * 4]; int color[MAXN]; int res[MAXN];void Push_Down(int root) {if (segment[root] != -1){segment[root << 1] = segment[root];segment[root << 1 | 1] = segment[root];segment[root] = -1;} }void Update(int root, int l, int r, int ql, int qr, int c) {if (ql > r || l > qr)return;if (ql <= l && r <= qr){segment[root] = c;return;}if (segment[root] == c)return;Push_Down(root);int mid = (l + r) / 2;Update(root << 1, l, mid, ql, qr, c);Update(root << 1 | 1, mid + 1, r, ql, qr, c); }void Query(int root, int l, int r) {if (segment[root] != -1){for (int i = l;i <= r;i++)color[i] = segment[root];return ;}if (l < r){int mid = (l + r) / 2;Query(root << 1, l, mid);Query(root << 1 | 1, mid + 1, r);} }void Count() {int i = 1;while (i <= 8000){if (color[i++] == -1)continue;while (i <= 8000 && color[i] == color[i - 1])++i;res[color[i - 1]]++;} }int main() {int n;while (~scanf("%d", &n)){memset(segment, -1, sizeof(segment));memset(color, -1, sizeof(color));memset(res, 0, sizeof(res));int l, r, c;for (int i = 1;i <= n;i++){scanf("%d%d%d", &l, &r, &c);Update(1, 1, 8000, l + 1, r, c);}Query(1, 1, 8000);Count();for (int i = 0;i <= 8000;i++){if (res[i] != 0)printf("%d %d\n", i, res[i]);}printf("\n");}return 0; }

  

轉載于:https://www.cnblogs.com/YDDDD/p/10447677.html

總結

以上是生活随笔為你收集整理的ZOJ-1610-Count the Colors的全部內容,希望文章能夠幫你解決所遇到的問題。

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