POJ 2777 - Count Color(線段樹區間更新+狀態壓縮)

題目鏈接 https://cn.vjudge.net/problem/POJ-2777

【題意】
有一個長度為 LLL 的區間 [1,L][1,L][1,L] ,有 TTT 種顏色可以涂,有 QQQ 次操作,操作分兩種
C?A?B?CC \ A \ B \ CC?A?B?C 把區間 [A,B][A,B][A,B] 涂成第 CCC 種顏色
P?A?BP \ A \ BP?A?B 查詢區間 [A,B][A,B][A,B] 有多少種不同的顏色
初始全部為第 111 種顏色(L,Q&lt;=105,T&lt;=30L,Q&lt;=10^5,T&lt;=30L,Q<=105,T<=30

【思路】
因為顏色種類比較少,所以可以用二進制來表示某個區間的顏色集合,合并時用按位或運算,用lazy標記區間更新,查詢結果中二進制里1的個數就是答案

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define node tree[id]
#define lson tree[id<<1]
#define rson tree[id<<1|1]
using namespace std;const int maxn=100005;struct Tree{int left,right;int col,lazy;
}tree[maxn<<2];int n,m,q;void pushup(int id){node.col=lson.col|rson.col;}void pushdown(int id){if(node.lazy && node.left!=node.right){lson.lazy=node.lazy;lson.col=(1<<(node.lazy-1));rson.lazy=node.lazy;rson.col=(1<<(node.lazy-1));node.lazy=0;}
}void build(int id,int le,int ri){node.left=le;node.right=ri;node.lazy=0;if(le==ri){node.col=1;return;}int mid=(le+ri)>>1;build(id<<1,le,mid);build(id<<1|1,mid+1,ri);pushup(id);
}void update(int id,int le,int ri,int val){if(node.left==le && node.right==ri){node.col=(1<<(val-1));node.lazy=val;return;}pushdown(id);int mid=(node.left+node.right)>>1;if(ri<=mid) update(id<<1,le,ri,val);else if(le>mid) update(id<<1|1,le,ri,val);else{update(id<<1,le,mid,val);update(id<<1|1,mid+1,ri,val);}pushup(id);
}int query(int id,int le,int ri){if(node.left==le && node.right==ri){return node.col;}pushdown(id);int mid=(node.left+node.right)>>1;if(ri<=mid) return query(id<<1,le,ri);else if(le>mid) return query(id<<1|1,le,ri);else{return query(id<<1,le,mid)|query(id<<1|1,mid+1,ri);}
}int main(){while(scanf("%d%d%d",&n,&m,&q)==3){build(1,1,n);while(q--){char op[2];scanf("%s",op);if(op[0]=='C'){int a,b,c;scanf("%d%d%d",&a,&b,&c);if(a>b) swap(a,b);update(1,a,b,c);}else{int a,b;scanf("%d%d",&a,&b);if(a>b) swap(a,b);int ans=query(1,a,b);printf("%d\n",__builtin_popcount(ans));}}}return 0;
}

轉載于:https://www.cnblogs.com/wafish/p/10465152.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/388281.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/388281.shtml
英文地址,請注明出處:http://en.pswp.cn/news/388281.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

如何實施成功的數據清理流程

干凈的數據是發現和洞察力的基礎。 如果數據很臟&#xff0c;您的團隊為分析&#xff0c;培養和可視化數據而付出的巨大努力完全是在浪費時間。 當然&#xff0c;骯臟的數據并不是新的。 它早在計算機變得普及之前就困擾著決策。 現在&#xff0c;計算機技術已普及到日常生活中…

nginx前端代理tomcat取真實客戶端IP

nginx前端代理tomcat取真實客戶端IP2011年12月14日? nginx? 暫無評論? 被圍觀 3,000 次使用Nginx作為反向代理時&#xff0c;Tomcat的日志記錄的客戶端IP就不在是真實的客戶端IP&#xff0c;而是Nginx代理的IP。要解決這個問題可以在Nginx配置一個新的Header&#xff0c;用來…

kubeadm安裝kubernetes 1.13.2多master高可用集群

1. 簡介 Kubernetes v1.13版本發布后&#xff0c;kubeadm才正式進入GA&#xff0c;可以生產使用,用kubeadm部署kubernetes集群也是以后的發展趨勢。目前Kubernetes的對應鏡像倉庫&#xff0c;在國內阿里云也有了鏡像站點&#xff0c;使用kubeadm部署Kubernetes集群變得簡單并且…

通才與專家_那么您準備聘請數據科學家了嗎? 通才還是專家?

通才與專家Throughout my 10-year career, I have seen people often spend their time and energy in passionate debates about what data science can deliver, and what data scientists do or do not do. I submit that these are the wrong questions to focus on when y…

ubuntu opengl 安裝

安裝相應的庫&#xff1a; sudo apt-get install build-essential libgl1-mesa-dev sudo apt-get install freeglut3-dev sudo apt-get install libglew-dev libsdl2-dev libsdl2-image-dev libglm-dev libfreetype6-dev 實例&#xff1a; #include "GL/glut.h" void…

分享一病毒源代碼,破壞MBR,危險!!僅供學習參考,勿運行(vc++2010已編譯通過)

我在編譯的時候&#xff0c;殺毒軟件提示病毒并將其攔截&#xff0c;所以會導致編譯不成功。 1>D:\c工程\windows\windows\MBR病毒.cpp : fatal error C1083: 無法打開編譯器中間文件:“C:\Users\lenovo\AppData\Local\Temp\_CL_953b34fein”: Permission denied 1> 1>…

HTTP請求錯誤400、401、402、403、404、405、406、407、412、414、500、501、502解析

【轉載】本文來自 chenxinchongcn 的CSDN 博客 &#xff0c;全文地址請點擊&#xff1a;https://blog.csdn.net/chenxinchongcn/article/details/54945998?utm_sourcecopy HTTP 錯誤 400 400 請求出錯 由于語法格式有誤&#xff0c;服務器無法理解此請求。不作修改&#xff0…

數據科學家 數據工程師_數據科學家實際上賺了多少錢?

數據科學家 數據工程師目錄 (Table of Contents) Introduction 介紹 Junior Data Scientist 初級數據科學家 Mid-Level Data Scientist 中級數據科學家 Senior Data Scientist 資深數據科學家 Additional Compensation 額外補償 Summary 摘要 介紹 (Introduction) The lucrativ…

Spring Cloud構建微服務架構-Hystrix監控面板

在Spring Cloud中構建一個Hystrix Dashboard非常簡單&#xff0c;只需要下面四步&#xff1a;愿意了解源碼的朋友直接求求交流分享技術 一零三八七七四六二六 創建一個標準的Spring Boot工程&#xff0c;命名為&#xff1a;hystrix-dashboard。 編輯pom.xml&#xff0c;具體依賴…

Google 地圖 API 參考

楊航收集技術資料&#xff0c;分享給大家 Google 地圖 API 參考 Google 地圖 API 現在與 Google AJAX API 載入器集成&#xff0c;后者創建了一個公共命名空間&#xff0c;以便載入和使用多個 Google AJAX API。該框架可讓您將可選 google.maps.* 命名空間用于當前在 Google …

spotify歌曲下載_使用Spotify數據預測哪些“ Novidades da semana”歌曲會成為熱門歌曲

spotify歌曲下載TL; DR (TL;DR) Spotify is my favorite digital music service and I’m very passionate about the potential to extract meaningful insights from data. Therefore, I decided to do this article to consolidate my knowledge of some classification mod…

Hook技術之Hook Activity

一、Hook技術概述 Hook技術的核心實際上是動態分析技術&#xff0c;動態分析是指在程序運行時對程序進行調試的技術。眾所周知&#xff0c;Android系統的代碼和回調是按照一定的順序執行的&#xff0c;這里舉一個簡單的例子&#xff0c;如圖所示。 對象A調用類對象B&#xff0c…

(第三周)周報

此作業要求https://edu.cnblogs.com/campus/nenu/2018fall/homework/2143 1.本周PSP 總計&#xff1a;1422 min 2.本周進度條 (1)代碼累積折線圖 (2)博文字數累積折線圖 4.PSP餅狀圖 轉載于:https://www.cnblogs.com/gongylx/p/9761852.html

功能測試代碼python_如何使您的Python代碼更具功能性

功能測試代碼pythonFunctional programming has been getting more and more popular in recent years. Not only is it perfectly suited for tasks like data analysis and machine learning. It’s also a powerful way to make code easier to test and maintain.近年來&am…

layou split 屬性

layou split&#xff1a;true - 顯示側分欄 轉載于:https://www.cnblogs.com/jasonlai2016/p/9764450.html

BZOJ4503:兩個串(bitset)

Description 兔子們在玩兩個串的游戲。給定兩個字符串S和T&#xff0c;兔子們想知道T在S中出現了幾次&#xff0c;分別在哪些位置出現。注意T中可能有“?”字符&#xff0c;這個字符可以匹配任何字符。Input 兩行兩個字符串&#xff0c;分別代表S和TOutput 第一行一個正整數k&…

C#Word轉Html的類

C#Word轉Html的類/**//******************************************************************** created: 2007/11/02 created: 2:11:2007 23:13 filename: D:C#程序練習WordToChmWordToHtml.cs file path: D:C#程序練習WordToChm file bas…

分庫分表的幾種常見形式以及可能遇到的難題

前言 在談論數據庫架構和數據庫優化的時候&#xff0c;我們經常會聽到“分庫分表”、“分片”、“Sharding”…這樣的關鍵詞。讓人感到高興的是&#xff0c;這些朋友所服務的公司業務量正在&#xff08;或者即將面臨&#xff09;高速增長&#xff0c;技術方面也面臨著一些挑戰。…

iOS 鑰匙串的基本使用

級別&#xff1a; ★☆☆☆☆ 標簽&#xff1a;「鑰匙串」「keychain」「iOS」 作者&#xff1a; WYW 審校&#xff1a; QiShare團隊 前言 &#xff1a; 項目中有時會需要存儲敏感信息&#xff08;如密碼、密鑰等&#xff09;&#xff0c;蘋果官方提供了一種存儲機制--鑰匙串&a…

線性回歸和將線擬合到數據

Linear Regression is the Supervised Machine Learning Algorithm that predicts continuous value outputs. In Linear Regression we generally follow three steps to predict the output.線性回歸是一種監督機器學習算法&#xff0c;可預測連續值輸出。 在線性回歸中&…