75252024-01-09 13:26:36TuruTamasÁruszállítás üres szakaszaicpp17Accepted 50/5086ms19132 KiB
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>

using namespace std;

typedef long long ll;

ll N, M, a, b, r, valsum;
ll tomb[1000000];

int main()
{
    cin >> N >> M;
    for (ll m = 0; m < M; m++) {
        cin >> a >> b;
        a--; b--;
        tomb[a]++;
        tomb[b]--;
    }
    bool f = false;
    for (ll n = 0; n < N; n++) {
        valsum += tomb[n];
        if (valsum == 0 && !f && n != N-1) {
            r++;
            f = true;
        }
        else if (tomb[n] != 0) {
            f = false;
        }
    }
    cout << r << endl;
}
SubtaskSumTestVerdictTimeMemory
base50/50
1Accepted0/03ms1880 KiB
2Accepted0/085ms17728 KiB
3Accepted2/23ms2580 KiB
4Accepted2/23ms2388 KiB
5Accepted2/23ms2384 KiB
6Accepted2/23ms2392 KiB
7Accepted2/23ms2392 KiB
8Accepted2/23ms2404 KiB
9Accepted2/23ms2540 KiB
10Accepted2/23ms2900 KiB
11Accepted2/23ms3432 KiB
12Accepted2/23ms4396 KiB
13Accepted3/37ms4724 KiB
14Accepted3/39ms6140 KiB
15Accepted3/37ms6240 KiB
16Accepted3/361ms4824 KiB
17Accepted3/363ms4980 KiB
18Accepted3/370ms4936 KiB
19Accepted3/312ms9604 KiB
20Accepted3/314ms11152 KiB
21Accepted3/386ms19060 KiB
22Accepted3/379ms19132 KiB