一、题目

  D2. Submarine in the Rybinsk Sea (hard edition)

二、分析

  相比于简单版本,它的复杂地方在于对于不同长度,可能对每个点的贡献可能是有差异的。

  但是,题目已经说明$a_{i}$最大知道10的9次方,那么$a_{i}$的长度最大也只有10,所以,我们可以按长度进行分组讨论。

  需要注意的是,$a_{i}$确定了在前和在后并且确定了$f(a_{i},b_{i})$中的$b_{i}$的长度后,$a_{i}$对各个位置的贡献其实就确定了,相当于对于每一个$a_{i}$,我们最多求10次贡献就可以了。

三、AC代码

  1 #include <bits/stdc++.h>
2
3 using namespace std;
4 typedef long long ll;
5 const int maxn = 1e5 + 14;
6 const int mod = 998244353;
7 int a[maxn], n;
8
9 int getlen(int data)
10 {
11 int len = 0;
12 while(data)
13 {
14 data/=10;
15 len++;
16 }
17 return len;
18 }
19
20 ll fun1(int x, int a, int b)
21 {
22 vector<int> vec, A(22, 0);
23 while(x)
24 {
25 vec.push_back(x % 10);
26 x /= 10;
27 }
28 reverse(vec.begin(), vec.end());
29 int _len = a + b;
30 if(a >= b)
31 {
32 auto itr = vec.begin();
33 for(int i = 1; i <= a - b + 1; i++)
34 {
35 A[i] = *itr;
36 itr++;
37 }
38 for(int i = a - b + 3; i <= _len; i += 2)
39 {
40 A[i] = *itr;
41 itr++;
42 }
43 }
44 else
45 {
46 auto itr = vec.begin();
47 for(int i = b - a + 1; i <= _len; i += 2)
48 {
49 A[i] = *itr;
50 itr++;
51 }
52 }
53 ll tot = 0;
54 for(int i = 0; i <= _len; i++)
55 {
56 tot = (tot * 10 + A[i]) % mod;
57 }
58 return tot;
59 }
60
61 ll fun2(int x, int b, int a)
62 {
63 vector<int> vec, A(22, 0);
64 while(x)
65 {
66 vec.push_back(x % 10);
67 x /= 10;
68 }
69 reverse(vec.begin(), vec.end());
70 int _len = a + b;
71 if(b <= a)
72 {
73 auto itr = vec.begin();
74 for(int i = 1; i <= a - b; i++)
75 {
76 A[i] = *itr;
77 itr++;
78 }
79 for(int i = a - b + 2; i <= _len; i += 2)
80 {
81 A[i] = *itr;
82 itr++;
83 }
84 }
85 else
86 {
87 auto itr = vec.begin();
88 for(int i = b - a + 2; i <= _len; i += 2)
89 {
90 A[i] = *itr;
91 itr++;
92 }
93 }
94 ll tot = 0;
95 for(int i = 0; i <= _len; i++)
96 {
97 tot = (tot * 10 + A[i]) % mod;
98 }
99 return tot;
100 }
101
102 int main()
103 {
104 while(scanf("%d", &n) != EOF)
105 {
106 ll ans = 0;
107 vector<int> vec[11];
108 for(int i = 0; i < n; i++)
109 {
110 scanf("%d", &a[i]);
111 vec[ getlen( a[i] ) ].push_back(a[i]);
112 }
113 for(int i = 1; i <= 10; i++)
114 {
115 for(auto itr : vec[i])
116 {
117 for(int j = 1; j <= 10; j++)
118 {
119 if( vec[j].size() )
120 {
121 ll res = 0;
122 int len = vec[j].size();
123 res = fun1(itr, i, j);
124 res = (res + fun2(itr, j, i)) % mod;
125 res = res * len % mod;
126 ans = (ans + res) % mod;
127 }
128 }
129 }
130 }
131 printf("%I64d\n", ans);
132 }
133 return 0;
134 }

Codeforces Round #574 (Div. 2) D2. Submarine in the Rybinsk Sea (hard edition) 【计算贡献】的更多相关文章

  1. Codeforces Round #574 (Div. 2) D1. Submarine in the Rybinsk Sea (easy edition) 【计算贡献】

    一.题目 D1. Submarine in the Rybinsk Sea (easy edition) 二.分析 简单版本的话,因为给定的a的长度都是定的,那么我们就无需去考虑其他的,只用计算ai的 ...

  2. Codeforces Round #574 (Div. 2)

    目录 Contest Info Solutions A. Drinks Choosing B. Sport Mafia C. Basketball Exercise D1. Submarine in ...

  3. Codeforces Round #574 (Div. 2) A~E Solution

    A. Drinks Choosing 有 $n$ 个人,每个人各有一种最喜欢的饮料,但是买饮料的时候只能同一种的两个两个买(两个一对) 学校只打算卖 $\left \lceil \frac{n}{2} ...

  4. Codeforces Round #574 (Div. 2)补题

    A. Drinks Choosing 统计每种酒有多少人偏爱他们. ki 为每种酒的偏爱人数. 输出ans = (n + 1)/2 >  Σki / 2 ? (n + 1)/2 - Σki / ...

  5. Codeforces Round #350 (Div. 2) D2. Magic Powder - 2

    题目链接: http://codeforces.com/contest/670/problem/D2 题解: 二分答案. #include<iostream> #include<cs ...

  6. Codeforces Round #527 (Div. 3) D2. Great Vova Wall (Version 2) 【思维】

    传送门:http://codeforces.com/contest/1092/problem/D2 D2. Great Vova Wall (Version 2) time limit per tes ...

  7. Codeforces Round #350 (Div. 2) D2 二分

    五一期间和然然打的团队赛..那时候用然然的号打一场掉一场...七出四..D1是个数据规模较小的题 写了一个暴力过了 面对数据如此大的D2无可奈何 现在回来看 一下子就知道解法了 二分就可以 二分能做多 ...

  8. Codeforces Round #594 (Div. 1) D2. The World Is Just a Programming Task (Hard Version) 括号序列 思维

    D2. The World Is Just a Programming Task (Hard Version) This is a harder version of the problem. In ...

  9. Codeforces Round #575 (Div. 3) D2. RGB Substring (hard version) 水题

    D2. RGB Substring (hard version) inputstandard input outputstandard output The only difference betwe ...

随机推荐

  1. 爬虫入门五 gooseeker

    title: 爬虫入门五 gooseeker date: 2020-03-16 16:00:00 categories: python tags: crawler gooseeker是一个简单的爬虫软 ...

  2. codeforces 1009D Relatively Prime Graph【欧拉函数】

    题目:戳这里 题意:要求构成有n个点,m条边的无向图,满足每条边上的两点互质. 解题思路: 显然1~n这n个点能构成边的条数,就是2~n欧拉函数之和(x的欧拉函数值代表小于x且与x互质的数的个数. 因 ...

  3. int、long long等的取值范围

    unsigned   int   0-4294967295   int   -2147483648-2147483647 unsigned long 0-4294967295long   -21474 ...

  4. 2019牛客多校第六场H Pair(数位DP 多个数相关)题解

    题意: 传送门 给你\(A,B,C\),要求你给出有多少对\((x, y)\)满足\(x\in [1,A],y\in [1,B]\),且满足以下任意一个条件:\(x \& y > C\) ...

  5. 关于Matlab GUI的一些经验总结

    注:此文来自转载,侵删去年做了一些关于Matlab GUI的程序,现在又要做相关的东西,回想起来,当时很多经验没有记录下来,现在回顾起来始终觉得不爽,所以从现在开始,一定要勤写记录. 从简单的例子说起 ...

  6. os-hackNOS-2(wp5.3本地文件包含 rbash绕过)

    一.信息收集 直接netdiscover,找到IP是 192.168.56.101 然后端口扫描一波 只打开了22和80端口,访问一下80端口,是apache首页,那就继续查目录赛.,发现了一个tsw ...

  7. copy-webpack-plugin & ignore folder

    copy-webpack-plugin & ignore folder https://github.com/webpack-contrib/copy-webpack-plugin#ignor ...

  8. CSS rulesets

    CSS rulesets https://developer.mozilla.org/en-US/docs/Web/CSS/Syntax#CSS_rulesets https://css-tricks ...

  9. how to check a var whether is number in js

    how to check a var whether is number in js js check var is number Number.isInteger(NaN) false Number ...

  10. Array in Depth

    Array in Depth Array.concat() & Array.push() https://developer.mozilla.org/en-US/docs/Web/JavaSc ...