75272024-01-09 13:27:26TuruTamasÁruszállítás üres szakaszaicpp17Accepted 50/5037ms19736 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()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    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/03ms1896 KiB
2Accepted0/035ms17724 KiB
3Accepted2/23ms2228 KiB
4Accepted2/23ms2444 KiB
5Accepted2/23ms2652 KiB
6Accepted2/23ms2864 KiB
7Accepted2/23ms2948 KiB
8Accepted2/23ms3108 KiB
9Accepted2/23ms3328 KiB
10Accepted2/23ms3408 KiB
11Accepted2/23ms3944 KiB
12Accepted2/23ms4908 KiB
13Accepted3/34ms5228 KiB
14Accepted3/37ms6944 KiB
15Accepted3/34ms7080 KiB
16Accepted3/324ms5536 KiB
17Accepted3/325ms5492 KiB
18Accepted3/328ms5568 KiB
19Accepted3/38ms10240 KiB
20Accepted3/38ms11792 KiB
21Accepted3/337ms19660 KiB
22Accepted3/337ms19736 KiB