Submission #73495174


Source Code Expand

#include<bits/stdc++.h>
using namespace std;
const int N=1e6+10;
typedef long long ll;
typedef pair<ll,ll> PII;
typedef array<ll,2> a2;
typedef array<ll,3> a3;
int n,m,k;
int a[N];

vector<int> e[N],e2[N];
ll sum[N];
ll mn[N];
bool tf[N];
int cnt[N];
set<int> se;
void 打卡啦摩托(){
    cin>>n>>m;
    vector<a2> vec;
    for(int i=1;i<=m;i++){
        int x,y;
        cin>>x>>y;
        if(x==y) continue;
        if(x<y)
        vec.push_back({x,y});
        // if(x>y) swap(x,y);
        e[x].push_back(y);
        e2[y].push_back(x);
    }
    for(int i=1;i<=n;i++) sort(e[i].begin(),e[i].end());
    for(int i=1;i<=n;i++){
        sort(e2[i].begin(),e2[i].end());
        if(e2[i].size()){
            int t=e2[i][0];
            // cout<<t<<" "<<i<<endl;
            if(t<i){
                sum[t]++;
                sum[i]--;
            }
        }
    }
    for(int i=1;i<=n;i++) sum[i]+=sum[i-1];
    priority_queue<a2,vector<a2>,greater<a2>> q;
    memset(mn,0x3f,sizeof mn);
    mn[1]=0;
    q.push({0,1});
    while(q.size()){
        auto tp=q.top();
        q.pop();
    
        int id=tp[1];
        if(tf[id]) continue;
        tf[id]=1;
        int nw=max(mn[id],1ll*id);
        for(auto j:e[id]){
            if(mn[j]>nw){
                mn[j]=nw;
                q.push({mn[j],j});
            }
        }
    }    
    ll mx=0;
    for(int i=1;i<=n;i++){
        mx=max(mx,mn[i]);
        if(i<mx) cout<<-1<<"\n";
        else cout<<sum[i]<<"\n";
    }

}


int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int _=1;
    // cin>>_;
    while(_--){
        打卡啦摩托();
    }
}

Submission Info

Submission Time
Task F - Reachable Set 2
User zhishengie
Language C++23 (GCC 15.2.0)
Score 500
Code Size 1705 Byte
Status AC
Exec Time 137 ms
Memory 51388 KiB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 55
Set Name Test Cases
Sample example_00.txt, example_01.txt
All example_00.txt, example_01.txt, hand_00.txt, hand_01.txt, hand_02.txt, hand_03.txt, hand_04.txt, hand_05.txt, hand_06.txt, hand_07.txt, hand_08.txt, hand_09.txt, hand_10.txt, hand_11.txt, hand_12.txt, hand_13.txt, hand_14.txt, hand_15.txt, hand_16.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt, random_30.txt, random_31.txt, random_32.txt, random_33.txt, random_34.txt, random_35.txt
Case Name Status Exec Time Memory
example_00.txt AC 11 ms 11348 KiB
example_01.txt AC 10 ms 11404 KiB
hand_00.txt AC 114 ms 51292 KiB
hand_01.txt AC 106 ms 38900 KiB
hand_02.txt AC 117 ms 48044 KiB
hand_03.txt AC 116 ms 48080 KiB
hand_04.txt AC 48 ms 18440 KiB
hand_05.txt AC 81 ms 31224 KiB
hand_06.txt AC 116 ms 48076 KiB
hand_07.txt AC 122 ms 50212 KiB
hand_08.txt AC 22 ms 13804 KiB
hand_09.txt AC 10 ms 11504 KiB
hand_10.txt AC 10 ms 11492 KiB
hand_11.txt AC 33 ms 13792 KiB
hand_12.txt AC 107 ms 49560 KiB
hand_13.txt AC 106 ms 49552 KiB
hand_14.txt AC 111 ms 51388 KiB
hand_15.txt AC 102 ms 46992 KiB
hand_16.txt AC 114 ms 51348 KiB
random_00.txt AC 47 ms 16728 KiB
random_01.txt AC 55 ms 18632 KiB
random_02.txt AC 87 ms 26880 KiB
random_03.txt AC 47 ms 17892 KiB
random_04.txt AC 49 ms 17628 KiB
random_05.txt AC 92 ms 38504 KiB
random_06.txt AC 135 ms 50064 KiB
random_07.txt AC 137 ms 50088 KiB
random_08.txt AC 137 ms 50060 KiB
random_09.txt AC 47 ms 17360 KiB
random_10.txt AC 70 ms 20884 KiB
random_11.txt AC 119 ms 37192 KiB
random_12.txt AC 11 ms 11492 KiB
random_13.txt AC 17 ms 13580 KiB
random_14.txt AC 133 ms 45120 KiB
random_15.txt AC 11 ms 11588 KiB
random_16.txt AC 19 ms 14416 KiB
random_17.txt AC 83 ms 34368 KiB
random_18.txt AC 11 ms 11604 KiB
random_19.txt AC 18 ms 14384 KiB
random_20.txt AC 98 ms 38140 KiB
random_21.txt AC 49 ms 17276 KiB
random_22.txt AC 60 ms 19212 KiB
random_23.txt AC 114 ms 35752 KiB
random_24.txt AC 106 ms 35808 KiB
random_25.txt AC 105 ms 35788 KiB
random_26.txt AC 107 ms 35856 KiB
random_27.txt AC 94 ms 30916 KiB
random_28.txt AC 93 ms 30788 KiB
random_29.txt AC 93 ms 30824 KiB
random_30.txt AC 73 ms 23740 KiB
random_31.txt AC 72 ms 23696 KiB
random_32.txt AC 72 ms 23672 KiB
random_33.txt AC 59 ms 19392 KiB
random_34.txt AC 59 ms 19420 KiB
random_35.txt AC 60 ms 19424 KiB