ural2062 Ambitious Experiment
Ambitious Experiment
Memory limit: 128 MB
- 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
Samples
input | output |
---|---|
3 |
12 |
6 |
3 |
分析:对每个询问,只有他的因子才会对答案有贡献,所以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的更多相关文章
- ural 2062 Ambitious Experiment
2062. Ambitious Experiment Time limit: 3.0 secondMemory limit: 128 MB During several decades, scient ...
- ural Ambitious Experiment 树状数组
During several decades, scientists from planet Nibiru are working to create an engine that would all ...
- URAL 2062 Ambitious Experiment(分块)
[题目链接] http://acm.timus.ru/problem.aspx?space=1&num=2062 [题目大意] 给出两个操作,操作一给出区间[l,r],对l到r中的每一个下标i ...
- 【树状数组】【枚举约数】 - Ambitious Experiment
给定一个序列,支持以下操作: 对区间[l,r]的每个i,将1i,2i,3i,...这些位置的数都加d. 询问某个位置的数的值. 如果把修改看作对区间[l,r]的每个数+d,那么询问x位置上的数时,显然 ...
- Ural 2062:Ambitious Experiment(树状数组 || 分块)
http://acm.timus.ru/problem.aspx?space=1&num=2062 题意:有n个数,有一个值,q个询问,有单点询问操作,也有对于区间[l,r]的每个数i,使得n ...
- An interesting experiment on China’s censorship
This paper presented a very interesting topic. Censorship in China has always drawn people's attenti ...
- 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 ...
- [POJ3684]Physics Experiment
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 1363 Accepted: 476 Special Judge ...
- poj 3684 Physics Experiment(数学,物理)
Description Simon ), the first ball is released and falls down due to the gravity. After that, the b ...
随机推荐
- spring security 3 自定义认证,授权示例
1,建一个web project,并导入所有需要的lib. 2,配置web.xml,使用Spring的机制装载: <?xml version="1.0" encoding=& ...
- 桥接 NAT HOST-ONLY
无论是vmware,virtual box,virtual pc等虚拟机软件,一般来说,虚拟机有三种网络模式: 1.桥接 2.NAT 3.Host-Only 桥接 桥接网络是指本地物理网卡和虚拟网卡通 ...
- 删除sql计划 调用的目标发生了异常。 (mscorlib) 其他信息: 用户 'sa' 登录失败。
在删除以前创建的sql的计划任务时,弹出如题错误提示,发现错误原因在于,sa密码更改过,导致在删除时因为sa的密码和当前的密码不正确出现此错误. 解决办法: 1.在计划任务的编辑窗口,找到管理连接 2 ...
- 字符串查找 cmd find命令
find /i "ora-" *.log 我对findstr是如此的依赖,以至于当我向各位讲解find命令的时候,我还得老老实实地在cmd窗口中敲下 find /? 这条命令,然后 ...
- php fsockopen
1.PHP fsockopen函数说明: Open Internet or Unix domain socket connection(打开套接字链接) Initiates a socket conn ...
- word2010无法打开文件时的一点对策
word2010无法打开文件时的一点对策 1. Word 安全模式启动,点击「开始」,在搜索栏中输入winword /safe并回车,测试问题是否依然存在? 2. 正常启动Word,点击“文件”—“选 ...
- java断点
第一步: 用firefox运行程序,当点击保存,提示保存失败后,启动firebug 通过请求找到addNew.ezt出现错误,在eztnews.xml里通过ctrl+F查找找到请求执行的类和方法 找到 ...
- Ubuntu不可以ping百度,但是可以ping通其ip
原来也安装过几个ubuntu系统,但是今天遇到一个很奇怪的情况,明明ifconfig显示已经获取了网络上的ip,但是浏览器就是打不开网页,百思不得其解.因为这几天用ping用多了,所以进行了以下尝试: ...
- hack,不同的IE浏览器
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- HDU-1548--A strange lift--(BFS,剪枝)
A strange lift Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) To ...