一、题目

  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. 3.安装可视化工具kibana

    作者 微信:tangy8080 电子邮箱:914661180@qq.com 更新时间:2019-06-19 10:10:42 星期三 欢迎您订阅和分享我的订阅号,订阅号内会不定期分享一些我自己学习过程 ...

  2. 9.[完]其他常用的rabbitmq的参数和设置

    作者 微信:tangy8080 电子邮箱:914661180@qq.com 更新时间:2019-08-12 20:42:25 星期一 欢迎您订阅和分享我的订阅号,订阅号内会不定期分享一些我自己学习过程 ...

  3. 1. mac 手动安装nodejs搭建vue环境

    为什么选择手动安装nodejs呢? 因为使用mac自动安装还要更新homebrew,还要安装xcode tool, 太费劲了,不如手动安装, 卸载起来也方便 再一个, 我是后台开发者, 对前端页面, ...

  4. Design Patterns All in One (JavaScript Version)

    Design Patterns All in One (JavaScript Version) JavaScript 设计模式 JavaScript 数据结构 23种设计模式分为 3 大类: 创建型模 ...

  5. JavaScript interview Question - Create a Array with two papameters without using loop!

    JavaScript interview Question - Create a Array with two papameters without using loop! JavaScript - ...

  6. ES6 进制字面量 All In One

    ES6 进制字面量 All In One 二进制 & 八进制 & 字面量 https://developer.mozilla.org/en-US/docs/Web/JavaScript ...

  7. 微信小程序 UI 组件库

    微信小程序 UI 组件库 Vant Weapp 需要注意的是 package.json 和 node_modules 必须在 miniprogram 目录下 $ yarn add @vant/weap ...

  8. nodejs stream 创建读写流

    const fs = require("fs"); const { Writable, Readable, Duplex, Transform } = require(" ...

  9. css & box-shadow & outline

    css & box-shadow & outline CSS3 box-shadow : 4 sides symmetry https://learning.xgqfrms.xyz/C ...

  10. XML & XPath & XQuery

    XML & XPath & XQuery full XPath demo https://www.w3.org/TR/xpath-full-text-30/ https://www.w ...