Educational Codeforces F. Remainder Problem
[传送门]
题意就是单点加以及查询下标为等差数列位置上的值之和。
刚开始看到这道题。我以为一个数的倍数是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的更多相关文章
- 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 ...
- Educational Codeforces Round 21 Problem E(Codeforces 808E) - 动态规划 - 贪心
After several latest reforms many tourists are planning to visit Berland, and Berland people underst ...
- 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 ...
- Educational Codeforces Round 21 Problem A - C
Problem A Lucky Year 题目传送门[here] 题目大意是说,只有一个数字非零的数是幸运的,给出一个数,求下一个幸运的数是多少. 这个幸运的数不是最高位的数字都是零,于是只跟最高位有 ...
- 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 ...
- 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 ...
- Educational Codeforces Round 71 (Rated for Div. 2)
传送门 A.There Are Two Types Of Burgers 签到. B.Square Filling 签到 C.Gas Pipeline 每个位置只有"高.低"两种状 ...
- Educational Codeforces Round 71
https://www.cnblogs.com/31415926535x/p/11460682.html 上午没课,做一套题,,练一下手感和思维,,教育场的71 ,,前两到没啥,,后面就做的磕磕巴巴的 ...
- Educational Codeforces Round 71 (Rated for Div. 2) Solution
A. There Are Two Types Of Burgers 题意: 给一些面包,鸡肉,牛肉,你可以做成鸡肉汉堡或者牛肉汉堡并卖掉 一个鸡肉汉堡需要两个面包和一个鸡肉,牛肉汉堡需要两个面包和一个 ...
随机推荐
- [转帖]ps 命令详解
ps 命令详解 https://www.jianshu.com/p/cba22cce2f97 ps 概述 Linux中的ps命令是Process Status的缩写.ps命令用来列出系统中当前运行的那 ...
- 最新修改Oracle10gscott用户
1.以system登录及输入自己设置口令; 2.更换sysdba身份: conn system/orcl as sysdba; 3.解锁scott用户(因装好默认是锁定的): alter user s ...
- Golang解析、验证、修改URL之Host、Port、Path
URL解析验证问题 net.ParseIP()只能解析不带冒号以及端口号的IP4/IP6 ✔: 127.0.0.1.2001:db8::68 ✖: 127.0.0.1:8080.www.baidu.c ...
- Scala 匹配模式
模式匹配 // Scala是没有Java中的switch case语法的,相对应的,Scala提供了更加强大的match case语法,即模式匹配,类替代switch case,match case也 ...
- 乘法器——Wallace树型乘法器
博主最近在看乘法器相关的知识,发现现在用的比较多的是booth编码的乘法器和Wallace树型乘法器,当然两者并不是互斥的关系,他们也可以结合使用.在这里给大家介绍一下Wallace树型乘法器,希望能 ...
- TCMalloc - 细节
1,释放速度控制 在将一个Span删除掉的时候,会优先将它加入到normal队列中,这之后会尝试从normal队列中释放一部分同样大小的内存给系统. 释放内存给系统的时候,tcmalloc使用了一个延 ...
- linux - 用户配置文件
用户配文件: 1用户信息文件 /etc/passwd 2 影子文件 /etc/shadow 3 组信息文件 /etc/group 4 组密码文件 /etc/gshadow 1 用户信息文件 / ...
- 『摆渡车 斜率优化dp及总结』
摆渡车的题解我已经写过一遍了,在这里,这次主要从斜率优化的角度讲一下摆渡车,并总结一下斜率优化会出现的一些奇奇怪怪的错误. 摆渡车 Description 有 n 名同学要乘坐摆渡车从人大附中前往人民 ...
- 解决IE下打印iframe时,页面比例变小的问题
$('#reportFrame')[0].contentWindow.printMyself();//主页面调用iframe里的打印方法 //reportFrame里的方法 function prin ...
- Vertx的命令行
IntelliJ----创建一个运行配置(Application), 用io.vertx.core.Launcher类作为主类,在程序参数输入:run your-verticle-fully-qual ...