zoukankan      html  css  js  c++  java
  • P3396 哈希冲突(思维+方块)

    题目

    P3396 哈希冲突

    做法

    预处理模数([1,sqrt{n}])的内存池,(O(nsqrt{n}))

    查询模数在范围里则直接输出,否则模拟(O(msqrt{n}))

    修改则遍历模数([1,sqrt{n}]),复杂度(O(msqrt{n}))

    Code

    #include<bits/stdc++.h>
    typedef int LL;
    const LL maxn=2e5+9;
    inline LL Read(){
    	LL x(0),f(1); char c=getchar();
    	while(c<'0' || c>'9'){
    		if(c=='-') f=-1; c=getchar();
    	}
    	while(c>='0' && c<='9'){
    		x=(x<<3ll)+(x<<1ll)+c-'0'; c=getchar();
    	}return x*f;
    }
    LL n,m;
    LL a[maxn],sum[509][509];
    int main(){
    	n=Read(); m=Read();
    	for(LL i=1;i<=n;++i) a[i]=Read();
    	LL up(sqrt(n));
    	for(LL i=1;i<=n;++i)
    		for(LL j=1;j<=up;++j) sum[j][i%j]+=a[i];
    	while(m--){
    		char c; scanf(" %c",&c);
    		LL x(Read()),y(Read());
    		if(c=='A'){
    			if(x<=up) printf("%d
    ",sum[x][y]);
    			else{
    				LL ret(0);
    				for(LL i=y;i<=n;i+=x) ret+=a[i];
    				printf("%d
    ",ret);
    			}
    		}else{
    			for(LL j=1;j<=up;++j) sum[j][x%j]-=a[x],sum[j][x%j]+=y;
    			a[x]=y;
    		}
    	}
    	return 0;
    }
    
  • 相关阅读:
    The requested resource (/) is not available解决办法
    字符问题
    Unknown column in 'field list'
    table 和 div 简单布局
    css简介
    div 与 table 的优点
    瞎搞
    html
    小计--关联 复制表结构
    ddl dml dcl
  • 原文地址:https://www.cnblogs.com/y2823774827y/p/11121598.html
Copyright © 2011-2022 走看看