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 题意: 给一些面包,鸡肉,牛肉,你可以做成鸡肉汉堡或者牛肉汉堡并卖掉 一个鸡肉汉堡需要两个面包和一个鸡肉,牛肉汉堡需要两个面包和一个 ...
随机推荐
- 【C学习笔记】一
一.运算符优先级 逻辑非>算术运算符>关系运算符>逻辑运算符>赋值运算符>逗号运算符 逻辑运算符>条件运算符>赋值运算符 对于if的执行语句,如果是一条语句那 ...
- TeamViewer14试用版到期-怎么解决
Teamviewer14提示试用期已到期怎么办? 问题分析: 出现这种问题,是因为在安装是选择了[公司/商务用途]或者[以上都是]这两个选项中的一个 解决方法: 1.退出TeamViewer远程软件, ...
- 整理:WPF中Binding的几种写法
原文:整理:WPF中Binding的几种写法 目的:整理WPF中Bind的写法 <!--绑定到DataContext--> <Button Content="{Bindin ...
- WebAPI 权限控制解决方案——Phenix.NET企业应用软件快速开发平台.使用指南.21.WebAPI服务(三)
21.1 数据服务 21.1.1基本操作功能 Phenixヾ的数据服务,提供了如下的基本操作: 功能 Type URI 参数 完整获取实体集合对象 GET api/Data 分页获取实体集合对象 ...
- java log4j 打日志到控制台同时打印到不同文件
1.pom配置 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...
- Vue学习之过滤器和自定义指令小结(三)
过滤器: 过滤是一个数据经过了这个过滤之后出来另一样东西,可以是从中取得你想要的,或者给那个数据添加点什么装饰.过滤器就是过滤用的工具.渲染数据用的!!! 我们需要知道的是: 1.Vue中的过滤器不能 ...
- 英语fraunce法兰西
fraunce 外文词汇,中文翻译为代指法兰西(地名) 中文名:法兰西 外文名:fraunce 目录 释义 Fraunce 读音:英 [frɑ:ns] 美 [fræns] Noun(名词) 1. ...
- SpringBoot+Security+MyBatis+ES+MQ+Redis+Docker+Vue的电商系统
今天鹏哥给大家推荐的项目是一套电商系统,包括前台商城系统及后台管理系统,基于SpringBoot+MyBatis实现. 前台商城系统包含首页门户.商品推荐.商品搜索.商品展示.购物车.订单流程.会员中 ...
- Spark基于自定义聚合函数实现【列转行、行转列】
一.分析 Spark提供了非常丰富的算子,可以实现大部分的逻辑处理,例如,要实现行转列,可以用hiveContext中支持的concat_ws(',', collect_set('字段'))实现.但是 ...
- I tensorflow/core/platform/cpu_feature_guard.cc:142] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
遇到了这个问题,意思是你的 CPU 支持AVX AVX2 (可以加速CPU计算),但你安装的 TensorFlow 版本不支持 解决:1. 如果是初学者 或者 没有太大计算速度的需求,在开头加上这两行 ...