9522022-02-04 20:38:41nmarciRendezéscpp11Accepted 40/40101ms25952 KiB
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <list>
using namespace std;
using ll = long long int;

ll inf = 1e9+7;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> v(n);
    for(auto& i : v){
        cin >> i;
    }
    vector<int> rend(n + 1,0);
    while(m--){
        int a, b;
        cin >>a >> b;
        --a, --b;
        ++rend[a]; --rend[b];
    }
    int i = 0, start = -1;
    int sum = 0;
    while(i < n){
        //cerr << rend[i] << " ";
        sum += rend[i];
        if(sum > 0 && start == -1){
            start = i;
        }
        if(sum == 0 && start != -1){
            sort(v.begin() + start, v.begin() + i + 1);
            //cerr << start << " " << i << endl;
            start = -1;
        }
        ++i;
    }
    //cerr << endl;
    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(v[i] == i + 1) ++ans;
    }
    cout << ans << endl;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/02ms1736 KiB
2Accepted0/012ms2088 KiB
3Accepted2/21ms2052 KiB
4Accepted2/21ms2056 KiB
5Accepted2/21ms2056 KiB
6Accepted2/21ms2068 KiB
7Accepted2/22ms2076 KiB
8Accepted2/22ms2096 KiB
9Accepted2/22ms2104 KiB
10Accepted2/22ms2120 KiB
11Accepted2/290ms5248 KiB
12Accepted2/294ms7000 KiB
13Accepted2/296ms8628 KiB
14Accepted1/198ms10456 KiB
15Accepted2/2101ms12104 KiB
16Accepted2/285ms13832 KiB
17Accepted2/293ms15560 KiB
18Accepted2/290ms17292 KiB
19Accepted2/290ms19020 KiB
20Accepted1/190ms20756 KiB
21Accepted2/290ms22488 KiB
22Accepted2/289ms24220 KiB
23Accepted2/290ms25952 KiB