QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#775098 | #9104. Zayin and Forest | wallcrack# | TL | 298ms | 26196kb | C++14 | 1.4kb | 2024-11-23 14:43:10 | 2024-11-23 14:43:10 |
Judging History
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;
}
詳細信息
Test #1:
score: 100
Accepted
time: 298ms
memory: 26196kb
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...