zoukankan      html  css  js  c++  java
  • 洛谷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]='
    ';
    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 }
  • 相关阅读:
    PAT (Basic Level) Practise:1001. 害死人不偿命的(3n+1)猜想
    流加密法
    The NMEA 0183 Protocol
    USB 描述符
    网摘
    What are the 10 algorithms one must know in order to solve most algorithm challenges/puzzles?
    Why did Jimmy Wales invest in Quora? Is he afraid that it will take over Wikipedia?
    Add Binary
    Cocos2d-x 网络资源
    Cache
  • 原文地址:https://www.cnblogs.com/bztMinamoto/p/9613881.html
Copyright © 2011-2022 走看看