CF1207 F - Remainder Problem 分块

博客介绍了如何使用分块思想解决CF1207F问题,涉及单点更新和模数相关查询。当模数大于平方根(n)时,采用暴力方法,复杂度为n/sqrt(n);当模数小于平方根(n)时,通过预处理mo[x][y]数组,达到O(n)复杂度。通过分块技巧可以有效处理这类问题。
摘要由CSDN通过智能技术生成

单点更新,

每次查询所有id 为模x余y  的和。

当模数大于sqrt(n)时,暴力,所有满足条件的数,复杂度 n/sqrt(n).

当模数小于sqrt(n)时,预处理出 mo[x][y], 复杂度O n , 数组开到[708][708]

分块思想,即可解决这题。

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ls (o<<1)
#define rs (o<<1|1)
#define pb push_back
const double PI= acos(-1.0);
const int M = 5e5+7;
/*
int head[M],cnt;
void init(){cnt=0,memset(head,0,sizeof(head));}
struct EDGE{int to,nxt,w;}ee[M*2];
void add(int x,int y,int w){ee[++cnt].nxt=head[x],ee[cnt].w=w,ee[cnt].to=y,head[x]=cnt;}
*/
int mo[708][708];
int a[M];
int main()
{
	ios::sync_with_stdio(false);
  	cin.tie(0);
  	int q;
  	//cout<<sqrt(M)<<endl;
  	cin>>q;
  	while(q--)
  	{
  		int t,x,y;
  		cin>>t>>x>>y;
  		int tp=707;
  		if(t==1)
  		{
  			a[x]+=y;
  			for(int i=1;i<
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值