Submission #67803507


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
#define rep(i, s, t) for(int i = (s); i <= (t); i ++)
#define per(i, s, t) for(int i = (s); i >= (t); i --)
template<typename T, typename T2>
inline void chmin(T &x, T2 &&y) { x = min(x, y); }
template<typename T, typename T2>
inline void chmax(T &x, T2 &&y) { x = max(x, y); }
typedef long long ll;

ll lcm(ll x, ll y) { return x / __gcd(x, y) * y; }
ll lcm(vector<ll> x)
{
    ll ans = x[0];
    for(ll i : x) ans = lcm(ans, i);
    return ans;
}

ll R(int x)
{
    ll ans = 0;
    rep(i, 1, x) ans = ans * 10 + 1;
    return ans;
}

const int N = 2e5 + 5, p = 998244353;

int r[N];
ll qpow(ll a, ll b)
{
    if(!b) return 1;
    return ((b & 1) ? a : 1ll) * qpow(a * a % p, b >> 1) % p;
}

vector<int> d[N];

int cnt[N];
int cd[N];

void add(int x, int v)
{
    cnt[x] = (cnt[x] + v) % (p - 1);
    for(int i : d[x]) cd[i] = (cd[i] + v) % (p - 1);
}
int qry(int x)
{
    return cd[x];
}

int a[N];

signed main()
{
    r[1] = 1; rep(i, 2, N - 1) r[i] = (10ll * r[i - 1] + 1) % p;
    rep(i, 1, N - 1) for(int j = i; j < N; j += i) d[j].push_back(i);
    
    // vector<pair<int, int>> cc;
    // int s = 0;
    // rep(i, 1, N - 1) { int cnt = 0; for(int j : d[i]) cnt += d[i / j].size(); cc.push_back({cnt, i}); s += cnt; }
    // cout << s;

    ios::sync_with_stdio(0);cin.tie(0);
    int n; cin >> n;
    int ans = 1;
    
    bool vis[N] = {};
    rep(i, 1, n)
    {
        int x; cin >> x;
        if(vis[x]) goto end;
        vis[x] = 1;
        for(int j : d[x])
        {
            a[j] = -qry(j);
        }
        // for(int j : d[x])
        //     cout << j << " " << a[j] << endl;
        per(j, d[x].size() - 1, 0)
        {
            int v = d[x][j];
            for(int k : d[x / v]) if(k > 1)
            {
                a[v] = (a[v] - a[v * k]) % (p - 1);
            }
        }
        a[x] ++;
        for(int j : d[x])
        {
            // cout << j << " " << a[j] << endl;
            ans = 1ll * ans * qpow(r[j], (a[j] % (p - 1) + (p - 1)) % (p - 1)) % p;
            add(j, a[j]);
        }
        end:
        cout << ans << "\n";
    }

    return 0;
}

Submission Info

Submission Time
Task C - Repunits
User adam01
Language C++ 20 (gcc 12.2)
Score 900
Code Size 2236 Byte
Status AC
Exec Time 510 ms
Memory 28320 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 900 / 900
Status
AC × 3
AC × 30
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, 02_random_10.txt, 02_random_11.txt, 02_random_12.txt, 02_random_13.txt, 02_random_14.txt, 03_hcn_00.txt, 03_hcn_01.txt, 03_hcn_02.txt, 03_hcn_03.txt, 03_hcn_04.txt, 04_max_00.txt, 05_min_00.txt
Case Name Status Exec Time Memory
00_sample_00.txt AC 99 ms 25980 KiB
00_sample_01.txt AC 102 ms 25964 KiB
00_sample_02.txt AC 106 ms 26240 KiB
01_n_small_00.txt AC 104 ms 28064 KiB
01_n_small_01.txt AC 106 ms 28096 KiB
01_n_small_02.txt AC 103 ms 28188 KiB
01_n_small_03.txt AC 104 ms 28192 KiB
01_n_small_04.txt AC 107 ms 28180 KiB
02_random_00.txt AC 322 ms 28200 KiB
02_random_01.txt AC 380 ms 28132 KiB
02_random_02.txt AC 311 ms 28164 KiB
02_random_03.txt AC 377 ms 28196 KiB
02_random_04.txt AC 370 ms 28312 KiB
02_random_05.txt AC 385 ms 28136 KiB
02_random_06.txt AC 345 ms 28184 KiB
02_random_07.txt AC 375 ms 28184 KiB
02_random_08.txt AC 295 ms 28244 KiB
02_random_09.txt AC 376 ms 28268 KiB
02_random_10.txt AC 392 ms 28180 KiB
02_random_11.txt AC 506 ms 28060 KiB
02_random_12.txt AC 503 ms 28096 KiB
02_random_13.txt AC 510 ms 28320 KiB
02_random_14.txt AC 500 ms 28272 KiB
03_hcn_00.txt AC 157 ms 28096 KiB
03_hcn_01.txt AC 161 ms 28272 KiB
03_hcn_02.txt AC 162 ms 28200 KiB
03_hcn_03.txt AC 160 ms 28188 KiB
03_hcn_04.txt AC 166 ms 28180 KiB
04_max_00.txt AC 124 ms 26156 KiB
05_min_00.txt AC 99 ms 25796 KiB