Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

堆修改标记居然1A。。。险些爆内存,Delmark都开成char了

Posted by PoPoQQQ at 2014-07-28 16:10:51 on Problem 3481
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int map[10001000];
int n,m;
void swap(int &x,int &y){int z=x;x=y;y=z;}
struct Heap_Changing_Lazy{
	int heap[200200],top;
	char delmark[10001000];
	void insert(int x){
	    if(delmark[x]){
			delmark[x]--;
			return ; 
		}
	    heap[++top]=x;int t=top;while(t>1&&heap[t]>heap[t>>1])swap(heap[t],heap[t>>1]),t>>=1;
	}//插入,如果有delmark的话直接delmark[x]--
	void pop()
	{
	    int t=2;
	    heap[1]=heap[top];heap[top--]=0;
	    while(t<=top)
	    {
	        if(heap[t]<heap[t+1]&&t<top)t++;
	        if(heap[t]>heap[t>>1])swap(heap[t],heap[t>>1]),t<<=1;
	        else break;
	    }
	}//弹顶
	int heaptop(){
		int t;
		while(delmark[heap[1]]) 
			delmark[heap[1]]--,pop();//把有删除标记的堆顶全部删除
		t=heap[1];
		if(top)pop();
		return t; 
	}
}Maxheap,Minheap;
int main()
{
	int p,x,y,t;
	while(scanf("%d",&p),p)
	{
		switch(p)
		{
			case 1:scanf("%d%d",&x,&y),map[y]=x,Maxheap.insert(y),Minheap.insert(10000001-y);break;
			case 2:t=Maxheap.heaptop(),printf("%d\n",map[t]),Minheap.delmark[10000001-t]++;break;
			case 3:t=10000001-Minheap.heaptop(),printf("%d\n",map[t]),Maxheap.delmark[t]++;break;
		}
	}
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator