QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#775801 | #9104. Zayin and Forest | wallcrack# | TL | 0ms | 0kb | C++14 | 1.7kb | 2024-11-23 16:44:58 | 2024-11-23 16:44:59 |
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){}
}tr[M*64];
long long lim,cnt=1;
void build(long long a1)
{
lim=a1;
}
int newNode()
{
cnt++;
return cnt;
}
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;
}
}seq;
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;
seq.build(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
Time Limit Exceeded
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 ...