79972024-01-12 09:55:09ZsBalazsRendezéscpp17Wrong answer 7/40118ms12500 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});
            
            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
base7/40
1Accepted0/03ms1812 KiB
2Wrong answer0/017ms3296 KiB
3Accepted2/23ms2224 KiB
4Wrong answer0/23ms2308 KiB
5Wrong answer0/23ms2540 KiB
6Wrong answer0/23ms2640 KiB
7Wrong answer0/23ms2884 KiB
8Wrong answer0/24ms3096 KiB
9Wrong answer0/24ms3440 KiB
10Wrong answer0/23ms3520 KiB
11Wrong answer0/2112ms11664 KiB
12Accepted2/2112ms12432 KiB
13Accepted2/2115ms12300 KiB
14Accepted1/1114ms12500 KiB
15Wrong answer0/2112ms12120 KiB
16Wrong answer0/2112ms9652 KiB
17Wrong answer0/2111ms9680 KiB
18Wrong answer0/2112ms9528 KiB
19Wrong answer0/2112ms9528 KiB
20Wrong answer0/1111ms9524 KiB
21Wrong answer0/2112ms9524 KiB
22Wrong answer0/2111ms9524 KiB
23Wrong answer0/2118ms9668 KiB