重囗另类BBWSeⅹHD,av狼论坛,精品一卡2卡三卡4卡乱码理论,体育生gv老师浪小辉3p警察

poj2892 Tunnel Warface -電腦資料

電腦資料 時間:2019-01-01 我要投稿
【www.ipr-jzsc.com - 電腦資料】

    Tunnel WarfareTime Limit:1000MSMemory Limit:131072KTotal Submissions:7434Accepted:3070

    Description

    During the War of Resistance Against Japan, tunnel warfare was carried out extensively in the vast areas of north China Plain. Generally speaking, villages connected by tunnels lay in a line. Except the two at the ends, every village was directly connected with two neighboring ones.

    Frequently the invaders launched attack on some of the villages and destroyed the parts of tunnels in them. The Eighth Route Army commanders requested the latest connection state of the tunnels and villages. If some villages are severely isolated, restoration of connection must be done immediately!

    Input

    The first line of the input contains two positive integersnandm(n,m≤ 50,000) indicating the number of villages and events. Each of the nextmlines describes an event.

    There are three different events described in different format shown below:

D x: Thex-th village was destroyed.Q x: The Army commands requested the number of villages thatx-th village was directly or indirectly connected with including itself.R: The village destroyed last was rebuilt.

    Output

    Output the answer to each of the Army commanders’ request in order on a separate line.

    Sample Input

7 9D 3D 6D 5Q 4Q 5RQ 4RQ 4

    Sample Output

1024

    Hint

    An illustration of the sample input:

OOOOOOOD 3   OOXOOOOD 6   OOXOOXOD 5   OOXOXXOR     OOXOOXOR     OOXOOOO

    Source

POJ Monthly--2006.07.30, updog

    平衡樹的應(yīng)用

    平衡樹中保存所有被炸毀的節(jié)點,

poj2892 Tunnel Warface

電腦資料

poj2892 Tunnel Warface》(http://www.ipr-jzsc.com)。

    對于炸毀和修復(fù)操作,直接在平衡樹中插入或刪除。

    對于查詢操作,先判斷該節(jié)點是否被炸毀,如果被炸毀答案為0,否則在平衡樹中求出前驅(qū)x和后繼y,答案為y-x-1。

    還有一種方法是二分+樹狀數(shù)組,感覺速度比這個慢就沒有寫…

#include<iostream>#include<cstdio>#include<cmath>#include<cstring>#include<cstdlib>#include#include<stack>#define F(i,j,n) for(int i=j;i<=n;i++)#define D(i,j,n) for(int i=j;i>=n;i--)#define LL long long#define MAXN 50005#define pa pair<int,int>#define INF 1000000000using namespace std;int n,m,x,tot=0,rt=0,l[MAXN],r[MAXN],rnd[MAXN],v[MAXN];char op;bool f[MAXN];stack<int>st;inline int read(){	int ret=0,flag=1;char ch=getchar();	while (ch<'0'||ch>'9'){if (ch=='-') flag=-1;ch=getchar();}	while (ch>='0'&&ch<='9'){ret=ret*10+ch-'0';ch=getchar();}	return ret*flag;}inline void rturn(int &k){	int tmp=l[k];	l[k]=r[tmp];r[tmp]=k;	k=tmp;}inline void lturn(int &k){	int tmp=r[k];	r[k]=l[tmp];l[tmp]=k;	k=tmp;}inline void ins(int &k,int x){	if (!k){k=++tot;v[k]=x;l[k]=r[k]=0;rnd[k]=rand();return;}	if (x<v[k]) else="" if="" inline="" int="" k="l[k]+r[k];" return="" tmp="pre(r[k],x);return" void="" x="">=v[k]) return suc(r[k],x);	else {int tmp=suc(l[k],x);return tmp==n+1?v[k]:tmp;}}inline int getans(int x){	if (f[x]) return 0;	return suc(rt,x)-pre(rt,x)-1;}int main(){	memset(f,false,sizeof(f));	n=read();m=read();	while (m--)	{		p=getchar();while (op<'A'||op>'Z') p=getchar();		if (op=='D') {x=read();f[x]=true;st.push(x);ins(rt,x);}		else if (op=='Q') {x=read();printf("%d\n",getans(x));}		else {del(rt,st.top());f[st.top()]=false;st.pop();}	}}</v[k])></int></int,int></stack></cstdlib></cstring></cmath></cstdio></iostream>

最新文章
主站蜘蛛池模板: 多伦县| 丘北县| 乐至县| 射阳县| 普陀区| 沾益县| 丰台区| 南郑县| 郯城县| 额敏县| 和林格尔县| 外汇| 和政县| 贵溪市| 六盘水市| 响水县| 长葛市| 修文县| 固阳县| 平南县| 遂溪县| 邵东县| 泗洪县| 射洪县| 安平县| 桃源县| 西和县| 泽州县| 惠来县| 南宁市| 襄城县| 永德县| 星座| 高碑店市| 库尔勒市| 霍林郭勒市| 阳江市| 成安县| 高邑县| 山阳县| 龙井市|