洛谷P3396 哈希冲突(分块)

传送门

 

 

题解在此,讲的蛮清楚的->这里

我就贴个代码

 1 //minamoto
 2 #include<iostream>
 3 #include<cstdio>
 4 #include<cmath>
 5 using namespace std;
 6 #define getc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
 7 char buf[1<<21],*p1=buf,*p2=buf;
 8 inline int read(){
 9     #define num ch-'0'
10     char ch;bool flag=0;int res;
11     while(!isdigit(ch=getc()))
12     (ch=='-')&&(flag=true);
13     for(res=num;isdigit(ch=getc());res=res*10+num);
14     (flag)&&(res=-res);
15     #undef num
16     return res;
17 }
18 char sr[1<<21],z[20];int C=-1,Z;
19 inline void Ot(){fwrite(sr,1,C+1,stdout),C=-1;}
20 inline void print(int x){
21     if(C>1<<20)Ot();if(x<0)sr[++C]=45,x=-x;
22     while(z[++Z]=x%10+48,x/=10);
23     while(sr[++C]=z[Z],--Z);sr[++C]='\n';
24 }
25 inline char getop(){
26     char ch;
27     while((ch=getc())!='A'&&ch!='C');
28     return ch;
29 }
30 const int N=150005,M=2005;
31 int ans[M][M],v[N],s,n,m;
32 int main(){
33 //    freopen("testdata.in","r",stdin);
34     n=read(),m=read(),s=pow(n,0.3333);
35     for(int i=1;i<=n;++i){
36         v[i]=read();
37         for(int j=1;j<=s;++j)
38         ans[j][i%j]+=v[i];
39     }
40     while(m--){
41         char op=getop();int x=read(),y=read();
42         switch(op){
43             case 'A':{
44                 if(x<=s) print(ans[x][y%x]);
45                 else{
46                     int res=0;
47                     for(int i=y;i<=n;i+=x) res+=v[i];
48                     print(res);
49                 }
50                 break;
51             }
52             case 'C':{
53                 for(int i=1;i<=s;++i) ans[i][x%i]+=y-v[x];
54                 v[x]=y;
55                 break;
56             }
57         }
58     }
59     Ot();
60     return 0;
61 }

 

转载于:https://www.cnblogs.com/bztMinamoto/p/9613881.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值