码迷,mamicode.com
首页 > 其他好文 > 详细

Turtles (非纯分块)

时间:2018-09-08 22:42:15      阅读:179      评论:0      收藏:0      [点我收藏+]

标签:type   iss   using   tle   ||   problem   clu   turn   from   

http://codeforces.com/contest/103/problem/D

 1 #include <bits/stdc++.h>
 2 using namespace std;
 3 typedef long long ll;
 4 #define faster ios::sync_with_stdio(0);cin.tie(0)
 5 
 6 inline ll read()
 7 {
 8     int x=0,f=1;char ch=getchar();
 9     while(ch<0||ch>9){if(ch==-)f=-1;ch=getchar();}
10     while(ch>=0&&ch<=9){x=x*10+ch-0;ch=getchar();}
11     return x*f;
12 }
13 
14 /********************************************************************/
15 
16 const int maxn = 3e5+5;
17 ll n, m;
18 ll a[maxn];
19 ll cx[maxn], cy[maxn];
20 int kiss = 600;
21 vector<int> d[600];
22 ll dp[maxn];
23 ll ans[maxn];
24 
25 int main(){
26     n = read();
27     for(int i = 1;i <= n;i++)
28         a[i] = read();
29     m = read();
30     for(int i = 1;i <= m;i++){
31         cx[i] = read(), cy[i] = read();
32         if(cy[i] < kiss)
33             d[cy[i]].push_back(i);
34         else{
35             ll ans1 = 0;
36             for(int j = cx[i];j <= n;j += cy[i]){
37                 ans1 += a[j];
38             }
39             ans[i] = ans1;
40         }
41     }
42     for(int i= 1;i < kiss;i++){
43         if(d[i].size()){
44             for(int j = n;j;j--){       //From the back forward
45                 if(j+i > n)
46                     dp[j] = a[j];
47                 else
48                     dp[j] = dp[j+i] + a[j];
49             }
50             for(int j = 0;j < d[i].size();j++)
51                 ans[d[i][j]] = dp[cx[d[i][j]]];
52         }
53     }
54     for(int i = 1;i <= m;i++)
55         cout << ans[i] << endl;
56     return 0;
57 }

 

Turtles (非纯分块)

标签:type   iss   using   tle   ||   problem   clu   turn   from   

原文地址:https://www.cnblogs.com/jaydenouyang/p/9610335.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!