80002024-01-12 09:57:51ZsBalazsRendezéscpp17Accepted 40/40120ms11860 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long n, m;
    cin >> n >> m;
    
    vector<long long> szamok;
    
    for (long long i = 0; n > i; i++) {
        long long temp;
        cin >> temp;
        
        szamok.push_back(temp);
    }
    
    vector<pair<long long, long long>> inter;
    
    for (long long i = 0; m > i; i++) {
        long long a, b;
        cin >> a >> b;
        
        a--;
        b--;
        
        inter.push_back({a, b});
    }
    
    sort(inter.begin(), inter.end());
    
    vector<pair<long long, long long>> realInter;
    
    long long currentStart = -1;
    long long currentEnd = -1;
    
    for (long long i = 0; m > i; i++) {
        pair<long long, long long> current = inter[i];
        
        if (currentStart == -1) {
            currentStart = current.first;
            currentEnd = current.second;
        } else if (currentEnd >= current.first) {
            // Ez egybeesik
            if (currentEnd < current.second) currentEnd = current.second;
        } else {
            realInter.push_back({currentStart, currentEnd});
            
            sort(szamok.begin()+currentStart, szamok.begin()+currentEnd+1);
            
            currentStart = current.first;
            currentEnd = current.second;
        }
    }
    
    if (currentStart != -1) {
        sort(szamok.begin()+currentStart, szamok.begin()+currentEnd+1);
    }
    
    int megoldas = 0;
    
    for (int i = 0; n > i; i++) {
        if (szamok[i] == i+1) {
            megoldas++;
        }
    }
    
    cout << megoldas << endl;
    
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1960 KiB
2Accepted0/017ms3336 KiB
3Accepted2/23ms2404 KiB
4Accepted2/23ms2336 KiB
5Accepted2/23ms2548 KiB
6Accepted2/23ms2632 KiB
7Accepted2/23ms2796 KiB
8Accepted2/23ms2992 KiB
9Accepted2/24ms3132 KiB
10Accepted2/23ms3000 KiB
11Accepted2/2112ms11188 KiB
12Accepted2/2112ms11860 KiB
13Accepted2/2112ms11712 KiB
14Accepted1/1112ms11728 KiB
15Accepted2/2114ms11836 KiB
16Accepted2/2114ms9104 KiB
17Accepted2/2115ms8960 KiB
18Accepted2/2115ms8964 KiB
19Accepted2/2120ms8960 KiB
20Accepted1/1115ms8964 KiB
21Accepted2/2112ms8972 KiB
22Accepted2/2112ms8968 KiB
23Accepted2/2115ms9260 KiB