QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#776033#9104. Zayin and Forestwallcrack#TL 306ms26452kbC++201.4kb2024-11-23 17:22:422024-11-23 17:22:42

Judging History

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

  • [2024-11-23 17:22:42]
  • 评测
  • 测评结果:TL
  • 用时:306ms
  • 内存:26452kb
  • [2024-11-23 17:22:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
const long long N=1e18+10,M=1e5+10;
struct Operation
{
	long long type,val,l,r;
	vector<long long> add;
}op[M];
long long n,m;
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;
}
void solve(int l,int r)
{
	if(l==r)return ;
	int mid=l+r>>1;
	set<long long> num;
	num.insert(0);
	map<long long,long long>id;
	for(int i=l;i<=mid;i++)
		for(long long ai:op[i].add)
			num.insert(ai);
	int cnt=0;
	for(long long ai:num)
	{
		id[ai]=cnt;
		cnt++;
	}
	vector<long long>pre(num.size());
	for(int i=l;i<=mid;i++)
		for(long long ai:op[i].add)
			pre[id[ai]]+=op[i].val;
	for(int i=1;i<pre.size();i++)
		pre[i]+=pre[i-1];
	for(int i=mid+1;i<=r;i++)
	{
		if(op[i].type==2)
		{
			long long l=*prev(num.lower_bound(op[i].l));
			long long r=*prev(num.upper_bound(op[i].r));
			op[i].val+=pre[id[r]]-pre[id[l]];
		}
	}
	solve(l,mid);
	solve(mid+1,r);
}
int main()
{
	ios::sync_with_stdio(false);
	cin>>n>>m;
	for(int i=1;i<=m;i++)
	{
		cin>>op[i].type;
		if(op[i].type==1)
		{
			long long x;
			cin>>x>>op[i].val;
			while(x<=n)
			{
				op[i].add.push_back(x);
				x=F(x);
			}
		}
		else cin>>op[i].l>>op[i].r;
	}
	solve(1,m);
	for(int i=1;i<=m;i++)
		if(op[i].type==2)
			cout<<op[i].val<<"\n";
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 306ms
memory: 26452kb

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
43148875202
17613404710
0
32808578044
28190043566
15641637055
78276219892
14955165236
20262224725
105057452192
17002492367
57916137452
27165464255
72766353838
39458327919
38294102627
264448717384
0
70928519548
279674530483
88885017175
111664599432
69703816663
211506104092
104120007714
34403738515
...

result:

ok 6649 lines

Test #2:

score: -100
Time Limit Exceeded

input:

1000000000000000000 100000
1 384578735 526547442
1 64211261 592970906
1 512065247 448267721
1 44993150 127180320
1 880319036 927623947
1 170536687 572121854
1 896600029 804033011
2 666246328 931651408754201635
1 654066651 179982083
1 984888006 240989825
1 372004567 858916479
1 76127818 98606736
1 18...

output:


result: