72662024-01-05 17:48:13anonRendezéscpp17Accepted 40/4043ms11924 KiB
#include <bits/stdc++.h>
#define FastIO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
typedef long long ll;
int main() {
    FastIO;
    ll i, j, fr, active, ans, N, M;
    cin >> N >> M;
    vector<ll> seq(N);
    for(i = 0; i < N; i++)
        cin >> seq[i];
    vector<array<ll, 2>> ranges(M);
    for(i = 0; i < M; i++) {
        cin >> ranges[i][0] >> ranges[i][1];
        ranges[i][0]--;
    }
    vector<array<ll, 2>> eps(N + 1, { 0, 0 });
    for(i = 0; i < M; i++) {
        for(j = 0; j < 2; j++)
            eps[ranges[i][j]][j]++;
    }
    fr = active = 0;
    for(i = 0; i <= N; i++) {
        active -= eps[i][1];
        if(!active && fr != -1) {
            sort(seq.begin() + fr, seq.begin() + i);
            fr = -1;
        }
        active += eps[i][0];
        if(active && fr == -1)
            fr = i;
    }
    ans = 0;
    for(i = 0; i < N; i++)
        ans += (seq[i] == i + 1);
    cout << ans << '\n';
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1824 KiB
2Accepted0/07ms2980 KiB
3Accepted2/23ms2556 KiB
4Accepted2/23ms2376 KiB
5Accepted2/23ms2444 KiB
6Accepted2/23ms2728 KiB
7Accepted2/23ms3068 KiB
8Accepted2/23ms3072 KiB
9Accepted2/23ms3000 KiB
10Accepted2/23ms3064 KiB
11Accepted2/237ms10544 KiB
12Accepted2/237ms10800 KiB
13Accepted2/239ms11076 KiB
14Accepted1/139ms10968 KiB
15Accepted2/239ms11228 KiB
16Accepted2/241ms11484 KiB
17Accepted2/243ms11748 KiB
18Accepted2/243ms11708 KiB
19Accepted2/241ms11708 KiB
20Accepted1/141ms11708 KiB
21Accepted2/241ms11784 KiB
22Accepted2/241ms11924 KiB
23Accepted2/241ms11856 KiB