提出 #71686307


ソースコード 拡げる

#include <bits/stdc++.h>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
using mint = modint998244353;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vmi = vector<mint>;
using vvmi = vector<vmi>;
using vvvmi = vector<vvmi>;
#define all(a) (a).begin(), (a).end()
#define rep2(i, m, n) for (int i = (m); i < (n); ++i)
#define rep(i, n) rep2(i, 0, n)
#define drep2(i, m, n) for (int i = (m)-1; i >= (n); --i)
#define drep(i, n) drep2(i, n, 0)

ll op(ll a, ll b){
    return a+b;
}
ll e(){return 0;}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n; cin >> n;
    vi p(n); rep(i, n)cin >> p[i];
    rep(i, n)p[i]--;
    scc_graph scc(n);
    rep(i, n)scc.add_edge(i, p[i]);
    vvi g = scc.scc();
    ll ans = 0;
    for(auto v : g){
        
        ll s = v.size();
        ans += s*(s-1)/2;
    }cout << ans << endl;
    /*segtree<ll, op, e> seg(n);
    ll k = 0;
    rep(i, n){
        k += seg.prod(p[i]+1, n);
        seg.set(p[i], 1);
    }
    cout << k << endl;*/

    
    return 0;
}

提出情報

提出日時
問題 E - Minimum Swap
ユーザ applejam
言語 C++23 (GCC 15.2.0)
得点 475
コード長 1224 Byte
結果 AC
実行時間 75 ms
メモリ 71236 KiB

ジャッジ結果

セット名 Sample All
得点 / 配点 0 / 0 475 / 475
結果
AC × 3
AC × 53
セット名 テストケース
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_random_03.txt, 01_random_04.txt, 01_random_05.txt, 01_random_06.txt, 01_random_07.txt, 01_random_08.txt, 01_random_09.txt, 01_random_10.txt, 01_random_11.txt, 01_random_12.txt, 01_random_13.txt, 01_random_14.txt, 01_random_15.txt, 01_random_16.txt, 01_random_17.txt, 01_random_18.txt, 01_random_19.txt, 01_random_20.txt, 01_random_21.txt, 01_random_22.txt, 01_random_23.txt, 01_random_24.txt, 01_random_25.txt, 01_random_26.txt, 01_random_27.txt, 01_random_28.txt, 01_random_29.txt, 01_random_30.txt, 01_random_31.txt, 01_random_32.txt, 01_random_33.txt, 01_random_34.txt, 01_random_35.txt, 01_random_36.txt, 01_random_37.txt, 01_random_38.txt, 01_random_39.txt, 01_random_40.txt, 01_random_41.txt, 01_random_42.txt, 01_random_43.txt, 01_random_44.txt, 01_random_45.txt, 01_random_46.txt, 01_random_47.txt, 01_random_48.txt, 01_random_49.txt, 01_random_50.txt, 01_random_51.txt, 01_random_52.txt
ケース名 結果 実行時間 メモリ
00_sample_00.txt AC 1 ms 3528 KiB
00_sample_01.txt AC 1 ms 3408 KiB
00_sample_02.txt AC 1 ms 3516 KiB
01_random_03.txt AC 59 ms 43240 KiB
01_random_04.txt AC 62 ms 52800 KiB
01_random_05.txt AC 68 ms 67008 KiB
01_random_06.txt AC 52 ms 33152 KiB
01_random_07.txt AC 63 ms 59144 KiB
01_random_08.txt AC 69 ms 67956 KiB
01_random_09.txt AC 57 ms 44340 KiB
01_random_10.txt AC 54 ms 41064 KiB
01_random_11.txt AC 69 ms 67124 KiB
01_random_12.txt AC 61 ms 52964 KiB
01_random_13.txt AC 55 ms 43416 KiB
01_random_14.txt AC 56 ms 44752 KiB
01_random_15.txt AC 55 ms 41220 KiB
01_random_16.txt AC 28 ms 23072 KiB
01_random_17.txt AC 27 ms 26816 KiB
01_random_18.txt AC 3 ms 6012 KiB
01_random_19.txt AC 13 ms 16464 KiB
01_random_20.txt AC 67 ms 64336 KiB
01_random_21.txt AC 69 ms 71232 KiB
01_random_22.txt AC 70 ms 71120 KiB
01_random_23.txt AC 70 ms 71104 KiB
01_random_24.txt AC 67 ms 62016 KiB
01_random_25.txt AC 59 ms 47532 KiB
01_random_26.txt AC 55 ms 42376 KiB
01_random_27.txt AC 49 ms 29188 KiB
01_random_28.txt AC 43 ms 16580 KiB
01_random_29.txt AC 40 ms 14524 KiB
01_random_30.txt AC 39 ms 14548 KiB
01_random_31.txt AC 39 ms 13888 KiB
01_random_32.txt AC 39 ms 13772 KiB
01_random_33.txt AC 39 ms 13936 KiB
01_random_34.txt AC 38 ms 16776 KiB
01_random_35.txt AC 36 ms 19716 KiB
01_random_36.txt AC 35 ms 22712 KiB
01_random_37.txt AC 15 ms 12692 KiB
01_random_38.txt AC 19 ms 12668 KiB
01_random_39.txt AC 22 ms 10284 KiB
01_random_40.txt AC 37 ms 13324 KiB
01_random_41.txt AC 10 ms 7072 KiB
01_random_42.txt AC 19 ms 18476 KiB
01_random_43.txt AC 6 ms 10976 KiB
01_random_44.txt AC 32 ms 36804 KiB
01_random_45.txt AC 19 ms 25696 KiB
01_random_46.txt AC 25 ms 16960 KiB
01_random_47.txt AC 44 ms 15564 KiB
01_random_48.txt AC 75 ms 71236 KiB
01_random_49.txt AC 47 ms 17596 KiB
01_random_50.txt AC 32 ms 25624 KiB
01_random_51.txt AC 31 ms 25476 KiB
01_random_52.txt AC 31 ms 25540 KiB