79682024-01-12 09:22:11ZsBalazsRendezéscpp17Wrong answer 7/40126ms12668 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
            currentEnd = current.second;
        } else {
            realInter.push_back({currentStart, currentEnd});
            
            currentStart = current.first;
            currentEnd = current.second;
        }
    }
    
    if (currentStart != -1) {
        realInter.push_back({currentStart, currentEnd});
    }
    
    long long megoldas = 0;
    
    for (auto curr : realInter) {
        long long start = curr.first;
        long long end = curr.second;
        
        vector<long long> subInter;
        
        for (long long i = start; end >= i; i++) {
            subInter.push_back(szamok[i]);
        }
        
        sort(subInter.begin(), subInter.end());
        
        for (long long i = 0; subInter.size() > i; i++) {
            if (subInter[i] == start+i+1) {
                megoldas++;
            }
        }
    }
    
    long long lastIndex = 0;
    for (auto curr : realInter) {
        for (long long i = lastIndex; n > i && curr.first > i; i++) {
            if (i+1 == szamok[i]) {
                megoldas++;
            }
        }
        
        lastIndex = curr.second+1;
    }
    
    cout << megoldas << endl;
    
	return 0;
}
SubtaskSumTestVerdictTimeMemory
base7/40
1Accepted0/03ms1812 KiB
2Wrong answer0/017ms3300 KiB
3Accepted2/23ms2260 KiB
4Wrong answer0/23ms2592 KiB
5Wrong answer0/23ms2560 KiB
6Wrong answer0/23ms2712 KiB
7Wrong answer0/23ms2868 KiB
8Wrong answer0/23ms3124 KiB
9Wrong answer0/23ms3044 KiB
10Wrong answer0/24ms3400 KiB
11Wrong answer0/2118ms11920 KiB
12Accepted2/2116ms12564 KiB
13Accepted2/2118ms12668 KiB
14Accepted1/1118ms12584 KiB
15Wrong answer0/2116ms12420 KiB
16Wrong answer0/2115ms9900 KiB
17Wrong answer0/2114ms9864 KiB
18Wrong answer0/2114ms9892 KiB
19Wrong answer0/2115ms9884 KiB
20Wrong answer0/1126ms9812 KiB
21Wrong answer0/2112ms9872 KiB
22Wrong answer0/2114ms9836 KiB
23Wrong answer0/2115ms9988 KiB