23812023-01-12 09:01:34TuruTamasRendezéscpp11Time limit exceeded 25/40377ms5696 KiB
#include <bits/stdc++.h>
using namespace std;

int N, M;

int main() {
    cin >> N >> M;
    vector<int> S(N);
    for (size_t i = 0; i < N; i++)
    {
        cin >> S[i];
    }
    int a, b;
    vector<pair<int, int>> A(M);
    for (size_t i = 0; i < M; i++)
    {
        cin >> a >> b;
        a--; b--;
        A[i] = {a, b};
    }
    bool f = true;

    while (f) {
        f = false;
        for (pair<int, int> i : A)
        {
            if (!is_sorted(S.begin() + i.first, S.begin() + i.second + 1)) {
                sort(S.begin() + i.first, S.begin() + i.second + 1);
                f = true;
            }
        }
    }
    int counter = 0;
    for (size_t i = 0; i < S.size(); i++)
    {
        if (S[i] == i + 1) counter++;
    }
    cout << counter;
}
SubtaskSumTestVerdictTimeMemory
base25/40
1Accepted0/03ms1812 KiB
2Accepted0/029ms2364 KiB
3Accepted2/22ms2256 KiB
4Accepted2/22ms2464 KiB
5Accepted2/22ms2668 KiB
6Accepted2/22ms2872 KiB
7Accepted2/23ms3084 KiB
8Accepted2/23ms3192 KiB
9Accepted2/23ms3276 KiB
10Accepted2/23ms3352 KiB
11Accepted2/298ms5564 KiB
12Accepted2/296ms5584 KiB
13Accepted2/296ms5668 KiB
14Accepted1/198ms5564 KiB
15Accepted2/297ms5696 KiB
16Time limit exceeded0/2363ms3876 KiB
17Time limit exceeded0/2377ms4084 KiB
18Time limit exceeded0/2361ms4196 KiB
19Time limit exceeded0/2372ms4068 KiB
20Time limit exceeded0/1365ms4208 KiB
21Time limit exceeded0/2361ms4412 KiB
22Time limit exceeded0/2361ms4560 KiB
23Time limit exceeded0/2358ms4700 KiB