Another Array of Orz Pandas
Another Array of Orz Pandas
题目链接:http://acm.xidian.edu.cn/problem.php?id=1187
线段树
线段树维护区间和以及区间内各个数平方和,对于每一个询问ans=(sum2-pow_sum)/2
代码如下:
#include<cstdio>
#include<cstring>
#define lson (x<<1)
#define rson (x<<1|1)
#define mid ((l+r)>>1)
#define N 100007
typedef long long LL;
struct nod{
LL sum,lazy,or2zds;
}a[N<<];
const LL mod=1e9+;
const LL Max=1e9;
LL n,m;
void push_up(LL x){
a[x].sum=(a[lson].sum+a[rson].sum)%mod;
a[x].or2zds=(a[lson].or2zds+a[rson].or2zds)%mod;
}
void push_down(LL x,LL l,LL r){
a[lson].or2zds=(a[lson].or2zds+(a[x].lazy*a[x].lazy)%mod*(mid+-l)+*a[x].lazy*a[lson].sum+mod)%mod;
a[lson].sum=(a[lson].sum+a[x].lazy*(mid+-l))%mod;
a[lson].lazy=(a[lson].lazy+a[x].lazy)%mod;
a[rson].or2zds=(a[rson].or2zds+(a[x].lazy*a[x].lazy)%mod*(r-mid)+*a[x].lazy*a[rson].sum+mod)%mod;
a[rson].sum=(a[rson].sum+a[x].lazy*(r-mid))%mod;
a[rson].lazy=(a[rson].lazy+a[x].lazy)%mod;
a[x].lazy=;
}
void add(LL x,LL l,LL r,LL cl,LL cr,LL v){
if(cl<=l&&r<=cr){
a[x].or2zds=(a[x].or2zds+(v*v)%mod*(r-l+)%mod+*v*a[x].sum)%mod;
a[x].sum=(a[x].sum+v*(r-l+))%mod;
a[x].lazy=(a[x].lazy+v)%mod;
return;
}
if(a[x].lazy!=)push_down(x,l,r);
if(cl<=mid)add(lson,l,mid,cl,cr,v);
if(mid<cr)add(rson,mid+,r,cl,cr,v);
push_up(x);
}
void query(LL x,LL l,LL r,LL ql,LL qr,LL &sum,LL &sum2){
if(ql<=l&&r<=qr){
sum=(sum+a[x].sum)%mod;
sum2=(sum2+a[x].or2zds)%mod;
return;
}
if(a[x].lazy!=)push_down(x,l,r);
if(ql<=mid)query(lson,l,mid,ql,qr,sum,sum2);
if(mid<qr)query(rson,mid+,r,ql,qr,sum,sum2);
}
int main(void){
while(~scanf("%lld%lld",&n,&m)){
memset(a,,sizeof(a));
LL l,r,op,k;
for(LL i=;i<m;i++){
scanf("%lld",&op);
if(op==){
scanf("%lld%lld%lld",&l,&r,&k);
add(,,n,l,r,k);
}else {
scanf("%lld%lld",&l,&r);
LL sum=,sum2=;
query(,,n,l,r,sum,sum2);
printf("%lld\n",(sum*sum%mod-sum2+mod)%mod*%mod);
}
}
}
return ;
}
Another Array of Orz Pandas的更多相关文章
- XidianOJ 1120 Gold of Orz Pandas
题目描述 Orz Panda is addicted to one RPG game. To make his character stronger, he have to fulfil tasks ...
- XidianOJ 1195 Industry of Orz Pandas
--正文 贪心 排序好慢慢找就好 #include <iostream> #include <cstring> #include <cstdio> #include ...
- Cai Xukun and Orz Pandas Gym - 102309C
题目链接:https://vjudge.net/problem/Gym-102309C 题意:给定蔡徐坤投篮的位置和篮筐的位置以及最大初速度,求一个初速度和时间. 思路:一开始我以为要用到二分,后面仔 ...
- 【Codeforces】Orz Panda Cup
大大出的题 大大经常吐槽没有人补,所以我决定做一个 A. APA of Orz Pandas 题意:给你一个包含+-*/%和()的表达式,让你把它转化成java里BigInteger的形式 大概就像这 ...
- numpy和pandas的基础索引切片
Numpy的索引切片 索引 In [72]: arr = np.array([[[1,1,1],[2,2,2]],[[3,3,3],[4,4,4]]]) In [73]: arr Out[73]: a ...
- Python:pandas(二)——pandas函数
Python:pandas(一) 这一章翻译总结自:pandas官方文档--General functions 空值:pd.NaT.np.nan //判断是否为空 if a is np.nan: .. ...
- xdoj-1117(记忆化搜索+组合数学)
因为我是从上到下,所以就不叫动态规划而叫记忆化搜索吧 (不过运行时间只有3ms....应该是很不错的吧) 排版怎么那么难看...编辑的时候不是这样子的啊?! 思想 : 大眼一看应该是一道很裸的状压dp ...
- scikit-learn_cookbook1: 高性能机器学习-NumPy
源码下载 在本章主要内容: NumPy基础知识 加载iris数据集 查看iris数据集 用pandas查看iris数据集 用NumPy和matplotlib绘图 最小机器学习配方 - SVM分类 介绍 ...
- 线性回归linear regression(python脚本实现)
python机器学习-乳腺癌细胞挖掘(博主亲自录制视频) https://study.163.com/course/introduction.htm?courseId=1005269003&u ...
随机推荐
- Ruby on rails3
Ruby on rails初体验(三) 继体验一和体验二中的内容,此节将体验二中最开始的目标来实现,体验二中已经将部门添加的部分添加到了公司的show页面,剩下的部分是将部门列表也添加到公司的显示 ...
- [原]Escape From the iOS Sanbox on Jailbreak Device
just my thinking, 3 ways to escape from sandbox on jailbreak device, to do file copying or execute s ...
- 教你使用shell数组
数组的使用,需要掌握 1.对数组进行赋值 2.通过下标访问数组元素 3.循环遍历所有的元素 代码如下: #!/bin/bash a="39" b="5" c=& ...
- ASP.NET MVC企业开发的基本环境
ASP.NET MVC企业开发的基本环境[资源服务器概念] 学完了ASP.NET MVC4 IN ACTION 六波以后 企业开发演习 标签:AaronYang 茗洋 EasyUI1.3.4 ...
- c语言,字符串原地翻转
实现字符串的原地翻转: #include<stdlib.h> #include<stdio.h> #include<assert.h> #define SWAP(a ...
- Ubuntu环境变量设置
在配置Ubuntu里面的JDK环境变量时,从网上找到的资料各异,在不同的文件里面配置,如/etc/environment./etc/profile,环境变量设置都是可以的.但是难免会有其它的疑问,不同 ...
- Ruby编码
目录 背景字符串可以使用不同的编码编码转换编码强制不同编码的字符串相加后是啥结果?一直没使用过的\u和\x使用Sublime开发Ruby时,输出到控制台的字符串为啥不能使用多种编码?备注 背景返回目录 ...
- Facebook开源的基于SQL的操作系统检测和监控框架:osquery
osquery简介 osquery是一款由facebook开源的,面向OSX和Linux的操作系统检测框架. osquery顾名思义,就是query os,允许通过使用SQL的方式来获取操作系统的数据 ...
- Wget 命令详解
Wget主要用于下载文件,在安装软件时会经常用到,以下对wget做简单说明. 1.下载单个文件:wget http://www.baidu.com.命令会直接在当前目录下载一个index.html的文 ...
- 论移动端Hybid开发
以下内容code地址:https://github.com/wytings/Hybrid 背景:公司业务的发展和开发需求升级,我们需要Hybrid了.市面上有很多开源的Hybrid框架给我们直接使用, ...