23832023-01-12 09:41:01rennRendezéscpp11Elfogadva 40/4050ms7412 KiB
#include <bits/stdc++.h>
using namespace std;

#define InTheNameOfGod cin.tie(0); ios::sync_with_stdio(0);
#define inv pair<int, int>

void print(vector<int> &s)
{
    for(auto &x : s)
        cout << x << " ";
    cout << "\n";
}

void print(vector<inv> &s)
{
    for(auto &x : s)
        cout << x.first << ":" << x.second << " ";
    cout << "\n";
}

int main()
{
    InTheNameOfGod

    int n, k, c = 0;
    cin >> n >> k;

    vector<int> s(n+2);
    for(int i = 1; i <= n; i++)
    {
        cin >> s[i];
    }

    vector<inv> ss;
    ss.reserve(k);
    queue<inv> done;
    for(int i = 0, a, b; i < k; i++)
    {
        cin >> a >> b;
        ss.push_back({a, b});
    }

    sort(ss.begin(), ss.end());

    inv z(-1, -1);
    for(inv &x : ss)
    {
        if(x.first <= z.second)
        {
            z.second = max(z.second, x.second);
            continue;
        }

        done.push(z);
        z.first = x.first;
        z.second = x.second;
    }
    done.push(z);
    done.pop();

    while(!done.empty())
    {
        z = done.front();
        done.pop();
        sort(s.begin()+z.first, s.begin()+z.second+1);
    }

    for(int i = 1; i <= n; i++)
    {
        c = i == s[i] ? c+1 : c;
    }
    cout << c << "\n";

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/03ms1828 KiB
2Elfogadva0/08ms2312 KiB
3Elfogadva2/22ms2220 KiB
4Elfogadva2/22ms2424 KiB
5Elfogadva2/22ms2632 KiB
6Elfogadva2/22ms2856 KiB
7Elfogadva2/22ms2928 KiB
8Elfogadva2/22ms3052 KiB
9Elfogadva2/22ms3276 KiB
10Elfogadva2/23ms3608 KiB
11Elfogadva2/246ms6712 KiB
12Elfogadva2/246ms7192 KiB
13Elfogadva2/246ms7244 KiB
14Elfogadva1/146ms7312 KiB
15Elfogadva2/246ms7412 KiB
16Elfogadva2/248ms6700 KiB
17Elfogadva2/250ms6552 KiB
18Elfogadva2/250ms6608 KiB
19Elfogadva2/250ms6808 KiB
20Elfogadva1/150ms7016 KiB
21Elfogadva2/248ms6964 KiB
22Elfogadva2/248ms6960 KiB
23Elfogadva2/248ms7024 KiB