ural Ambitious Experiment 树状数组
- Measure current charge of the particle number i.
- Direct radiation with power d at particles with numbers from l to r inclusive.
Input
- 1 i — measure current charge of the particle number i (1 ≤ i ≤ n).
- 2 l r d — direct radiation with power d at particles with numbers from l to r inclusive (1 ≤ l ≤ r ≤ n, 0 ≤ d ≤ 106).
Output
Example
| input | output |
|---|---|
3 |
12 |
6 |
3 |
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<vector>
#include<cstdio>
#include<iomanip>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define pi acos(-1)
#define ll long long
#define mod 1000000007 using namespace std; const int N=+,maxn=+,inf=1e9+; ll a[N],m[N];
void add(int i,int v)
{
while(i<=N){
m[i]+=v;
i+=i&(-i);
}
}
ll sum(int i)
{
ll ans=;
while(i>){
ans+=m[i];
i-=i&(-i);
}
return ans;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie();
int n;
cin>>n;
memset(m,,sizeof m);
for(int i=;i<=n;i++)cin>>a[i];
int k;
cin>>k;
while(k--){
int p,l,r,d;
cin>>p;
if(p==)
{
cin>>d;
ll ans=;
for(int i=;i*i<=d;i++)
{
if(d%i==)
{
ans+=sum(i);
if(i*i!=d)ans+=sum(d/i);
}
}
cout<<ans+a[d]<<endl;
}
else
{
cin>>l>>r>>d;
add(l,d);
add(r+,-d);
}
}
return ;
}
ural Ambitious Experiment 树状数组的更多相关文章
- Ural 2062:Ambitious Experiment(树状数组 || 分块)
http://acm.timus.ru/problem.aspx?space=1&num=2062 题意:有n个数,有一个值,q个询问,有单点询问操作,也有对于区间[l,r]的每个数i,使得n ...
- URAL 2062 树状数组
一个长度为n的数组 每次对lr区间进行修改 如果要修改i 则对i i*2 i*3...都修改 最后单点查询值 思想是利用树状数组维护每一个区间的更新值 查询的时候得出这个点的所有因子的查询值的和 加上 ...
- ural 1989(树状数组+多项式hash)
题意:给出一个字符串.有两种操作,一个是p a b,问字符串从位置a到位置b的子串是否是一个回文子串.还有一个操作 c a b,把字符串位置a的字符替换为b. 题解:由于字符串长度为1e5且问的次数也 ...
- HDU1541 树状数组
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- POJ 2352Stars 树状数组
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 42898 Accepted: 18664 Descripti ...
- POJ-2352 Stars 树状数组
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 39186 Accepted: 17027 Description A ...
- hdu 1541/poj 2352:Stars(树状数组,经典题)
Stars Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- Stars(树状数组或线段树)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37323 Accepted: 16278 Description A ...
- POJ2352Stars【树状数组】
Stars Description Astronomers often examine star maps where stars are represented by points on a pla ...
随机推荐
- C++提供了四个转换运算符
const_cast <new_type> (expression) static_cast <new_type> (expression) reinterpret_cast ...
- python网络编程之一
套接字的详细介绍会在另一篇博文指出,此片博文主要是python套接字的简单客户端编写. 两种套接字介绍: 面向连接的套接字:面向连接的套接字提供序列化,可靠的和不重复的数据交付.面向连接是可靠的传输, ...
- 20145127 《Java程序设计》第五次实验报告
实验简述: 在本周,我们进行了Java的第五次试验,本次实验的主要内容是结对编程.本次实验的大体过程是: 1.先进行Java的客户端与服务端的代码编写.结对是两个人,一人负责客户端,一人负责服务端. ...
- 20145324王嘉澜《网络对抗技术》web安全基础实践
实验内容 •使用webgoat进行XSS攻击.CSRF攻击.SQL注入 实验问答 •SQL注入攻击原理,如何防御 ①SQL注入攻击是攻击者在web应用程序中事先定义好的查询语句的结尾上添加额外的SQL ...
- 关于STM32 MDK中USE_STDPERIPH_DRIVER问题的解释
初学STM32,在RealView MDK 环境中使用STM32固件库建立工程时,初学者可能会遇到编译不通过的问题.出现如下警告或错误提示: warning: #223-D: function &qu ...
- Git 基础 —— 常见使用场景
Git 基础学习系列 Git 基础 -- 安装 配置 别名 对象 Git 基础 -- 常用命令 Git 基础 -- 常见使用场景 Git基础 -- Github 的使用 突然插入 Bugifx 工作, ...
- linux下获取本机的获取内网和外网地址
1.获取内网地址(私有地址) ifconfig -a 2.获取外网地址(公网地址) curl members.3322.org/dyndns/getip
- 高斯消元&&luogu3389
高斯消元(Gauss) 高斯消元和我们做二元一次方程组差不多 流程: 1.把系数和右边的值就是用二维数组存下来->转化成矩阵 我们的目标是把这个矩阵装换成 上三角的形式 对角线系数全部为1,1下 ...
- <OFFER> 06_PrintListInReversedOrder
#include<stack> #include "List.h" void PrintListReversingly_Iteratively(ListNode* pH ...
- system.data.sqlite的源代码下载
帮助文档 http://system.data.sqlite.org/index.html/doc/trunk/www/index.wiki 历史版本https://system.data.sqlit ...