多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

國內(nèi)最全IT社區(qū)平臺 聯(lián)系我們 | 收藏本站
阿里云優(yōu)惠2
您當(dāng)前位置:首頁 > php開源 > php教程 > POJ 2528 Mayor's posters(離散化線段樹)

POJ 2528 Mayor's posters(離散化線段樹)

來源:程序員人生   發(fā)布時間:2015-02-27 08:34:12 閱讀次數(shù):4070次

Description

The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally decided to build an electoral wall for placing the posters and introduce the following rules: 
  • Every candidate can place exactly one poster on the wall. 
  • All posters are of the same height equal to the height of the wall; the width of a poster can be any integer number of bytes (byte is the unit of length in Bytetown). 
  • The wall is divided into segments and the width of each segment is one byte. 
  • Each poster must completely cover a contiguous number of wall segments.

They have built a wall 10000000 bytes long (such that there is enough place for all candidates). When the electoral campaign was restarted, the candidates were placing their posters on the wall and their posters differed widely in width. Moreover, the candidates started placing their posters on wall segments already occupied by other posters. Everyone in Bytetown was curious whose posters will be visible (entirely or in part) on the last day before elections. 
Your task is to find the number of visible posters when all the posters are placed given the information about posters' size, their place and order of placement on the electoral wall. 

Input

The first line of input contains a number c giving the number of cases that follow. The first line of data for a single case contains number 1 <= n <= 10000. The subsequent n lines describe the posters in the order in which they were placed. The i-th line among the n lines contains two integer numbers li and ri which are the number of the wall segment occupied by the left end and the right end of the i-th poster, respectively. We know that for each 1 <= i <= n, 1 <= li <= ri <= 10000000. After the i-th poster is placed, it entirely covers all wall segments numbered li, li+1 ,... , ri.

Output

For each input data set print the number of visible posters after all the posters are placed. 

The picture below illustrates the case of the sample input. 

Sample Input

1 5 1 4 2 6 8 10 3 4 7 10

Sample Output

4

由于點的個數(shù)到達了1e7,、而更新卻1e4所以斟酌離散化。

然后想到了map結(jié)果果斷超時,就只能換種方法。

普遍做法是2維數(shù)組mp[maxn<<2][2]放(l,r)區(qū)間。

#include<cstdio> #include<cstring> #include<algorithm> #include<vector> #include<string> #include<iostream> #include<queue> #include<cmath> #include<map> #include<stack> #include<bitset> using namespace std; #define REPF( i , a , b ) for ( int i = a ; i <= b ; ++ i ) #define REP( i , n ) for ( int i = 0 ; i < n ; ++ i ) #define CLEAR( a , x ) memset ( a , x , sizeof a ) typedef long long LL; typedef pair<int,int>pil; const int maxn=100100; int col[maxn<<2],vis[maxn<<2]; int mp[maxn<<2][2]; struct node{ int val;//值 int num;//節(jié)點編號 }e[maxn<<2]; int t,m,ans; void pushdown(int rs) { if(col[rs]) { col[rs<<1]=col[rs<<1|1]=col[rs]; col[rs]=0; } } void build(int rs,int l,int r) { col[rs]=0; if(l==r) return ; int mid=(l+r)>>1; build(rs<<1,l,mid); build(rs<<1|1,mid+1,r); } void update(int x,int y,int c,int l,int r,int rs) { if(l>=x&&r<=y) { col[rs]=c; return ; } pushdown(rs); int mid=(l+r)>>1; if(x<=mid) update(x,y,c,l,mid,rs<<1); if(y>mid) update(x,y,c,mid+1,r,rs<<1|1); } void query(int l,int r,int rs) { if(col[rs]) { if(!vis[col[rs]]) ans++; vis[col[rs]]=1; return ; } if(l==r) return ; int mid=(l+r)>>1; query(l,mid,rs<<1); query(mid+1,r,rs<<1|1); } int cmp(node l1,node l2) { return l1.val<l2.val; } int main() { scanf("%d",&t); while(t--) { scanf("%d",&m); int l=1; REP(i,m) { scanf("%d%d",&mp[i][0],&mp[i][1]); e[i<<1].val=mp[i][0]; e[i<<1].num=-(i+1);//左端點置為負區(qū)分右端點,num可恢復(fù)原來的店編號 e[i<<1|1].val=mp[i][1]; e[i<<1|1].num=i+1; } sort(e,e+2*m,cmp); int tmp=e[0].val,len=1; REP(i,2*m) { if(e[i].val!=tmp) { len++; tmp=e[i].val; } if(e[i].num<0) mp[-e[i].num⑴][0]=len; else mp[e[i].num⑴][1]=len; } build(1,1,len); CLEAR(vis,0); REP(i,m) update(mp[i][0],mp[i][1],i+1,1,len,1);//正常的更新 ans=0; query(1,len,1); printf("%d ",ans); } return 0; }


生活不易,碼農(nóng)辛苦
如果您覺得本網(wǎng)站對您的學(xué)習(xí)有所幫助,可以手機掃描二維碼進行捐贈
程序員人生
------分隔線----------------------------
分享到:
------分隔線----------------------------
關(guān)閉
程序員人生
主站蜘蛛池模板: 亚洲国产欧美国产第一区二区三区 | 久久精品国产400部免费看 | 噜噜噜在线视频免费观看 | 国产高清在线免费观看 | 毛片资源站| 日日夜夜天天久久 | 日韩免费专区 | 色综合天天综合网亚洲 | 久久黄色毛片 | 日韩一区国产一级 | 久久久一区二区三区不卡 | 欧美jizz18性欧美 | 欧美日韩亚 | 精品国产一区二区三区四区不 | 日本日韩欧美 | www.黄色网址.com | 午夜视频在线观看免费视频 | 九色91精品国产网站 | 一级视频免费观看 | 亚洲乱码中文 | 久久久久88色偷偷 | 亚洲精品视频在线播放 | 校园春色亚洲色图 | 伊人伊成久久人综合网777 | 伊人影院99 | 欧美另类激情 | 最近更新中文字幕在线 | www.自拍| 亚洲精品老司机在线观看 | 成人免费一区二区三区在线观看 | 亚洲性综合| 日本japanesexxxx人妖2 | 国产成人精品免费视频网页大全 | 久久久久国产精品美女毛片 | 亚洲最大福利网 | 最近的中文字幕大全免费版 | 久久精品一区二区 | a集毛片| 久久大 | 欧美aa级 | 玖玖色资源网 |