【CF103D】Time to Raid Cowavans(分块)
题意:
思路:院赛防AK题,然而还没来得及做就被数据出锅的题坑了……
1 #include<cstdio> 2 #include<cstring> 3 #include<string> 4 #include<cmath> 5 #include<iostream> 6 #include<algorithm> 7 #include<map> 8 #include<set> 9 #include<queue> 10 #include<vector> 11 #include<bitset> 12 #include<ctime> 13 using namespace std; 14 typedef long long ll; 15 typedef unsigned int uint; 16 typedef unsigned long long ull; 17 typedef pair<int,int> PII; 18 typedef vector<int> VI; 19 #define fi first 20 #define se second 21 #define MP make_pair 22 #define N 310000 23 #define M 51 24 #define MOD 1000000007 25 #define eps 1e-8 26 #define pi acos(-1) 27 #define oo 1e9 28 29 ll a[N],s[N],ans[N]; 30 int n; 31 32 struct node 33 { 34 int x,y,id; 35 }b[N]; 36 37 bool cmp(node a,node b) 38 { 39 return a.y<b.y; 40 } 41 42 int main() 43 { 44 int n; 45 scanf("%d",&n); 46 for(int i=1;i<=n;i++) scanf("%lld",&a[i]); 47 int q; 48 scanf("%d",&q); 49 for(int i=1;i<=q;i++) 50 { 51 scanf("%d%d",&b[i].x,&b[i].y); 52 b[i].id=i; 53 } 54 sort(b+1,b+q+1,cmp); 55 for(int i=1;i<=q;i++) 56 if(b[i].y<=(int)sqrt(n)) 57 { 58 if(i>1&&b[i].y==b[i-1].y) ans[b[i].id]=s[b[i].x]; 59 else 60 { 61 for(int j=1;j<=n;j++) s[j]=0; 62 for(int j=n;j>=1;j--) 63 { 64 s[j]=a[j]; 65 if(j+b[i].y<=n) s[j]+=s[j+b[i].y]; 66 } 67 ans[b[i].id]=s[b[i].x]; 68 } 69 } 70 else 71 { 72 ll t=0; 73 int j=b[i].x; 74 while(j<=n) 75 { 76 t+=a[j]; 77 j+=b[i].y; 78 } 79 ans[b[i].id]=t; 80 } 81 for(int i=1;i<=q;i++) printf("%lld\n",ans[i]); 82 return 0; 83 }
null