记录编号 |
494713 |
评测结果 |
AAAAAAAAAAAAAAAAAAAA |
题目名称 |
[HZOI 2016] 数列操作e |
最终得分 |
100 |
用户昵称 |
サイタマ |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
8.996 s |
提交时间 |
2018-04-12 21:55:24 |
内存使用 |
11.24 MiB |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
class node
{public:
unsigned long long val,val1,val2,val3;
}seg[400040];
unsigned long long n,m,op,ql,qr,x,ans=0,s[100010][2];
void operate(unsigned long long root,unsigned long long l,unsigned long long r,unsigned long long w1,unsigned long long w2,unsigned long long w3)
{
seg[root].val+=(s[r][1]-s[l-1][1])*w1-(s[r][0]-s[l-1][0])*w2+(r-l+1)*w3;
seg[root].val1+=w1;
seg[root].val2+=w2;
seg[root].val3+=w3;
}
void pushdown(unsigned long long root,unsigned long long l,unsigned long long r)
{
unsigned long long mid=(l+r)>>1;
operate(root<<1,l,mid,seg[root].val1,seg[root].val2,seg[root].val3);
operate(root<<1|1,mid+1,r,seg[root].val1,seg[root].val2,seg[root].val3);
seg[root].val1=0;
seg[root].val2=0;
seg[root].val3=0;
}
void add(unsigned long long root,unsigned long long l,unsigned long long r)
{
if(l>=ql&&r<=qr)
{
operate(root,l,r,x,2*(ql-1)*x,(ql-1)*(ql-1)*x);
return;
}
pushdown(root,l,r);
unsigned long long mid=(l+r)>>1;
if(mid>=ql)
add(root<<1,l,mid);
if(mid<qr)
add(root<<1|1,mid+1,r);
seg[root].val=seg[root<<1].val+seg[root<<1|1].val;
}
unsigned long long query(unsigned long long root,unsigned long long l,unsigned long long r)
{
if(l>=ql&&r<=qr){
return seg[root].val;}
pushdown(root,l,r);
unsigned long long mid=(l+r)>>1;
unsigned long long sum=0;
if(mid>=ql)
sum+=query(root<<1,l,mid);
if(mid<qr)
sum+=query(root<<1|1,mid+1,r);
return sum;
}
int lyh()
{
freopen("rneaty.in","r",stdin);
freopen("rneaty.out","w",stdout);
scanf("%llu%llu",&n,&m);
for(unsigned long long i=1;i<=n;i++)
{
s[i][0]+=s[i-1][0]+i;
s[i][1]+=s[i-1][1]+i*i;
}
for(unsigned long long i=1;i<=m;i++)
{
scanf("%llu%llu%llu",&op,&ql,&qr);
if(op==1)
{
scanf("%llu",&x);
add(1,1,n);
}
if(op==2)
ans^=query(1,1,n);
}
printf("%llu\n",ans);
return 0;
}
int Main=lyh();
int main(){;}