首页 > 其他分享 >D - Another Sigma Problem

D - Another Sigma Problem

时间:2024-05-16 20:30:51浏览次数:18  
标签:return int pow ll prefix Another Problem Sigma sum

D - Another Sigma Problem

https://atcoder.jp/contests/abc353/tasks/abc353_d

 

思路

前缀和 + 快速幂

https://zhuanlan.zhihu.com/p/697255076

 

Code

https://atcoder.jp/contests/abc353/submissions/53514365

typedef long long ll;

ll pow(ll x, ll n)
{
    if(n == 0) return 1;
    if(n == 1) return x;
    ll half = pow(x, n / 2);
    ll rest = pow(x, n % 2);
    return half*half*rest;
}

ll BASE = 998244353;

int n;
vector<long long> a;
vector<long long> alen;
vector<long long> prefix_sum;

int main()
{
    cin >> n;
    
    a.resize(n);
    alen.resize(n);
    prefix_sum.resize(n);

    auto get = [&](ll x){
        ll cnt = 0;
        while(x){
            cnt ++;
            x /= 10;
        }
        return cnt;
    };

    for(int i=0; i<n; i++){
        cin >> a[i];
        
        alen[i] = get(a[i]);
        
        if (i==0){
            prefix_sum[i] = a[i];
        } else {
            prefix_sum[i] = prefix_sum[i-1] + a[i];
        }
    }

//    cout << "--------aaa------" << endl;
    
    long long ans = 0;

    for(int i=1; i<n; i++){
        long long contr = 0;
        
        /*
            aj+ai | 0 =< j < i
            ai contribute ai*i
            aj make prefix_sum[i-1]
            
            so for every ai, it contributes by two parts:
            prefix_sum[i-1] * 1e(strlen(ai))
            +
            ai * i
        */
        
        contr += ((i-0) * a[i]) % BASE;
        contr %= BASE;
        
        ll pw = pow(10, alen[i]);
        pw %= BASE;
        
        ll prefix_sum_mode = prefix_sum[i-1] % BASE;
        
        contr += (prefix_sum_mode * pw) % BASE;
        contr %= BASE;
        
        ans += contr;
        
        ans %= BASE;
    }

    cout << ans << endl;

    return 0;
}

 

标签:return,int,pow,ll,prefix,Another,Problem,Sigma,sum
From: https://www.cnblogs.com/lightsong/p/18196688

相关文章

  • 「ABC353」Yet Another Sigma Problem
    题目字典树做法(用时187ms)#include<cstdio>#include<ctype.h>constintN=3e5+10;intn;longlongans;inttrans[N][26],cnt[N];inttot;chars[N];template<classT>voidread(T&x){ charc=getchar(); while(!isdigit(c))c=getchar()......
  • ABC353C Sigma Problem 题解
    ABC353CSigmaProblem题解题目链接:AT题目中的两个求和符号\(\sum_{i=1}^{N-1}\sum_{j=i+1}^{N}\)实际上是在枚举所有的有序数对\((i,j)\)。而有序数对的个数\(N(N-1)/2=O(N^{2})\),真的去枚举所有数对肯定会T。这时应该考虑去拆贡献,求出每个\(A_i\)对答案的贡献。......
  • C - Sigma Problem
    C-SigmaProblemhttps://atcoder.jp/contests/abc353/tasks/abc353_c 思路暴力TLE观察a1a2...an序列计算目标是,两两结合并并求模sum=sigma(ai+aj)%1e8ai,aj<=1e8ai+aj可能溢出,也可能不溢出于是我们考虑,统计所有溢出的个数。 对数组进行排序,......
  • Week 9 Problems
    T1用等值演算、构造指派等方式判断公式的永真性(1)\[(\forallxP(x)\rightarrow\existxQ(x))\rightarrow\existx(P(x)\rightarrowQ(x))\](2)\[(\forallxP(x)\rightarrow\forallxQ(x))\rightarrow\forallx(P(x)\rightarrowQ(x))\]T2以下哪一步出现错误?......
  • Codeforces 954I Yet Another String Matching Problem
    考虑到这个答案怎么算。能发现相当于是对应的字符间相连边,那么一个连通块中的字符就要变成同一个字符。于是一个连通块的代价就是\(sz-1\)。所以令有\(x\)个连通块,最后的代价就是\(|\Sigma|-x\)。考虑到因为\(|\Sigma|=6\),而\(B_6=203\)(贝尔数,\(B_n\)意义为大......
  • 「主席树维护高精度」 CF464E The Classic Problem
    发现难点在于维护\(dis_u\)(起点\(s\)到\(u\)的最短路)。如果使用暴力高精度,复杂度会乘上一个\(len\)。考虑边权\(2^w\)的特殊性质,如果使用一个二进制串来维护\(dis\),那么加上边权\(2^w\)相当于将二进制下某一段\(1\)置为\(0\),然后再将一个\(0\)置为\(1\)。说白了......
  • 196. 删除重复的电子邮箱【Problem:Every derived table must have its own alias】
    SQL-Boy上线,最近在写SQL语句遇到了这样的问题。Problem:Everyderivedtablemusthaveitsownalias错误语句如下deletefromPersonwhereidnotin(selectidfrom(selectmin(id)asidfromPersongroupbyemail)......
  • vscode remote-x11 ssh 连接时Another All configured authentication methods failed
    错误remote-x11-ssh插件使用ssh2扩展出现以下错误https://github.com/joelspadin/vscode-remote-x11/issues/75Error:Allconfiguredauthenticationmethodsfailed原因https://github.com/mscdex/ssh2/issues/989解决换成ed25519并修改配置......
  • wpf datagrid,menuitem, style, export ,show in a another window,mvvm
    //xaml<Windowx:Class="WpfApp58.MainWindow"xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"xmlns:d="http://schemas.mic......
  • YetAnotherBoardGame
    Topcoder#搜索经典套路,我们发现枚举第一行后剩余的其实是确定的那么枚举并爆搜即可时间复杂度是\(3^k\)因为列的限制//Author:xiaruizeconstintN=13+10;intn,m;bools[N][N],bck[N][N];intop[N];voidupd(intx,inty,intty){if(ty==1)......