CodeForces - 1207F Remainder Problem(分块)
题目链接:点击查看
题目大意:给出一个长度为 500000500000500000 的数组,初始时全部为 000,需要执行 nnn 次操作,每次操作分为两种类型:
- 1xy1 \ x \ y1 x y:ax+=ya_x+=yax+=y
- 2xy2 \ x \ y2 x y:统计∑i∈R(x,y)ai\sum_{i \in R(x,y)}a_i∑i∈R(x,y)ai,其中 R(x,y)R(x,y)R(x,y) 是 [1,500000][1,500000][1,500000] 中对 xxx 取余等于 yyy 的位置
题目分析:考虑根号分块,即小范围暴力大范围通过预处理获得,当 x≤500000x \le \sqrt {500000}x≤500000 时,直接维护一个前缀和 sumi,jsum_{i,j}sumi,j 代表 x=i,y=jx = i,y = jx=i,y=j 时的答案;当 x≥500000x \ge \sqrt {500000}x≥500000 时,暴力查询的时间复杂度是 500000\sqrt {500000}500000
考虑修改,每次直接暴力修改 sumsumsum 数组即可,时间复杂度同样是 500000\sqrt {500000}500000 的,所以这个题分块实现两个操作的时间复杂度均摊下来就是 O(nn)O(n\sqrt n)O(nn) 的
代码:
// #pragma GCC optimize(2)
// #pragma GCC optimize("Ofast","inline","-ffast-math")
// #pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#include<bitset>
#include<unordered_map>
using namespace std;
typedef long long LL;
typedef unsigned long long ull;
template<typename T>
inline void read(T &x)
{T f=1;x=0;char ch=getchar();while(0==isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}while(0!=isdigit(ch)) x=(x<<1)+(x<<3)+ch-'0',ch=getchar();x*=f;
}
template<typename T>
inline void write(T x)
{if(x<0){x=~(x-1);putchar('-');}if(x>9)write(x/10);putchar(x%10+'0');
}
const int inf=0x3f3f3f3f;
const int N=1e6+100;
LL sum[1010][1010],a[N];
int main()
{#ifndef ONLINE_JUDGE
// freopen("data.in.txt","r",stdin);
// freopen("data.out.txt","w",stdout);
#endif
// ios::sync_with_stdio(false);int n;read(n);for(int i=1;i<=n;i++){int op,x,y;read(op),read(x),read(y);if(op==1){for(int i=1;i<=1000;i++) sum[i][x%i]+=y;a[x]+=y;}else{if(x<=1000) write(sum[x][y]),putchar('\n');else{LL ans=0;for(int i=y;i<=500000;i+=x) ans+=a[i];write(ans),putchar('\n');}}}return 0;
}
CodeForces - 1207F Remainder Problem(分块)相关推荐
- CF-1207 F. Remainder Problem(分块)
CF-1207 F. Remainder Problem(分块) 题目链接 题意 一共5e5个数字,两种操作: 1 x y , a[x] += y 2 x y , ∑i∈nai,n∈[1,5e5],n ...
- Codeforces 1375H Set Merging (分块)
题目链接 https://codeforces.com/contest/1375/problem/H 题解 首先注意到 \(2.2\times 10^6\approx 2n\sqrt q\),因此想到 ...
- Codeforces Gym 100342J Problem J. Triatrip 求三元环的数量 bitset
Problem J. Triatrip Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/gym/100342/at ...
- CodeForces - 29A - Spit Problem
题目出处:codeforces - 29A A. Spit Problem time limit per test 2 seconds memory limit per test 256 megaby ...
- CodeForces - 29A Spit Problem【水题】
题目链接:https://codeforces.com/contest/29/problem/A #include <iostream> #include <cstdio> # ...
- Codeforces Gym 100623I Problem I. Important Wires
题目传送门:http://codeforces.com/gym/100623/attachments 题解:这道题...说了一大堆没用的....如果你看了题不会做再看代码...你会大喊我去.... C ...
- Codeforces Contest 1092 problem D1 Great Vova Wall (Version 1)
Vova's family is building the Great Vova Wall (named by Vova himself). Vova's parents, grandparents, ...
- Codeforces Contest 1081 problem D Maximum Distance —— 并查集
Chouti was tired of the tedious homework, so he opened up an old programming problem he created year ...
- CodeForces - 1096D Easy Problem(线性dp)
题目链接:点击查看 题目大意:给出一个字符串,每个字符都有一个权值,现在需要删除权值和最少的字符,满足字符串中不再含有子序列"hard" 题目分析:线性dp,但我不会,看着题解写的 ...
最新文章
- Linux基础:Shell脚本学习
- EASYHOOK逆向寒假生涯(20/100)
- 爬取虎牙之二:试用htmlunit模拟js爬取ajax页面
- .[转] 几米语录 生活永远不是童话
- java钩子函数(hook)以spring源码为例
- 按照 排序 oracle,oracle 按照中文排序
- [BUUCTF-pwn]——picoctf_2018_buffer overflow 1
- 领域驱动设计,让程序员心中有码(二)
- Fiddler改包场景04——先拦截请求,修改请求,再拦截响应,修改响应,放行响应
- centos下java编程工具_centos下安装JAVA开发工具(4)------Redis
- element UI实现动态生成多级表头
- ActiveMQ消息队列
- 前端学习笔记 - 移动端Web开发
- 调度系统核心算法第一篇-交通管制
- PAT(甲级)2020年春季考试 7-2 The Judger (25分)
- 在JAVA中如何求Decimal的相反数,如何求Decimal的负数
- vb打开服务器excel文件,vb打开、操作并且关闭EXCEL
- FFmpeg使用滤镜链为视频插入多张图片
- AWS免费套餐服务器部署NET CORE网站
- ZOJ Monthly,Feburary 2012 部分题解
热门文章
- 大牛推荐的5本 Linux 经典必读书
- MySQL语法规范介绍
- MySQL高级 - 查询缓存 - 配置参数
- 缓存-SpringCache-原理与不足
- BufferedInputStream_字节缓冲输入流
- ServletContext_功能_获取MIME类型
- 长江大学微型计算机课设报告,长江大学B第一学期计算机基础试卷.doc
- K8S之HELM详细介绍
- 语音控制面板 通过linux_在Linux中,通常把设备作为( )来处理.
- axios nodejs 上传图片_vue项目中使用axios上传图片等文件操作