20162022-12-14 10:15:47gkataÁruszállítás üres szakaszaicpp17Accepted 50/5094ms27420 KiB
#include <iostream>
//#include <fstream>
#include <vector>

using namespace std;

//ifstream cin("aru.in");
//ofstream cout("aru.out");



struct aru
{
    int vesz,lerak,arudb;
};

vector <aru> x;
int n,m,a,b,i,db;

int main()
{
    cin>>n>>m;
    x.resize(n+1);

    for(i=1;i<=m;++i)
    {
        cin>>a>>b;
        ++x[a].vesz;
        ++x[b].lerak;
    }

    x[0].arudb=1;
    for(i=1;i<=n;++i)
    {
        if(i>1) x[i].arudb=x[i-1].arudb;
        if(x[i].vesz!=0) x[i].arudb+=x[i].vesz;
        if(x[i].lerak!=0) x[i].arudb-=x[i].lerak;
        if(x[i].arudb==0 && x[i].arudb!=x[i-1].arudb && i!=n) ++db;
    }

    cout<<db;
    //for(auto &e:x) cout<<e<<" ";
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1872 KiB
2Accepted0/094ms25572 KiB
3Accepted2/22ms2480 KiB
4Accepted2/22ms2540 KiB
5Accepted2/22ms2620 KiB
6Accepted2/22ms2576 KiB
7Accepted2/22ms2692 KiB
8Accepted2/22ms2572 KiB
9Accepted2/22ms2704 KiB
10Accepted2/22ms2784 KiB
11Accepted2/23ms4252 KiB
12Accepted2/23ms5108 KiB
13Accepted3/37ms5308 KiB
14Accepted3/39ms7592 KiB
15Accepted3/38ms7712 KiB
16Accepted3/370ms27032 KiB
17Accepted3/371ms27180 KiB
18Accepted3/379ms27156 KiB
19Accepted3/313ms12992 KiB
20Accepted3/314ms15332 KiB
21Accepted3/382ms27420 KiB
22Accepted3/390ms27296 KiB