HDU5023A Corrupt Mayor's Performance Art (2014 ACM/ICPC Asia Regional Guangzhou Online)
分析:
線段樹模板題(區間更新 ,區間求和)
初始的顏色為2,一開始設成1了掛了好幾發
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAX=1000001;
struct node
{
int left,right,cover;
};
node tree[MAX*4];
bool used[31];
void built(int L,int R,int id)//建樹
{
tree[id].cover=2;//初始化顏色
tree[id].left=L;
tree[id].right=R;
if(L<R)
{
int mid=(L+R)/2;
built(L,mid,2*id); //左子樹
built(mid+1,R,2*id+1); //右子樹
}
}
void insert(int id,int L,int R,int col)
{
if(tree[id].left>=L&&tree[id].right<=R)
{
tree[id].cover=col;
return;
}
if(tree[id].left<tree[id].right)
{
int mid=(tree[id].left+tree[id].right)>>1;
if(tree[id].cover>0)
{
tree[id*2].cover=tree[id].cover;
tree[id*2+1].cover=tree[id].cover;
}
tree[id].cover=-1;
if(R<=mid)
insert(id*2,L,R,col);
else if(L>mid)
insert(id*2+1,L,R,col);
else
{
insert(id*2,L,mid,col);
insert(id*2+1,mid+1,R,col);
}
}
}
void cnt(int L,int R,int id)
{
if(tree[id].cover>0)
{
used[tree[id].cover]=true;
return;
}
if(tree[id].left<tree[id].right)
{
int mid=(tree[id].left+tree[id].right)>>1;
if(R<=mid)
cnt(L,R,id*2);
else if(L>mid)
cnt(L,R,id*2+1);
else
{
cnt(L,mid,id*2);
cnt(mid+1,R,id*2+1);
}
}
}
int main()
{
int n,Q;
while(~scanf("%d%d",&n,&Q)){
if(n==0&&Q==0)
break;
built(1,n,1);
int a,b,c;
char ord[2];
while(Q--){
scanf("%s",ord);
if(ord[0]=='P'){
scanf("%d%d%d",&a,&b,&c);
if(a<b) insert(1,a,b,c);
else insert(1,b,a,c);
}
else{
scanf("%d%d",&a,&b);
memset(used,0,sizeof(used));
if(a<b) cnt(a,b,1);
else cnt(b,a,1);
bool tt=1;
for(int i=1;i<=30;i++){
if(used[i]){
if(tt) tt=0;
else printf(" ");
printf("%d",i);
}
}
puts("");
}
}
}
return 0;
}
相關文章
- HDU4998 Rotate (2014 ACM/ICPC Asia Regional Anshan Online)ACM
- 2017 ACM/ICPC Asia Regional Shenyang Online - 做題記錄ACM
- HDU 5052 Yaoge’s maximum profit 光禿禿的樹鏈拆分 2014 ACM/ICPC Asia Regional Shanghai Online...ACMAI
- 2013 ACM/ICPC Asia Regional Online —— Warmup2 兩個水題ACM
- 2015 ACM/ICPC Asia Regional Shenyang Online-1012 Largest PointACM
- The 2021 ICPC Asia Shenyang Regional Contest
- 2016-2017 ACM-ICPC Asia-Bangkok Regional ContestACM
- 2018-2019 ACM-ICPC, Asia Seoul Regional Contest——A - CircuitsACMUI
- The 2024 ICPC Asia Nanjing Regional ContestNaN
- The 2022 ICPC Asia Nanjing Regional ContestNaN
- The 2023 ICPC Asia Macau Regional ContestMac
- The 2022 ICPC Asia Xian Regional Contest
- The 2022 ICPC Asia Hangzhou Regional Programming Contest
- The 2022 ICPC Asia Xian Regional Contest 前六題
- The 2023 ICPC Asia EC Regionals Online Contest (I)
- The 2024 ICPC Asia East Continent Online Contest (I)AST
- The 2022 ICPC Asia Nanjing Regional Contest IGDA,和令人疑惑的MNaN
- The 2023 ICPC Asia Hangzhou Regional Contest (The 2nd Universal Cup. Stage 22: Hangzhou)
- 2017-2018 ACM-ICPC Southeast Regional Contest (Div. 1)ACMAST
- 2017-2018 ACM-ICPC Pacific Northwest Regional Contest (Div. 1)ACM
- 2017-2018 ACM-ICPC, Central Europe Regional Contest (CERC 17)ACM
- Chayas - 2023-2024 ICPC, Asia Yokohama Regional Contest 2023, Problem E
- The 2024 ICPC Asia EC Regionals Online Contest (II) - Problem B. Mountain BookingAI
- The 2024 ICPC Asia EC Regionals Online Contest (II) - Problem H. Points Selection
- Performance and Memory Improvements in ART(Android O)ORMAndroid
- 2017-2018 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2017)ACM
- The 2023 ICPC Asia Jinan Regional Contest (The 2nd Universal Cup. Stage 17: Jinan)補題記錄NaN
- 2016-2017 ACM-ICPC Northwestern European Regional Programming Contest (NWERC 2016)ACM
- 2016-2017 ACM-ICPC Southwestern European Regional Programming Contest (SWERC 2016)ACM
- online website Performance testingWebORM
- ACM ICPC Vietnam National Second RoundACM
- ACM/ICPC2014鞍山現場賽E hdu5074Hatsune MikuACM
- HDU4091(2011 Asia Shanghai Regional Contest)AI
- Gradle's dependency cache may be corruptGradle
- acm/icpc入門級演算法模板ACM演算法
- 2018ACM-ICPC北京賽區 - A:Jin Yong’s Wukong Ranking List(DFS)ACM
- 2015 ACM/ICPC EC-FinalACM
- HDU3714 Error Curves(2010 Asia Chengdu Regional Contest)Error