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

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

POJ2777(线段树裸题)

發(fā)布時(shí)間:2023/12/13 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 POJ2777(线段树裸题) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

題目:http://poj.org/problem?id=2777

別忘了各地的return;

有可能輸入的L<R,手動(dòng)swap;

似乎是多組輸入?

pushup和pushdown的位置。

(原來pushup只有一行)

要開四倍數(shù)組。是這種寫法的原因吧。

#include<iostream> #include<cstdio> #include<cstring> using namespace std; const int N=400005; int n,m,q,L,R,co; char ch; long long col[N],lazy[N]; void pushdown(int cnt) {if(lazy[cnt]){col[cnt*2]=lazy[cnt];col[cnt*2+1]=lazy[cnt];lazy[cnt*2]=lazy[cnt];lazy[cnt*2+1]=lazy[cnt];lazy[cnt]=0;} } void pushup(int cnt) {col[cnt]=(col[cnt*2]|col[cnt*2+1]); } void add(int l,int r,int cnt) {if(l>=L&&r<=R){col[cnt]=co;lazy[cnt]=co;return;}pushdown(cnt);int mid=(l+r)/2;if(mid>=L)add(l,mid,cnt*2);if(mid<R)add(mid+1,r,cnt*2+1);pushup(cnt); } long long query(int l,int r,int cnt) {if(l>=L&&r<=R){return col[cnt];}long long ans=0;pushdown(cnt);int mid=(l+r)/2;if(mid>=L)ans|=query(l,mid,cnt*2);if(mid<R)ans|=query(mid+1,r,cnt*2+1);return ans; } void build(int l,int r,int cnt) {col[cnt]=1;if(l==r)return;int mid=(l+r)/2;build(l,mid,cnt*2);build(mid+1,r,cnt*2+1); } int main() {while(scanf("%d%d%d",&n,&m,&q)!=EOF){build(1,n,1);memset(lazy,0,sizeof lazy);for(int i=1;i<=q;i++){scanf(" %c%d%d",&ch,&L,&R);if(L>R)swap(L,R);// if(ch=='C'){scanf("%d",&co);co=(1<<(co-1));add(1,n,1);}if(ch=='P'){int ret=0;long long ans=query(1,n,1);while(ans){ret+=(ans&1);ans>>=1;}printf("%d\n",ret);}}}return 0; }

?

轉(zhuǎn)載于:https://www.cnblogs.com/Narh/p/8721372.html

總結(jié)

以上是生活随笔為你收集整理的POJ2777(线段树裸题)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

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