提交记录 3483


用户 题目 状态 得分 用时 内存 语言 代码长度
yww noi17a. 【NOI2017】整数 Accepted 100 697.997 ms 59388 KB C++11 3.76 KB
提交时间 评测时间
2018-07-15 20:38:37 2020-07-31 21:18:32
#include<cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
void read(int &s)
{
	int c;
	int b=0;
	while(((c=getchar())<'0'||c>'9')&&c!='-');
	if(c=='-')
	{
		b=1;
		s=0;
	}
	else
		s=c-'0';
	while((c=getchar())>='0'&&c<='9')
		s=s*10+c-'0';
	if(b)
		s=-s;
}
const int b30=(1<<30)-1;
const int all=1000000;
int bitcount(int x)
{
	int s=0;
	for(;x;x-=x&-x,s++);
	return s;
}
#define ls(x) ((x)<<1)
#define rs(x) (((x)<<1)|1)
int t[5000010];
int s[5000010];
int a[5000010];
void addt(int p,int v,int l,int r)
{
	t[p]=v;
	s[p]=v*(r-l+1);
	if(v)
		a[p]=b30;
	else
		a[p]=0;
}
void push(int p,int l,int mid,int r)
{
	if(t[p]==-1)
		return;
	addt(ls(p),t[p],l,mid);
	addt(rs(p),t[p],mid+1,r);
	t[p]=-1;
}
void change(int p,int x,int v,int l,int r)
{
	if(l==r)
	{
		a[p]=v;
		s[p]=bitcount(v);
		return;
	}
	int mid=(l+r)>>1;
	if(~t[p])
		push(p,l,mid,r);
	if(x<=mid)
		change(ls(p),x,v,l,mid);
	else
		change(rs(p),x,v,mid+1,r);
	s[p]=s[ls(p)]+s[rs(p)];
}
int query(int p,int x,int l,int r)
{
	if(l==r)
		return a[p];
	int mid=(l+r)>>1;
	if(~t[p])
		push(p,l,mid,r);
	if(x<=mid)
		return query(ls(p),x,l,mid);
	else
		return query(rs(p),x,mid+1,r);
}
//int query(int p,int ll,int rr,int l,int r)
//{
//	if(ll<=l&&rr>=r)
//		return s[p];
//	int mid=(l+r)>>1;
//	if(~t[p])
//		push(p,l,mid,r);
//	int s=0;
//	if(ll<=mid)
//		s+=query(ls(p),ll,rr,l,mid);
//	if(rr>mid)
//		s+=query(rs(p),ll,rr,mid+1,r);
//	return s;
//}
void find1(int p,int l,int r)
{
	if(l==r)
	{
		a[p]++;
		s[p]=bitcount(a[p]);
		return;
	}
	int mid=(l+r)>>1;
	if(~t[p])
		push(p,l,mid,r);
	if(s[ls(p)]<30*(mid-l+1))
		find1(ls(p),l,mid);
	else
	{
		addt(ls(p),0,l,mid);
		find1(rs(p),mid+1,r);
	}
	s[p]=s[ls(p)]+s[rs(p)];
}
void find2(int p,int l,int r)
{
	if(l==r)
	{
		a[p]--;
		s[p]=bitcount(a[p]);
		return;
	}
	int mid=(l+r)>>1;
	if(~t[p])
		push(p,l,mid,r);
	if(s[ls(p)])
		find2(ls(p),l,mid);
	else
	{
		addt(ls(p),30,l,mid);
		find2(rs(p),mid+1,r);
	}
	s[p]=s[ls(p)]+s[rs(p)];
}
int solve1(int p,int x,int l,int r)
{
	if(l==r)
		return 0;
	int mid=(l+r)>>1;
	if(~t[p])
		push(p,l,mid,r);
	if(x>mid)
	{
		int b=solve1(rs(p),x,mid+1,r);
		s[p]=s[ls(p)]+s[rs(p)];
		return b;
	}
	if(solve1(ls(p),x,l,mid))
	{
		s[p]=s[ls(p)]+s[rs(p)];
		return 1;
	}
	if(s[rs(p)]<30*(r-mid))
	{
		find1(rs(p),mid+1,r);
		s[p]=s[ls(p)]+s[rs(p)];
		return 1;
	}
	addt(rs(p),0,mid+1,r);
	s[p]=s[ls(p)]+s[rs(p)];
	return 0;
}
int solve2(int p,int x,int l,int r)
{
	if(l==r)
		return 0;
	int mid=(l+r)>>1;
	if(~t[p])
		push(p,l,mid,r);
	if(x>mid)
	{
		int b=solve2(rs(p),x,mid+1,r);
		s[p]=s[ls(p)]+s[rs(p)];
		return b;
	}
	if(solve2(ls(p),x,l,mid))
	{
		s[p]=s[ls(p)]+s[rs(p)];
		return 1;
	}
	if(s[rs(p)])
	{
		find2(rs(p),mid+1,r);
		s[p]=s[ls(p)]+s[rs(p)];
		return 1;
	}
	addt(rs(p),30,mid+1,r);
	s[p]=s[ls(p)]+s[rs(p)];
	return 0;
}
void add(int x,int v)
{
	int s=query(1,x,1,all);
	s=s+v;
	if(s>b30)
	{
		solve1(1,x,1,all);
		s-=1<<30;
	}
	change(1,x,s,1,all);
}
void del(int x,int v)
{
	int s=query(1,x,1,all);
	s=s-v;
	if(s<0)
	{
		solve2(1,x,1,all);
		s+=1<<30;
	}
	change(1,x,s,1,all);
}
int main()
{
	memset(t,-1,sizeof t);
	memset(s,0,sizeof s);
	memset(a,0,sizeof a);
	int n,t1,t2,t3;
	scanf("%d%d%d%d",&n,&t1,&t2,&t3);
	int c,x,y;
	int i;
	for(i=1;i<=n;i++)
	{
//		scanf("%d",&c);
		read(c);
		if(c==1)
		{
//			scanf("%d%d",&x,&y);
			read(x);
			read(y);
			if(x>0)
			{
				int bl=y/30+1;
				int t=y%30;
				ll s=ll(x)<<t;
				int s1=s&b30;
				int s2=s>>30;
				if(s1)
					add(bl,s1);
				if(s2)
					add(bl+1,s2);
			}
			else if(x<0)
			{
				x=-x;
				int bl=y/30+1;
				int t=y%30;
				ll s=ll(x)<<t;
				int s1=s&b30;
				int s2=s>>30;
				if(s1)
					del(bl,s1);
				if(s2)
					del(bl+1,s2);
			}
		}
		else
		{
//			scanf("%d",&x);
			read(x);
			int bl=x/30+1;
			int t=x%30;
			int s=query(1,bl,1,all);
			s=(s>>t)&1;
			printf("%d\n",s);
		}
	}
	return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #14.738 ms57 MB + 240 KBAcceptedScore: 4

Testcase #24.82 ms57 MB + 240 KBAcceptedScore: 4

Testcase #35.41 ms57 MB + 240 KBAcceptedScore: 4

Testcase #45.752 ms57 MB + 240 KBAcceptedScore: 4

Testcase #57.641 ms57 MB + 240 KBAcceptedScore: 4

Testcase #66.689 ms57 MB + 244 KBAcceptedScore: 4

Testcase #79.602 ms57 MB + 244 KBAcceptedScore: 4

Testcase #89.522 ms57 MB + 244 KBAcceptedScore: 4

Testcase #921.693 ms57 MB + 256 KBAcceptedScore: 4

Testcase #1033.795 ms57 MB + 264 KBAcceptedScore: 4

Testcase #1134.277 ms57 MB + 276 KBAcceptedScore: 4

Testcase #1224.08 ms57 MB + 276 KBAcceptedScore: 4

Testcase #1345.541 ms57 MB + 280 KBAcceptedScore: 4

Testcase #14126.896 ms57 MB + 356 KBAcceptedScore: 4

Testcase #15101.504 ms57 MB + 416 KBAcceptedScore: 4

Testcase #16260.349 ms57 MB + 476 KBAcceptedScore: 4

Testcase #17277.741 ms57 MB + 536 KBAcceptedScore: 4

Testcase #18406.373 ms57 MB + 596 KBAcceptedScore: 4

Testcase #19479.998 ms57 MB + 656 KBAcceptedScore: 4

Testcase #20333.013 ms57 MB + 1020 KBAcceptedScore: 4

Testcase #21340.616 ms57 MB + 776 KBAcceptedScore: 4

Testcase #22519.005 ms57 MB + 792 KBAcceptedScore: 4

Testcase #23645.13 ms57 MB + 708 KBAcceptedScore: 4

Testcase #24561.585 ms57 MB + 828 KBAcceptedScore: 4

Testcase #25697.997 ms57 MB + 832 KBAcceptedScore: 4


Judge Duck Online | 评测鸭在线
Server Time: 2024-11-22 12:27:39 | Loaded in 2 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠