QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#775592#9104. Zayin and Forestwallcrack#RE 0ms0kbC++141.7kb2024-11-23 16:16:042024-11-23 16:16:05

Judging History

你现在查看的是最新测评结果

  • [2024-11-23 16:16:05]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-11-23 16:16:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const long long N=1e18+10,M=1e5+10;
long long n,m;
struct DynamicSegmentTree
{
	struct Node
	{
		int ls,rs;
		long long sum;
		Node():ls(0),rs(0),sum(0){}
	};
	long long lim;
	vector<Node> tr; 
	DynamicSegmentTree(long long a1):tr(2),lim(a1){}
	int newNode()
	{
		tr.push_back(Node());
		return tr.size()-1;
	}
	void add(long long x,long long v)
	{
		add(1,1,lim,x,v);
	}
	void add(int o,long long l,long long r,long long x,long long v)
	{
		if(l==r)
		{
			tr[o].sum+=v;
			return ;
		}
		long long mid=l+r>>1;
		if(x<=mid)
		{
			if(!tr[o].ls)tr[o].ls=newNode();
			add(tr[o].ls,l,mid,x,v);
		}
		else 
		{
			if(!tr[o].rs)tr[o].rs=newNode();
			add(tr[o].rs,mid+1,r,x,v);
		}
		tr[o].sum=tr[tr[o].ls].sum+tr[tr[o].rs].sum;
	}
	long long query(long long l,long long r)
	{
		return query(1,1,lim,l,r);
	}
	long long query(int o,long long l,long long r,long long ql,long long qr)
	{
		if(l>=ql and r<=qr)return tr[o].sum;
		long long mid=l+r>>1,sum=0;
		if(l<=mid and tr[o].ls)
			sum+=query(tr[o].ls,l,mid,ql,qr);
		if(r>mid and tr[o].rs)
			sum+=query(tr[o].rs,mid+1,r,ql,qr);
		return sum;
	}
};
ull F(ull x)
{
	int p=0;
	while(!((1ll<<p)&x and !(((1ll<<(p+1))&x))))p++;
	ull res=(1ll<<(p+1));
	for(int i=p+2;i<63;i++)
		if(x&(1ll<<i))res|=(1ll<<i);
	return res;
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	DynamicSegmentTree seq(n);
	for(int i=1;i<=m;i++)
	{
		int op;
		cin>>op;
		if(op==1)
		{
			long long x,v;
			cin>>x>>v;
			while(x<=n)
			{
				seq.add(x,v);
				x=F(x);
			}
		}
		else 
		{
			long long l,r;
			cin>>l>>r;
			cout<<seq.query(l,r)<<"\n";
		}
	}
	return 0;
}


Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Runtime Error

input:

1000000000 20000
2 384578735 526547442
1 64211261 592970906
1 512065247 448267721
1 44993150 127180320
1 880319036 927623947
1 170536687 572121854
1 896600029 804033011
1 666246328 754201635
1 654066651 179982083
2 240989825 984888006
2 372004567 858916479
2 76127818 98606736
1 181794163 902842353
1...

output:

0
-729390784340407656
-8053291054738277826
0
-4351156108969420070
-2640296424153892293
3552123279086962778
-173219951803274377
184824929963965599
-6977281057729701624
-9121554378033758551
-8392039394096006320
-643338817159548638
-2978547094418595963
-8188011156447329066
1192771386929480308
-14721897...

result: