zoukankan      html  css  js  c++  java
  • 15th 浙江省赛 F Now Loading!!!

    DreamGrid has  integers . DreamGrid also has  queries, and each time he would like to know the value of

     

    for a given number , where .

    Input

    There are multiple test cases. The first line of input is an integer  indicating the number of test cases. For each test case:

    The first line contains two integers  and  () -- the number of integers and the number of queries.

    The second line contains  integers  ().

    The third line contains  integers  ().

    It is guaranteed that neither the sum of all  nor the sum of all  exceeds .

    Output

    For each test case, output an integer , where  is the answer for the -th query.

    Sample Input

    2
    3 2
    100 1000 10000
    100 10
    4 5
    2323 223 12312 3
    1232 324 2 3 5
    

    Sample Output

    11366
    45619
    思路:排序后预处理a[i] / k的前缀和,查询时二分求出相同的一段区间。复杂度O(n*k+ nlogn),k小于32
     1 #include <iostream>
     2 #include <fstream>
     3 #include <sstream>
     4 #include <cstdlib>
     5 #include <cstdio>
     6 #include <cmath>
     7 #include <string>
     8 #include <cstring>
     9 #include <algorithm>
    10 #include <queue>
    11 #include <stack>
    12 #include <vector>
    13 #include <set>
    14 #include <map>
    15 #include <list>
    16 #include <iomanip>
    17 #include <cctype>
    18 #include <cassert>
    19 #include <bitset>
    20 #include <ctime>
    21 
    22 using namespace std;
    23 
    24 #define pau system("pause")
    25 #define ll long long
    26 #define pii pair<int, int>
    27 #define pb push_back
    28 #define mp make_pair
    29 #define clr(a, x) memset(a, x, sizeof(a))
    30 
    31 const double pi = acos(-1.0);
    32 const int INF = 0x3f3f3f3f;
    33 const int MOD = 1e9;
    34 const double EPS = 1e-9;
    35 
    36 /*
    37 #include <ext/pb_ds/assoc_container.hpp>
    38 #include <ext/pb_ds/tree_policy.hpp>
    39 
    40 using namespace __gnu_pbds;
    41 tree<pli, null_type, greater<pli>, rb_tree_tag, tree_order_statistics_node_update> T;
    42 */
    43 
    44 int t, n, m;
    45 ll a[100015], sum[100015][30];
    46 int get_pos(int sta, ll tt) {
    47     int s = sta, e = n, mi, res = sta - 1;
    48     while (s <= e) {
    49         mi = s + e >> 1;
    50         if (a[mi] <= tt) {
    51             s = (res = mi) + 1;
    52         } else {
    53             e = mi - 1;
    54         }
    55     }
    56     //printf("sta = %d, tt = %lld, res = %d
    ", sta, tt, res);
    57     return res;
    58 }
    59 int main() {
    60     scanf("%d", &t);
    61     while (t--) {
    62         scanf("%d%d", &n, &m);
    63         for (int i = 1; i <= n; ++i) {
    64             scanf("%lld", &a[i]);
    65         }
    66         sort(a + 1, a + n + 1);
    67         for (int k = 1; k <= 30; ++k) {
    68             for (int i = 1; i <= n; ++i) {
    69                 sum[i][k] = sum[i - 1][k] + a[i] / k;
    70             }
    71         }
    72         ll res = 0;
    73         for (int rep = 1; rep <= m; ++rep) {
    74             ll ans = 0, p;
    75             scanf("%lld", &p);
    76             ll tt = p;
    77             for (int i = 1, j = 1; i <= n; ) {
    78                 int pos = get_pos(i, tt);
    79                 ans += sum[pos][j] - sum[i - 1][j];
    80                 ++j;
    81                 tt *= p;
    82                 i = pos + 1;
    83                 //printf("pos = %d, tt = %lld, i = %d
    ", pos, tt, i);
    84             }
    85             res = (res + ans % MOD * rep) % MOD;
    86         }
    87         printf("%lld
    ", res);
    88     }
    89     return 0;
    90 }
    View Code
  • 相关阅读:
    C# 获取文件名、无后缀文件名、扩展名
    navicat for oracle 导入xlsx文件提示无法打开xlsx文件
    复制的文件不能粘贴到远程的服务器上
    使用.bat 批量将部分文件迁移到新的路径下
    sql sever 查询用户所有的表和各个表数据量
    orecle 查询数量 union合并 的排序问题
    oracle 如何将带有,的一列分成多列
    java中selenium判断某个元素是否存在
    docker安装Ubuntu以及ssh连接
    Java8 将List<JavaBean>中某个属性取出来为单独的一个集合List<String>
  • 原文地址:https://www.cnblogs.com/BIGTOM/p/8971736.html
Copyright © 2011-2022 走看看