[传送门]

题意就是单点加以及查询下标为等差数列位置上的值之和。
刚开始看到这道题。我以为一个数的倍数是log级别的。就直接写了发暴力。就T了。还在想为啥,优化了几发才发现不太对劲。
然后才想到是$\dfrac {n}{x}$级别的。不过看到$\dfrac {n}{x}$应该就出来了。
当$x \leq \sqrt n$时用$sum[i][j]$表示公差为$i$,首项为$j$的和。修改时可以$O(\sqrt n)$修改,查询就可以$O(1)$了。
当$x > \sqrt n$时直接暴力就行了。

#include <bits/stdc++.h>
using namespace std; const int N = 5e5;
int sum[][];
int a[N + ]; int main() {
int q;
scanf("%d", &q);
while (q--) {
int opt, x, y;
scanf("%d%d%d", &opt, &x, &y);
if (opt == ) {
a[x] += y;
for (int i = ; i <= ; i++) {
sum[i][x % i] += y;
}
} else {
if (x > ) {
int ans = ;
for (int i = y; i <= N; i += x) ans += a[i];
printf("%d\n", ans);
} else {
printf("%d\n", sum[x][y]);
}
}
}
return ;
}

Educational Codeforces F. Remainder Problem的更多相关文章

  1. Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案

    Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...

  2. Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心

    After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...

  3. Educational Codeforces Round 21 Problem D(Codeforces 808D)

    Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into t ...

  4. Educational Codeforces Round 21 Problem A - C

    Problem A Lucky Year 题目传送门[here] 题目大意是说,只有一个数字非零的数是幸运的,给出一个数,求下一个幸运的数是多少. 这个幸运的数不是最高位的数字都是零,于是只跟最高位有 ...

  5. Educational Codeforces Round 32 Problem 888C - K-Dominant Character

    1) Link to the problem: http://codeforces.com/contest/888/problem/C 2) Description: You are given a ...

  6. Codeforces Educational Codeforces Round 17 Problem.A kth-divisor (暴力+stl)

    You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist ...

  7. Educational Codeforces Round 71 (Rated for Div. 2)

    传送门 A.There Are Two Types Of Burgers 签到. B.Square Filling 签到 C.Gas Pipeline 每个位置只有"高.低"两种状 ...

  8. Educational Codeforces Round 71

    https://www.cnblogs.com/31415926535x/p/11460682.html 上午没课,做一套题,,练一下手感和思维,,教育场的71 ,,前两到没啥,,后面就做的磕磕巴巴的 ...

  9. Educational Codeforces Round 71 (Rated for Div. 2) Solution

    A. There Are Two Types Of Burgers 题意: 给一些面包,鸡肉,牛肉,你可以做成鸡肉汉堡或者牛肉汉堡并卖掉 一个鸡肉汉堡需要两个面包和一个鸡肉,牛肉汉堡需要两个面包和一个 ...

随机推荐

  1. scratch教程:学做控制类积木

    少儿编程中scratch很容易被小孩所接受,不管是从外观还是教程中,都符合少儿的兴趣,为此现在只要是开少儿编程课都会有scratch课程,今天娜娜姐小码王scratch培训机构就为大家分享,scrat ...

  2. [翻译] InfluxDB 存储机制解析

    原文地址: https://medium.com/dataseries/analysis-of-the-storage-mechanism-in-influxdb-b84d686f3697 TODO

  3. Lodash之throttle(节流)与debounce(防抖)总结

    全手打原创,转载请标明出处:https://www.cnblogs.com/dreamsqin/p/11305028.html 先重点说一下可能遇到的坑:主要在原本默认参数的设置以及两个方法的选择上, ...

  4. kubectl rollout回滚和autoscale自动扩容

    系列目录 kubernetes 滚动升级 Kubernetes 中采用ReplicaSet(简称RS)来管理Pod.如果当前集群中的Pod实例数少于目标值,RS 会拉起新的Pod,反之,则根据策略删除 ...

  5. asp.net core mvc 集成miniprofiler

    原文:asp.net core mvc 集成miniprofiler asp.net core mvc 集成miniprofiler 一.环境介绍 二.监控asp.net 页面 三.监控执行的sql语 ...

  6. laravel hash密码生成和密码验证

    在laravel中 登录表单中的密码是用hash来生成的. 在生成密码需要用到 laravel框架中的方法(都是laravel封装好了的) bcrypt($password)方法,直接将获取到的pas ...

  7. 冒泡排序法vs快速排序法

    闲着没事,想思考一下两种排序法的直观对比,写了个小程序,代码如下,分析见后面: class Program { static DateTime t1, t2; static TimeSpan ts1, ...

  8. rsync 排除指定目录

    背景 将Server1上的数据同步到Server2: Server1目录结构: /us_data/yahoo └── qlib ├── calendars ├── dataset_cache ├── ...

  9. 【Java】调用摄像头进行拍照并保存【详细】以及处理no jniopencv_core in java.library.path的一种方法

    [之前困扰笔者的问题描述]   date:2019.12.18 网上教程很多,但是没有看见完整的,所以写一个出来. 调用摄像头需要javaCV的jar包和openCV的jar包,现在已经不需要安装包了 ...

  10. 前端1-----A标签 (锚点)

    Title 头部,顶端, 点击跳转到id='abc' 1 2 到百度这里,点击跳转百度 3 到这里了 4 alex1 5 6 根据id 从底部到头      根据id='a1' 到指定位置      ...