Submission #58777202


Source Code Expand

/*
  Compete against Yourself.
  Author - Aryan (@aryanc403)
*/
/*
  Credits -
  Atcoder library - https://atcoder.github.io/ac-library/production/document_en/ (namespace atcoder)
  Github source code of library - https://github.com/atcoder/ac-library/tree/master/atcoder
  https://codeforces.com/contest/4/submission/150120627
*/
#include <bits/stdc++.h>
#include <atcoder/modint>
using mint = atcoder::modint998244353;
//using mint = atcoder::modint1000000007;
using vm = std::vector<mint>;
std::ostream& operator << (std::ostream& out, const mint& rhs) {
        return out<<rhs.val();
    }
#ifdef ARYANC403
    #include <header.h>
#else
    #pragma GCC optimize ("Ofast")
    // #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
    #pragma GCC target ("sse,sse2,mmx")
    #pragma GCC optimize ("-ffloat-store")
    #include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #define dbg(args...) 42;
    #define endl "\n"
#endif

// y_combinator from @neal template https://codeforces.com/contest/1553/submission/123849801
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0200r0.html
template<class Fun> class y_combinator_result {
    Fun fun_;
public:
    template<class T> explicit y_combinator_result(T &&fun): fun_(std::forward<T>(fun)) {}
    template<class ...Args> decltype(auto) operator()(Args &&...args) { return fun_(std::ref(*this), std::forward<Args>(args)...); }
};
template<class Fun> decltype(auto) y_combinator(Fun &&fun) { return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun)); }

using namespace std;
#define fo(i,n)   for(i=0;i<(n);++i)
#define repA(i,j,n)   for(i=(j);i<=(n);++i)
#define repD(i,j,n)   for(i=(j);i>=(n);--i)
#define all(x) begin(x), end(x)
#define sz(x) ((lli)(x).size())
#define eb emplace_back
#define X first
#define Y second

using lli = long long int;
using mytype = long double;
using ii = pair<lli,lli>;
using vii = vector<ii>;
using vi = vector<lli>;

template <class T>
using ordered_set =  __gnu_pbds::tree<T,__gnu_pbds::null_type,less<T>,__gnu_pbds::rb_tree_tag,__gnu_pbds::tree_order_statistics_node_update>;
// X.find_by_order(k) return kth element. 0 indexed.
// X.order_of_key(k) returns count of elements strictly less than k.

// namespace Re = std::ranges;
// namespace Ve = std::ranges::views;

const auto start_time = std::chrono::high_resolution_clock::now();
void aryanc403()
{
auto end_time = std::chrono::high_resolution_clock::now();
std::chrono::duration<double> diff = end_time-start_time;
    cerr<<"Time Taken : "<<diff.count()<<"\n";
}

const lli INF = 0xFFFFFFFFFFFFFFFLL;
const lli SEED=chrono::steady_clock::now().time_since_epoch().count();
mt19937_64 rng(SEED);
inline lli rnd(lli l=0,lli r=INF)
{return uniform_int_distribution<lli>(l,r)(rng);}

class CMP
{public:
bool operator()(ii a , ii b) //For min priority_queue .
{    return ! ( a.X < b.X || ( a.X==b.X && a.Y <= b.Y ));   }};

void add( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt==m.end())         m.insert({x,cnt});
    else                    jt->Y+=cnt;
}

void del( map<lli,lli> &m, lli x,lli cnt=1)
{
    auto jt=m.find(x);
    if(jt->Y<=cnt)            m.erase(jt);
    else                      jt->Y-=cnt;
}

bool cmp(const ii &a,const ii &b)
{
    return a.X<b.X||(a.X==b.X&&a.Y<b.Y);
}

const lli MX = 100000+5;
// const lli MX = 10;

int main(void) {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    // freopen("txt.in", "r", stdin);
    // freopen("txt.out", "w", stdout);
// cout<<std::fixed<<std::setprecision(35);
// Ve::iota(1, 6) | Ve::transform([](int x) { return x * 2; }) | Ve::reverse | Ve::take(3)
lli T=1;
// cin>>T;
while(T--)
{
    lli n;
    cin>>n;
    vector<vi> idx(MX);
    vm pBefore(n,1);//,pAfter(n,1);

    vi a;

    for(lli i=1;i<n;i++)
        pBefore[i]=2*pBefore[i-1];
    // for(lli i=n-2;i>=0;i--)
    //     pAfter[i]=2*pAfter[i+1];

    for(lli i=0;i<n;i++){
        lli x;
        cin>>x;
        idx[x].eb(i);
        a.eb(x);
    }

    vector<vi> fac(MX);
    for(lli i=MX-1;i>0;i--)
        for(lli j=i;j<MX;j+=i)
            fac[j].eb(i);

    mint ans = 0;
    vm dp(MX),pSumBefore(MX);

    // lli mx = 0;
    // for(lli val=1;val<MX;val++){
    //     lli cur = 0;
    //     for(const auto &f2:fac[val])
    //         for(const auto &f:fac[f2])
    //             cur++;
    //     mx=max(mx,cur);
    // }
    // cerr<<"mx: "<<mx<<endl;

    for(lli id=0;id<n;id++){
        const lli val = a[id];
        ans*=2;
        dbg(val,fac[val]);
        for(const auto &f:fac[val])
            dp[f]+=pSumBefore[f];
        for(const auto &f2:fac[val]){
            for(const auto &f:fac[f2]){
                if(f!=f2)
                    dp[f]-=dp[f2];
            }
            ans+=f2*dp[f2];
        }
        // dbg(dp);
        // dbg(val);
        for(const auto &f:fac[val])
            dp[f]=0;
        for(const auto &f:fac[val])
            pSumBefore[f]+=pBefore[id];
        cout<<ans<<endl;
        // dbg(pSumBefore);
    }

}   aryanc403();
    return 0;
}

Submission Info

Submission Time
Task E - Adjacent GCD
User aryanc403
Language C++ 20 (gcc 12.2)
Score 800
Code Size 5271 Byte
Status AC
Exec Time 1981 ms
Memory 37152 KiB

Compile Error

Main.cpp: In function ‘int main()’:
Main.cpp:29:26: warning: statement has no effect [-Wunused-value]
   29 |     #define dbg(args...) 42;
      |                          ^~
Main.cpp:158:9: note: in expansion of macro ‘dbg’
  158 |         dbg(val,fac[val]);
      |         ^~~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 800 / 800
Status
AC × 3
AC × 50
Set Name Test Cases
Sample 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt
All 00_sample_00.txt, 00_sample_01.txt, 00_sample_02.txt, 01_n_small_00.txt, 01_n_small_01.txt, 01_n_small_02.txt, 01_n_small_03.txt, 01_n_small_04.txt, 02_random_00.txt, 02_random_01.txt, 02_random_02.txt, 02_random_03.txt, 02_random_04.txt, 02_random_05.txt, 02_random_06.txt, 02_random_07.txt, 02_random_08.txt, 02_random_09.txt, 03_hcn_00.txt, 03_hcn_01.txt, 03_hcn_02.txt, 03_hcn_03.txt, 03_hcn_04.txt, 03_hcn_05.txt, 03_hcn_06.txt, 03_hcn_07.txt, 03_hcn_08.txt, 03_hcn_09.txt, 03_hcn_10.txt, 03_hcn_11.txt, 03_hcn_12.txt, 03_hcn_13.txt, 03_hcn_14.txt, 03_hcn_15.txt, 03_hcn_16.txt, 03_hcn_17.txt, 03_hcn_18.txt, 03_hcn_19.txt, 03_hcn_20.txt, 03_hcn_21.txt, 03_hcn_22.txt, 03_hcn_23.txt, 03_hcn_24.txt, 03_hcn_25.txt, 03_hcn_26.txt, 03_hcn_27.txt, 03_hcn_28.txt, 03_hcn_29.txt, 04_max_00.txt, 05_min_00.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 32 ms 21876 KiB
00_sample_01.txt AC 34 ms 21836 KiB
00_sample_02.txt AC 33 ms 21804 KiB
01_n_small_00.txt AC 33 ms 21976 KiB
01_n_small_01.txt AC 33 ms 22048 KiB
01_n_small_02.txt AC 33 ms 22056 KiB
01_n_small_03.txt AC 32 ms 22064 KiB
01_n_small_04.txt AC 34 ms 22112 KiB
02_random_00.txt AC 235 ms 33028 KiB
02_random_01.txt AC 299 ms 37124 KiB
02_random_02.txt AC 265 ms 34852 KiB
02_random_03.txt AC 305 ms 37152 KiB
02_random_04.txt AC 270 ms 34512 KiB
02_random_05.txt AC 301 ms 37096 KiB
02_random_06.txt AC 299 ms 36824 KiB
02_random_07.txt AC 297 ms 37076 KiB
02_random_08.txt AC 282 ms 35944 KiB
02_random_09.txt AC 298 ms 37092 KiB
03_hcn_00.txt AC 1942 ms 33988 KiB
03_hcn_01.txt AC 1960 ms 34112 KiB
03_hcn_02.txt AC 1949 ms 34096 KiB
03_hcn_03.txt AC 1929 ms 34140 KiB
03_hcn_04.txt AC 1924 ms 34152 KiB
03_hcn_05.txt AC 1872 ms 34200 KiB
03_hcn_06.txt AC 1749 ms 34192 KiB
03_hcn_07.txt AC 1697 ms 34244 KiB
03_hcn_08.txt AC 1570 ms 34308 KiB
03_hcn_09.txt AC 1449 ms 34492 KiB
03_hcn_10.txt AC 1934 ms 34108 KiB
03_hcn_11.txt AC 1981 ms 34104 KiB
03_hcn_12.txt AC 1936 ms 34236 KiB
03_hcn_13.txt AC 1908 ms 34276 KiB
03_hcn_14.txt AC 1903 ms 34332 KiB
03_hcn_15.txt AC 1827 ms 34384 KiB
03_hcn_16.txt AC 1751 ms 34364 KiB
03_hcn_17.txt AC 1675 ms 34388 KiB
03_hcn_18.txt AC 1554 ms 34352 KiB
03_hcn_19.txt AC 1442 ms 34448 KiB
03_hcn_20.txt AC 1687 ms 35332 KiB
03_hcn_21.txt AC 1681 ms 35344 KiB
03_hcn_22.txt AC 1647 ms 35584 KiB
03_hcn_23.txt AC 1618 ms 35684 KiB
03_hcn_24.txt AC 1610 ms 35640 KiB
03_hcn_25.txt AC 1583 ms 35768 KiB
03_hcn_26.txt AC 1491 ms 35948 KiB
03_hcn_27.txt AC 1450 ms 36212 KiB
03_hcn_28.txt AC 1355 ms 36388 KiB
03_hcn_29.txt AC 1255 ms 36364 KiB
04_max_00.txt AC 431 ms 34052 KiB
05_min_00.txt AC 34 ms 21872 KiB