82分,9和10都T了,怀疑是二分写挂了
查看原帖
82分,9和10都T了,怀疑是二分写挂了
444135
thostever楼主2022/4/13 15:55
#include<bits/stdc++.h>
#define int unsigned long long
using namespace std;
struct node2
{
	int l,r;
	int s,add;
	int zero;
}t[1200010];
inline void push_up(int p)
{
	t[p].s=t[p<<1].s+t[p<<1|1].s;
}
inline void push_down(int p)
{
	if(t[p].zero)
	{
		t[p<<1].add=0;
		t[p<<1|1].add=0;
		t[p<<1].s=0;
		t[p<<1|1].s=0;
		t[p<<1].zero=1;
		t[p<<1|1].zero=1;
		t[p].zero=0;
	}
	if(t[p].add)
	{
		t[p<<1].add+=t[p].add;
		t[p<<1|1].add+=t[p].add;
		t[p<<1].s+=t[p].add*(t[p<<1].r-t[p<<1].l+1);
		t[p<<1|1].s+=t[p].add*(t[p<<1|1].r-t[p<<1|1].l+1);
		t[p].add=0;
	}
}
inline void build(int p,int l,int r)
{
	t[p].l=l; t[p].r=r;
	if(l==r)
	{
		t[p].s=0;
		return;
	}
	int mid=(l+r)>>1;
	build(p<<1,l,mid);
	build(p<<1|1,mid+1,r);
	push_up(p);
}
inline void update(int p,int x,int y,int z)
{
	if(x<=t[p].l&&t[p].r<=y)
	{
		t[p].add+=z;
		t[p].s+=z*(t[p].r-t[p].l+1);
		return;
	}
	push_down(p);
	int mid=(t[p].l+t[p].r)>>1;
	if(x<=mid) update(p<<1,x,y,z);
	if(mid<y) update(p<<1|1,x,y,z);
	push_up(p);
}
inline int query(int p,int x)
{
	if(x<=t[p].l&&t[p].r<=x) return t[p].s;
	push_down(p);
	int mid=(t[p].l+t[p].r)>>1;
	int sum=0;
	if(x<=mid) sum+=query(p<<1,x);
	if(mid<x) sum+=query(p<<1|1,x);
	return sum;
}
inline void tui(int p,int x,int y)
{
	if(x<=t[p].l&&t[p].r<=y)
	{
		t[p].s=0;
		t[p].add=0;
		t[p].zero=1;
		return;
	}
	push_down(p);
	int mid=(t[p].l+t[p].r)>>1;
	if(x<=mid) tui(p<<1,x,y);
	if(mid<y) tui(p<<1|1,x,y);
	push_up(p);
}
int n,m;
int T;
vector<int> p[300010],v[300010];
struct node
{
	int l,r;
	int x;
	int ans=0;
}a[300010],b[300010];
inline bool check()
{
	for(int i=1;i<=n;i++) if(a[i].l<a[i].r) return 1;
	return 0;
}
vector<int>::iterator it1,it2;
signed main()
{
	scanf("%lld%lld",&n,&m);
	build(1,1,m);
	for(int i=1;i<=m;i++)
	{
		int x;
		scanf("%lld",&x);
		p[x].push_back(i);
	}
	for(int i=1;i<=n;i++) scanf("%lld",&a[i].x);
	cin>>T;
	for(int i=1;i<=T;i++) scanf("%lld%lld%lld",&b[i].l,&b[i].r,&b[i].x);
	for(int i=1;i<=n;i++) a[i].l=1,a[i].r=T+1;
	while(check())
	{
		for(int i=1;i<=T;i++) v[i].clear();
		for(int i=1;i<=n;i++)
		{
			if(a[i].l<a[i].r)
			{
				int mid=(a[i].l+a[i].r)>>1;
				v[mid].push_back(i);
			}
		}
		tui(1,1,m);
		for(int i=1;i<=T;i++)
		{
			if(b[i].l<=b[i].r)
			{
				update(1,b[i].l,b[i].r,b[i].x);
			}
			else
			{
				update(1,1,b[i].r,b[i].x);
				update(1,b[i].l,m,b[i].x);
			}
			if(v[i].size())
			{
				for(it1=v[i].begin();it1!=v[i].end();it1++)
				{
					int x=*it1;
					int s=0;
					for(it2=p[x].begin();it2!=p[x].end();it2++) s+=query(1,*it2);
					int mid=(a[x].l+a[x].r)>>1;
					if(s>=a[x].x)
					{
						a[x].ans=mid;
						a[x].r=mid;
					}
					else
					{
						a[x].l=mid+1;
					}
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i].ans) printf("%lld\n",a[i].ans);
		else printf("NIE\n");
	}
    return 0;
}
/*

*/
2022/4/13 15:55
加载中...