39392023-03-05 23:40:11zsomborMágikus sorozatcpp17Elfogadva 100/100165ms88640 KiB
#include <iostream>
#include <vector>
using namespace std;

int n, done = 1, a, b, cnt = 0;
vector <int> z(3e5, 0);
vector <int> p(3e5, 0);
vector <vector <int>> dif(3e5);
vector <int> root;
vector <vector <bool>> v(800, vector<bool>(3e5, true));
vector <int> val(3e5, 0);

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> z[i];
        p[i] = i;
    }
    for (int i = 1; i < n; i++) {
        for (int j = max(i, done); j < i + z[i]; j++) {
            p[j] = j - i;
        }
        done = max(done, i + z[i]);
        p[i] = p[p[i]];
    }
    for (int i = 1; i < n; i++) {
        a = z[i]; b = i + z[i];
        if (b < n) dif[a].push_back(b);
    }
    for (int i = 0; i < n; i++) {
        if (p[i] != i) { p[i] = p[p[i]]; continue; }
        a = cnt;
        for (int j = cnt - 1; j >= 0; j--) if (v[j][i]) a = j;
        if (a == cnt) { root.push_back(i); cnt++; val[i] = cnt; }
        p[i] = root[a];
        for (int j : dif[i]) v[a][j] = false;
    }
    for (int i = 0; i < n; i++) cout << val[p[i]] << " ";
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
subtask10/0
1Elfogadva28ms81472 KiB
2Elfogadva32ms82092 KiB
subtask215/15
3Elfogadva29ms81892 KiB
4Elfogadva37ms82100 KiB
5Elfogadva30ms82400 KiB
subtask315/15
6Elfogadva28ms82352 KiB
7Elfogadva28ms82356 KiB
8Elfogadva28ms82648 KiB
9Elfogadva28ms82912 KiB
10Elfogadva35ms83032 KiB
subtask430/30
11Elfogadva37ms82908 KiB
12Elfogadva29ms83164 KiB
13Elfogadva37ms83372 KiB
14Elfogadva37ms83584 KiB
subtask540/40
15Elfogadva128ms88468 KiB
16Elfogadva128ms86716 KiB
17Elfogadva129ms87416 KiB
18Elfogadva127ms87352 KiB
19Elfogadva136ms87312 KiB
20Elfogadva149ms88112 KiB
21Elfogadva153ms88012 KiB
22Elfogadva150ms87952 KiB
23Elfogadva145ms88056 KiB
24Elfogadva131ms87972 KiB
25Elfogadva133ms87824 KiB
26Elfogadva135ms88340 KiB
27Elfogadva109ms86304 KiB
28Elfogadva123ms86828 KiB
29Elfogadva128ms88640 KiB
30Elfogadva165ms84396 KiB
31Elfogadva146ms86928 KiB
32Elfogadva128ms86880 KiB