29032023-02-02 12:59:08tamasmarkÁruszállítás üres szakaszaicpp17Elfogadva 50/50100ms52884 KiB
// arulas ures szakaszai.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <deque>

using namespace std;

struct adat
{
    long long indul, erkezik;
};
deque<adat >x;
long long i, n,a,b,m,db,y[1000002];
bool t;

int main()
{
    cin >> n>>m;
    x.resize(n + 1);
    /*for (i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        x[a].indul++;
        x[b].erkezik++;
    }
    //x[1].erkezik = x[1].indul;
    for (i = 2; i <=n; ++i)
    {
        if (x[i].erkezik == 0)
        {
            x[i].indul =x[i].indul + x[i - 1].indul;
        }
        else if (x[i].erkezik)
        {
            x[i].indul = x[i].indul + (x[i - 1].indul-x[i].erkezik);
        }
        if (x[i].indul == 0&&x[i-1].indul>0&&i<=n&&!t)
        {
            db++;
            t = true;
        }
        else if (t && x[i].indul)
        {
            t = false;
        }
        
    }
    cout << db;*/
    y[n] = 5;
    for (i = 1; i <= m; ++i)
    {
        cin >> a >> b;
        y[a]++;
        y[b]--;
    }
    for (i = 2; i <= n; ++i)
    {
        y[i] += y[i - 1];
    }
    for (i = 1; i <= n; ++i)
    {
        if (y[i] == 0) t = true;
        else if (y[i - 1] == 0 && t)
        {
            db++;
            t = false;
        }
    }
    cout << db;
    return 0;
}
/*
10 4
8 9
1 6
1 3
3 4
*/
// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
RészfeladatÖsszpontTesztVerdiktIdőMemória
base50/50
1Elfogadva0/03ms1816 KiB
2Elfogadva0/0100ms50408 KiB
3Elfogadva2/23ms2224 KiB
4Elfogadva2/23ms2456 KiB
5Elfogadva2/23ms2644 KiB
6Elfogadva2/23ms2880 KiB
7Elfogadva2/22ms3096 KiB
8Elfogadva2/22ms3208 KiB
9Elfogadva2/22ms3280 KiB
10Elfogadva2/23ms3412 KiB
11Elfogadva2/24ms6592 KiB
12Elfogadva2/24ms8480 KiB
13Elfogadva3/38ms8544 KiB
14Elfogadva3/313ms13100 KiB
15Elfogadva3/39ms13180 KiB
16Elfogadva3/382ms52692 KiB
17Elfogadva3/382ms52668 KiB
18Elfogadva3/390ms52544 KiB
19Elfogadva3/317ms23620 KiB
20Elfogadva3/323ms28700 KiB
21Elfogadva3/394ms52804 KiB
22Elfogadva3/397ms52884 KiB