[传送门]

题意就是单点加以及查询下标为等差数列位置上的值之和。
刚开始看到这道题。我以为一个数的倍数是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. 63 网络编程(四)——TCP编程

    TCP编程 TCP编程是面向连接的数据传输,所以需要时用IO流来建立连接. 用户输出流到服务器,服务器输入流接收数据. 服务器输出流到用户,用户输入流接收. 基本流程 服务器端 创建服务器端:Serv ...

  2. 关于mysql的null相关查询的一些坑

    我们先看一下效果,然后在解释,示例如下: mysql> create table test5 (a int not null,b int,c varchar(10)); Query OK, 0 ...

  3. 搞清楚一道关于Integer的面试题【华为云技术分享】

    请看题1: public class IntegerDemo { public static void main(String[] args) { Integer a = ; Integer b = ...

  4. What Is HLS (HTTP Live Streaming)?

    HTTP Live Streaming  (HLS) Executive Summary HTTP Live Streaming (or HLS) is an adaptive streaming c ...

  5. Excel转换成xml文件

    namespace ExcelToXml { class Program { [STAThread] static void Main(string[] args) { Program program ...

  6. 1.0EnterpriseFrameWork 框架学习

    1.先报其主页 :博主的框架是开源的 http://www.cnblogs.com/kakake/p/3938262.html . 2.学习的精髓是:该框架支持 ORM.SQL语句 和 存储过程 ,O ...

  7. vs2015下编译免费开源的jpeg库,ijg的jpeg.lib

    vs2015下编译免费开源的jpeg库,ijg的jpeg.lib 1. 去Independent JPEG Group官网www.ijg.org下载jpegsrc,我下载的版本是jpegsrc9c.z ...

  8. [Leetcode] 1120. Maximum Average Subtree

    Given the root of a binary tree, find the maximum average value of any subtree of that tree. (A subt ...

  9. C# 网络连接中异常断线的处理:ReceiveTimeout, SendTimeout 及 KeepAliveValues(设置心跳)

    C# 网络连接中异常断线的处理:ReceiveTimeout, SendTimeout 及 KeepAliveValues(设置心跳) 在使用 TcpClient 网络连接中常常会发生客户端连接异常断 ...

  10. HDOJ 6664 Andy and Maze

    HDOJ题目页面传送门 给定一个无向带权图\(G=(V,E),|V|=n,|E|=m\),求边权之和最大的有\(s\)个节点的链的边权之和,即求\(\max\limits_{\forall i\in[ ...