求助呜呜呜
查看原帖
求助呜呜呜
287539
勇敢的菜鸡楼主2020/11/11 19:32

改了一下午不知道哪里wa了...对了里面的某份数据改不出来

100 20
2 1 9
1 47
1 52
2 13 3
2 6 7
1 83
2 9 5
1 59
2 13 3
1 58
1 58
2 3 8
1 58
2 18 1
1 64
2 13 3
1 2
1 7
1 3
1 31
正确的输入应该是:

1
48
0
0
0
0
0
0
3
5
12
0
#include<iostream>
#include<fstream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=5e4+1000;
typedef int LL;
struct Tree{
	LL l,r,pre,suf,sum,tag;//pre表示前缀最长连续1,suf表示后缀最长连续1,sum表示该区间的最长连续1 
}tree[maxn*4];
LL rmax(LL A,LL B,LL C){
	return max(A,max(B,C));
}
void push_up(LL p){
	tree[p].pre=tree[p*2].pre;
	tree[p].suf=tree[p*2+1].suf;
	tree[p].sum=rmax(tree[p*2].pre,tree[p*2+1].suf,tree[p*2].suf+tree[p*2+1].pre);
	if(tree[p*2].pre==tree[p*2].r-tree[p*2].l+1) tree[p].pre+=tree[p*2+1].pre;
	if(tree[p*2+1].suf==tree[p*2+1].r-tree[p*2+1].l+1) tree[p].suf+=tree[p*2].suf;
}
void addtag(LL p,LL d){
	tree[p].tag=d;
	tree[p].pre=tree[p].suf=tree[p].sum=d*(tree[p].r-tree[p].l+1);
}
void push_down(LL p){
	if(tree[p].tag!=-1){
		addtag(p*2,tree[p].tag);
		addtag(p*2+1,tree[p].tag);
		tree[p].tag=-1;
	}
}
void build(LL p,LL l,LL r){
	tree[p].l=l;tree[p].r=r;tree[p].pre=tree[p].suf=tree[p].sum=tree[p].r-tree[p].l+1;tree[p].tag=-1;
	if(l==r){return;}
	LL mid=(l+r)>>1;
	build(p*2,l,mid);build(p*2+1,mid+1,r);
	push_up(p);
}
void modify(LL p,LL l,LL r,LL d){
	if(l<=tree[p].l&&r>=tree[p].r){
		addtag(p,d);
		return;
	}
	push_down(p);
	LL mid=(tree[p].l+tree[p].r)>>1;
	if(l<=mid) modify(p*2,l,r,d);
	if(r>mid) modify(p*2+1,l,r,d);
	push_up(p);
}
LL query(LL p,LL l,LL r,LL num){
	if(l==r){
		return l;
	}
	push_down(p);
	LL mid=(l+r)>>1;
	if(tree[p].sum>=num){
		if(tree[p*2].sum>=num) return query(p*2,l,mid,num);
		if(tree[p*2].suf+tree[p*2+1].pre>=num) return mid-tree[p*2].suf+1;
		if(tree[p*2+1].sum>=num) return query(p*2+1,mid+1,r,num);
	}
	///return pos;
	return 0;
}
LL debugquery(LL p,LL l,LL r)
{
	if(l<=tree[p].l&&r>=tree[p].r){
		return tree[p].sum;
	}
	push_down(p);
	LL ans=0;
	LL mid=(tree[p].l+tree[p].r)>>1;
	if(l<=mid) ans+=debugquery(p*2,l,r);
	if(r>mid) ans+=debugquery(p*2+1,l,r);
	return ans;
} 
int main(void)
{
  ///cin.tie(0);std::ios::sync_with_stdio(false);
  LL n,m;
 //// freopen("in1.in","r",stdin);
 //// freopen("out1.out","w",stdout); 
  cin>>n>>m;
  build(1,1,n);
  for(int i=1;i<=m;i++)
  {
  	LL op;cin>>op;
//  	for(LL i=1;i<=n;i++){
//  		cout<<debugquery(1,i,i)<<" ";
//	}
//	cout<<endl;
	if(op==1){
  		LL k;cin>>k;
		LL pos=query(1,1,n,k);
		cout<<pos<<endl;	
		if(pos) modify(1,pos,pos+k-1,0);
	}
	else{
		LL l,r;cin>>l>>r;
		modify(1,l,l+r-1,1);
	}
//	for(LL i=1;i<=n;i++){
//		cout<<debugquery(1,i,i)<<" ";
//	}	
//	cout<<endl;
  }
 /// fclose(stdin);
 /// fclose(stdout);
return 0;
}


2020/11/11 19:32
加载中...