果然我自己写的读入优化naive!。。。换题目给的读入优化就A了。。。话说用visual交快了好多啊。。。

const int BufferSize=1<<16;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=0,f=1;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
return x*f;
}
#include<cstdio>
#include<cstring>
#include<cctype>
#include<algorithm>
using namespace std;
#define rep(i,s,t) for(int i=s;i<=t;i++)
#define dwn(i,s,t) for(int i=s;i>=t;i--)
#define clr(x,c) memset(x,c,sizeof(x))
#define ll long long
const int BufferSize=1<<14;
char buffer[BufferSize],*head,*tail;
inline char Getchar() {
if(head==tail) {
int l=fread(buffer,1,BufferSize,stdin);
tail=(head=buffer)+l;
}
return *head++;
}
inline int read() {
int x=0,f=1;char c=Getchar();
for(;!isdigit(c);c=Getchar()) if(c=='-') f=-1;
for(;isdigit(c);c=Getchar()) x=x*10+c-'0';
return x*f;
}
const int nmax=1e6+5;
ll c[nmax];int t[nmax];
int main(){
int n=read(),m=read(),u,v,d;
rep(i,1,n) for(int j=i;j<=n;j+=i) ++t[j];
rep(i,1,m){
u=read();
if(u==1){
v=read(),d=read();
for(int j=v,k=1;j<=n;j+=v,++k) c[j]+=d*t[k];
}else{
v=read();printf("%lld\n",c[v]);
}
}
return 0;
}

  

基准时间限制:2 秒 空间限制:131072 KB 分值: 80 难度:5级算法题
 收藏
 关注

有三个下标从1到n的数组a、b、c。

a数组初始全为0。

b[i]=∑j|ia[j]

c[i]=∑j|ib[j]

需要进行下列操作:

1 x y :将a[x]加上y

2 x :询问当前c[x]的值

 
j | i 表示j是i的约数。

由于数据比较多,请用输入挂。

以下供参考。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
 
Input
第一行两个整数,n和q,分别表示数组下标范围和操作次数。(1<=n,q<=1,000,000)
接下来q行,描述一个操作。(x随机,1<=x<=n,1<=y<=10^6)
Output
对于每一个第二种操作输出一个答案。
Input示例
5 5
1 2 4
2 2
2 4
1 1 3
2 5
Output示例
4
8
6

51nod1586 约数和的更多相关文章

  1. BZOJ 1968: [Ahoi2005]COMMON 约数研究

    1968: [Ahoi2005]COMMON 约数研究 Time Limit: 1 Sec  Memory Limit: 64 MBSubmit: 2032  Solved: 1537[Submit] ...

  2. 【BZOJ】3994: [SDOI2015]约数个数和

    题意: \(T(1 \le T \le 50000)\)次询问,每次给出\(n, m(1 \le n, m \le 50000)\),求\(\sum_{i=1}^{n} \sum_{j=1}^{m} ...

  3. 【P1379】天才的约数和

    来自GDOI2007,原题已不可考-- 又自己做出来了好开心,找特殊性是个关键的切入点 原题: 这天周航遇到了靳泽旭. 周航:"我是天才!" 靳泽旭:"你为什么是天才?& ...

  4. codevs 2606 约数和问题

    题目描述 Description Smart最近沉迷于对约数的研究中. 对于一个数X,函数f(X)表示X所有约数的和.例如:f(6)=1+2+3+6=12.对于一个X,Smart可以很快的算出f(X) ...

  5. hdu5175 gcd 求约数

    题意:求满足条件GCD(N,M) = N XOR M的M的个数 sol:和uva那题挺像的.若gcd(a,b)=a xor b=c,则b=a-c 暴力枚举N的所有约数K,令M=NxorK,再判断gcd ...

  6. hdu1492(约数个数定理)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1492 这里先讲一下约数个数定理: 对于正整数x,将其质因分解为 x = pow(p1, a) * po ...

  7. POJ 2480 (约数+欧拉函数)

    题目链接: http://poj.org/problem?id=2480 题目大意:求Σgcd(i,n). 解题思路: 如果i与n互质,gcd(i,n)=1,且总和=欧拉函数phi(n). 如果i与n ...

  8. POJ 1845 (约数和+二分等比数列求和)

    题目链接: http://poj.org/problem?id=1845 题目大意:A^B的所有约数和,mod 9901. 解题思路: ①整数唯一分解定理: 一个整数A一定能被分成:A=(P1^K1) ...

  9. HDU 1452 (约数和+乘法逆元)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1452 题目大意:求2004^X所有约数和,结果mod 29. 解题思路: ①整数唯一分解定理: 一个 ...

随机推荐

  1. Java 中最常见的 5 个错误

    在编程时,开发者经常会遭遇各式各样莫名错误.近日,Sushil Das 在 Geek On Java上列举了 Java 开发中常见的 5 个错误,与君共「免」. 原文链接:Top 5 Common M ...

  2. SiteView

    http://www.siteview.com/cms/sites/public/home.html

  3. JavaScript基础之函数与数组

     函数    函数的基本概念 为完成某一功能的程序指令(语句)的集合,称为函数.有的程序员把函数称为方法,希望大家不要被这两个名词搞晕了. 函数分为:自定义函数.系统函数(经常查看js帮助手册). j ...

  4. Gradle Goodness: Continue Build Even with Failed Tasks

    If we run a Gradle build and one of the tasks fails, the whole build stops immediately. So we have f ...

  5. hdu1715

    http://acm.hdu.edu.cn/showproblem.php?pid=1715 模板大数: #include <stdio.h> #include <string.h& ...

  6. spring PropertyPlaceholderConfigurer 找不到配置文件原因

    1:  spring 版本问题 参见: http://www.cnblogs.com/alex-blog/archive/2012/12/25/2832357.html 2: bean id 同名   ...

  7. 李洪强iOS开发之计算数组的最大最小值

    // //  ViewController.m //  A21 - 李洪强 - 输出参数 // //  Created by vic fan on 16/7/3. //  Copyright © 20 ...

  8. 二分法查找(大于,大于等于x的最小,小于,小于等于x的最大值)

    #include<stdio.h> #include<algorithm> using namespace std; //小于x的最大 //大于x的最小 //x的第一个 //x ...

  9. C++运算符重载——重载一元运算符

    0.重载一元操作符的方法 一元运算符即只需要一个操作用的运算符,如取地址运算符(&).复数(-).自减(--).自加(++)等. 运算符重载可以分为3种方式:类的非静态成员函数.类的友元函数. ...

  10. Why you have so few friends?

    Why you have so few friends?十个原因告诉你:为什么你的朋友那么少1. You Complain A Lot 你总是抱怨 If you’re constantly compl ...