小燈是一個居住在南極的企鵝觀測家,她每天的工作就是要觀察南極企鵝的生態。今天一早,她打開了窗戶看到了窗外有許多隻企鵝,喜歡企鵝的她馬上關上了窗戶,去跟企鵝們玩。
今天,她跟企鵝們玩的遊戲是「計算 mex」!詳細來說,企鵝們會給小燈一個序列,該序列有 $n$ 個整數 $a_1, a_2, \ldots, a_n$,而小燈必須要回答牠們「所有子區間的 mex 總和」。更明確來說,需要計算的是:
$$
\sum_{i = 1}^ {n}\sum_{j = i}^ {n}\text{mex}(a_i, a_{i + 1}, \ldots a_j)
$$
其中 $\text{mex}(b_1, b_2, \ldots, b_k)$ 為最小的非負整數 $x$ 滿足 $\forall 1 \leq i \leq k, x \neq b_i$。
企鵝所認得的運算系統為 8 進位,所以每個數字都會用 8 進位來表示,而小燈的答案也必須要用 8 進位來回答。
小燈害怕自己計算錯誤,於是她寫了一個程式來幫助她計算,但這個程式好像出了一點問題...,你能幫幫她在 edit distance
以內將程式碼修改正確嗎?
#include <bits/stdc++.h>
using namespace std;
int main() {
    const int base = 8;
    string s; cin >> s;
    int n = stoi(s, 0, base);
    vector <long long> a(n);
    for (int i = 0; i < n; ++i) {
        string t; cin >> t;
        a[i] = stol(t, 0, base);
    }
    long long ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j <= n; ++j) {
            vector <bool> vis(n + 1, false);
            int mex = 0;
            for (int k = i; k < j; ++k) {
                if (a[k] <= n) {
                    vis[a[k]] = true;
                }
            }
            while (vis[mex]) {
                mex++;
            }
            cout << mex << " ";
            ans += mex;
        }
        cout << "prefix " << i << " finished" << endl;
    }
    if (ans == 0) {
        cout << 0 << endl;
    } else {
        string t;
        while (ans > 0) {
            t += '0' + char(ans % base);
            ans /= base;
        }
        reverse(t.begin(), t.end());
        cout << t << endl;
    }
}
輸入第一行有一個正整數 $n$,代表序列的長度。
第二行有 $n$ 個以空白分隔的數字,分別為 $a_1, a_2, \ldots, a_n$。
每個數字皆以 8 進位表示(包含 $n$)。
請輸出一行,該行包括一個整數代表以 8 進位表示的答案。請特別注意本題的輸出為嚴格比對。
13 2 0 1 3 77777777777777777777 0 2 1 0 2 1
233

| No. | Testdata Range | Constraints | Score | 
|---|---|---|---|
| 1 | 0 | 範例測資 | 0 | 
| 2 | 0~19 | 無額外限制 | 200 |