23822023-01-12 09:33:26TuruTamasRendezéscpp11Time limit exceeded 25/40382ms18772 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<bool, pair<int, int>>> A(M);
    {
    vector<vector<int>> B(N);
    for (size_t i = 0; i < M; i++)
    {
        cin >> a >> b;
        a--; b--;
        for (size_t k = a; k < b + 1; k++)
        {
            B[k].push_back(i);
        }
        A[i].second = {a, b};
    }
    for (size_t i = 0; i < N; i++)
    {
        if (B[i].size() > 1) {
            for (size_t k = 0; k < B[i].size(); k++)
            {
                A[B[i][k]].first = true;
            }
        }
    }
    }
    bool f = true;
    for (pair<bool, pair<int, int>> i : A)
    {
        sort(S.begin() + i.second.first, S.begin() + i.second.second + 1);
    }
    while (f) {
        f = false;
        for (pair<bool, pair<int, int>> i : A)
        {
            if (i.first && !is_sorted(S.begin() + i.second.first, S.begin() + i.second.second + 1)) {
                sort(S.begin() + i.second.first, S.begin() + i.second.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/032ms3356 KiB
3Accepted2/22ms2208 KiB
4Accepted2/22ms2456 KiB
5Accepted2/22ms2664 KiB
6Accepted2/22ms2840 KiB
7Accepted2/23ms2960 KiB
8Accepted2/23ms3212 KiB
9Accepted2/23ms3532 KiB
10Accepted2/23ms3740 KiB
11Accepted2/2123ms15560 KiB
12Accepted2/2115ms15160 KiB
13Accepted2/2119ms15408 KiB
14Accepted1/1116ms15664 KiB
15Accepted2/2116ms15868 KiB
16Time limit exceeded0/2372ms13508 KiB
17Time limit exceeded0/2374ms16708 KiB
18Time limit exceeded0/2370ms15888 KiB
19Time limit exceeded0/2370ms15692 KiB
20Time limit exceeded0/1342ms15332 KiB
21Time limit exceeded0/2382ms18772 KiB
22Time limit exceeded0/2358ms14016 KiB
23Time limit exceeded0/2347ms15496 KiB