一、题目

  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. ArcGIS处理栅格数据(一)

    一.建立影像金字塔 ArcToolbox--数据管理工具--栅格--栅格属性--构建金字塔(pyramid) 说明:该方式一次只能为一张影像数据建立影像金字塔. ArcToolbox--数据管理工具- ...

  2. 慕课网站 & MOOC website

    慕课网站 & MOOC website MOOC, massive open online course Mooc for everyone ! 国家精品课程 & 在线学习平台 慕课平 ...

  3. Oh My Zsh All In One

    Oh My Zsh All In One https://ohmyz.sh/ install # CURL $ sh -c "$(curl -fsSL https://raw.github. ...

  4. Mac 开机时为什么突然响一下,duang

    Mac 开机时为什么突然响一下,duang duang 一下 https://zh.wikipedia.org/wiki/Duang refs xgqfrms 2012-2020 www.cnblog ...

  5. Matthew Effect

    Matthew Effect 马太效应 / 马修效应 马太效应(Matthew Effect),是指好的愈好,坏的愈坏,多的愈多,少的愈少的一种现象, 即两极分化现象. 来自于圣经<新约•马太福 ...

  6. tslint 忽略对某行代码的检测

    tslint rules class Ajanuw { constructor() { console.log("hello ajanuw"); } } // @ts-ignore ...

  7. NGK公链:通用型存储网络

    NGK公链,是一条发展中的通用型存储网络. NGK的运用归结与存储场景.NGK通证的运用归结于支付场景.个人数据被中心化服务商买卖.被大数据服务商使用.被无数的商务及销售人员窃取.那么NGK的运用场景 ...

  8. Vue学习笔记-Vue.js-2.X 学习(三)===>组件化高级

    (四) 组件化高级 1.插槽(slot)的基本使用 A:基本使用: <slot></slot> B:默认置:<slot><h1>中间可以放默认值< ...

  9. ctf.show_web13(文件上传之.user.ini)

    这是一道文件上传题,先二话不说丢个图片码,显示为 先考虑文件太小,用burp抓包,添加了一堆无用的东西后显示仍然是error file zise,直到上传正常图片依旧如此,考虑文件太大.将一句话木马修 ...

  10. Spring IoC总结

    Spring 复习 1.Spring IoC 1.1 基本概念 1.1.1 DIP(Dependency Inversion Principle) 字面意思依赖反转原则,即调用某个类的构造器创建对象时 ...