Ambitious Experiment

Time limit: 3.0 second
Memory limit: 128 MB
During several decades, scientists from planet Nibiru are working to create an engine that would allow spacecrafts to fall into hyperspace and move there with superluminal velocity. To check whether their understanding of properties of hyperspace is right, scientists have developed the following experiment.
A chain of n particles is placed in hyperspace. Positions of particles in the chain are numbered from 1 to n. Initially, ith particle has charge ai.
According to the current theory, if particle number i got special radiation with power d, oscillations would spread by hyperspace and increase by d charge of particles with numbers i, 2i, 3iand so on (i.e. with numbers divisible by i).
Using a special device, scientists can direct the radiation of the same power at a segment of adjacent particles. For example, suppose that initially there were 6 particles with zero charges, and scientists have sent radiation with power five to particles with numbers 2 and 3. Then charge of 2nd, 3rd, and 4th particles will increase to five, and charge of 6th particle will increase to ten (the oscillations will reach it twice). Charge of other particles won’t change.
Charge of particles can’t change without impact of the device.
During the experiment, the scientists plan to perform actions of the following types:
  1. Measure current charge of the particle number i.
  2. Direct radiation with power d at particles with numbers from l to r inclusive.
Your program will be given a list of performed actions. For every action of the first type the program should output value of expected charge of the particle calculated in accordance with the current theory described above.
If the expected charges of the particles coincide with charges measured during the experiment, it will turn out that scientists’ understanding of hyperspace is right, and they will be able to start building of the hyperdrives. Then inhabitants of Nibiru will finally meet their brothers from Earth in just a few years!

Input

The first line contains a single integer n — number of particles (1 ≤ n ≤ 3 · 105).
The second line contains n integers ai separated by spaces — initial charges of the particles (0 ≤ai ≤ 106).
The third line contains a single integer q — number of actions in the experiment (1 ≤ q ≤ 3 · 105).
Each of the following q lines contain two or four integers — a description of the next action in one of the following formats:
  • i — measure current charge of the particle number i (1 ≤ i ≤ n).
  • 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

For each query output the expected charge of the ith particle.

Samples

input output
3
1 2 3
2
2 1 3 5
1 2
12
6
1 2 1 4 5 6
5
2 2 4 2
1 3
1 4
2 3 5 1
1 5
3
8
6

分析:对每个询问,只有他的因子才会对答案有贡献,所以sqrt(n)枚举因子;

   树状数组前缀和可以获得因子的贡献;

代码:

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=3e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p%mod;p=p*p%mod;q>>=;}return f;}
int n,m,k,t,q,a[maxn];
ll b[maxn];
void add(int x,int y)
{
for(int i=x;i<=n;i+=(i&(-i)))
b[i]+=y;
}
ll get(int x)
{
ll ans=;
for(int i=x;i;i-=(i&(-i)))
ans+=b[i];
return ans;
}
int main()
{
int i,j;
scanf("%d",&n);
rep(i,,n)scanf("%d",&a[i]);
scanf("%d",&q);
while(q--)
{
int c[];
scanf("%d",&c[]);
if(c[]==)
{
scanf("%d",&c[]);
ll ans=;
for(i=;i*i<=c[];i++)
{
if(c[]%i)continue;
ans+=get(i);
if(i!=c[]/i)ans+=get(c[]/i);
}
printf("%lld\n",ans+=a[c[]]);
}
else
{
rep(i,,)scanf("%d",&c[i]);
add(c[],c[]);add(c[]+,-c[]);
}
}
//system("Pause");
return ;
}

ural2062 Ambitious Experiment的更多相关文章

  1. ural 2062 Ambitious Experiment

    2062. Ambitious Experiment Time limit: 3.0 secondMemory limit: 128 MB During several decades, scient ...

  2. ural Ambitious Experiment 树状数组

    During several decades, scientists from planet Nibiru are working to create an engine that would all ...

  3. URAL 2062 Ambitious Experiment(分块)

    [题目链接] http://acm.timus.ru/problem.aspx?space=1&num=2062 [题目大意] 给出两个操作,操作一给出区间[l,r],对l到r中的每一个下标i ...

  4. 【树状数组】【枚举约数】 - Ambitious Experiment

    给定一个序列,支持以下操作: 对区间[l,r]的每个i,将1i,2i,3i,...这些位置的数都加d. 询问某个位置的数的值. 如果把修改看作对区间[l,r]的每个数+d,那么询问x位置上的数时,显然 ...

  5. Ural 2062:Ambitious Experiment(树状数组 || 分块)

    http://acm.timus.ru/problem.aspx?space=1&num=2062 题意:有n个数,有一个值,q个询问,有单点询问操作,也有对于区间[l,r]的每个数i,使得n ...

  6. An interesting experiment on China’s censorship

    This paper presented a very interesting topic. Censorship in China has always drawn people's attenti ...

  7. Reading With Purpose: A grand experiment

    Reading With Purpose: A grand experiment This is the preface to a set of notes I'm writing for a sem ...

  8. [POJ3684]Physics Experiment

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 1363   Accepted: 476   Special Judge ...

  9. poj 3684 Physics Experiment(数学,物理)

    Description Simon ), the first ball is released and falls down due to the gravity. After that, the b ...

随机推荐

  1. 【转】Ecshop 后台增加一个左侧列表菜单menu菜单的方法

    cshop 后台增加一个左侧列表菜单menu菜单需要修改三个文件:/admin/includes/inc_menu.php/admin/includes/inc_priv.php/languages/ ...

  2. RS232 DB9 公头 母头 串口引脚定义

    转自:http://hi.baidu.com/zhy_myspace/item/ad1ab0f112a4da1ad7ff8cf9 DB9 公头 母头 串口引脚定义 1.RS-232端(DB9母头/孔型 ...

  3. vs2010在进行数据架构比较时报'text lines should not be null'错误

    通过VS2010进行服务器数据库和本地数据库比较架构(都是sql server 2008 R2)时,弹出“text lines should be not null”错误,如下图: 解决方法:在Vis ...

  4. 这几天用到的 Linux 命令

    下面总结一下这几天用到的linux 命令,记录一下: 13 netstat -atunlp 26 apt-get install python-pip 27 pip install shadowsoc ...

  5. C语言头文件

    最近在工作当中遇到了一点小问题,关于C语言头文件的应用问题,主要还是关于全局变量的定义和声明问题.学习C语言已经有好几年了,工作使用也近半年了,但是对于这部分的东西的确还没有深入的思考过.概念上还是比 ...

  6. Hibernate 系列教程9-自关联

    自关联:本质还是原来双向一对多,原来要配置两个类,现在全部都配置在一个类里面 Employee public class Employee { private Long id; private Str ...

  7. hiho 1015 KMP

    input 1<=T<=20 string1 1<=strlen(string1)<=1e4 string2 2<=strlen(string2)<=1e6 out ...

  8. WordPress 邮箱防抓取

    现在网络上有很多爬虫,专门四处搜集网站代码中出现的邮箱,搜集到了之后就批量出售或者发送垃圾邮件.很多人都把邮箱中的 “@” 换成 “#”,但这样对用户不太方便,而且这种方法很多机器人都可以识破,同样被 ...

  9. myeclipse 2013 SR2 安装svn

    1.下载SVN-site-1.8.22.zip 2.找到MyEclipse安装路径 我的是F:\tool\myeclipse2013\dropins,复制SVN-site-1.8.22.zip到此文件 ...

  10. pat L1-006. 连续因子

    L1-006. 连续因子 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 一个正整数N的因子中可能存在若干连续的数字.例如630 ...