QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#796162#8212. Football in Osijekucup-team173#Compile Error//C++231.8kb2024-12-01 13:33:072024-12-01 13:33:07

Judging History

你现在查看的是最新测评结果

  • [2024-12-01 13:33:07]
  • 评测
  • [2024-12-01 13:33:07]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

using ll = long long;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n + 1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    vector<int> vis(n + 1), bel(n + 1), sz(n + 1), cir(n + 1);
    vector<int> stk(n + 1), instk(n + 1); int tp = 0;
    for(int i = 1; i <= n; i++) if(!vis[i]) {
        auto dfs = [&](this auto &&self, int x) -> void {
            vis[x] = 1, stk[++tp] = x, instk[x] = 1;
            if(bel[a[x]]) {
                bel[x] = bel[a[x]], sz[bel[x]]++;
            } else if(vis[a[x]]) {
                while(stk[tp] != a[x]) {
                    cir[x]++, sz[x]++;
                    bel[stk[tp]] = x;
                    instk[stk[tp]] = 0;
                    tp--;
                }
                cir[x]++, sz[x]++, bel[a[x]] = x, instk[a[x]] = 0, tp--;
            } else {
                self(a[x]);
            }
            if(instk[x]) tp--, instk[x] = 0;
        };
        dfs(i);
    }
    vector<int> ve, ans(n + 2);
    for(int i = 1; i <= n; i++) {
        if(bel[i] == i) {
            ve.push_back(sz[i]);
            ans[cir[i]]++, ans[sz[i] + 1]--;
        }
    }
    for(int i = 1; i <= n; i++) ans[i] += ans[i - 1];
    for(int i = 1; i <= n; i++) ans[i] = !ans[i];
    sort(ve.begin(), ve.end(), greater<int>());
    for(int i = 1; i < ve.size(); i++) ve[i] += ve[i - 1];
    for(int i = 1; i < ve.size(); i++) {
        for(int j = ve[i - 1] + 1; j <= ve[i]; j++) {
            ans[j] = i;
        }
    }
    for(int i = 1; i <= n; i++) {
        cout << ans[i] << " \n"[i == n];
    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while(t--) solve();
    return 0;
}

詳細信息

answer.code: In function ‘void solve()’:
answer.code:16:24: error: expected identifier before ‘this’
   16 |         auto dfs = [&](this auto &&self, int x) -> void {
      |                        ^~~~
answer.code:16:24: error: expected ‘,’ or ‘...’ before ‘this’
answer.code: In lambda function:
answer.code:17:17: error: ‘x’ was not declared in this scope
   17 |             vis[x] = 1, stk[++tp] = x, instk[x] = 1;
      |                 ^
answer.code:29:17: error: ‘self’ was not declared in this scope
   29 |                 self(a[x]);
      |                 ^~~~