71962024-01-03 12:39:26horvathabelRendezéscpp17Wrong answer 5/40112ms5968 KiB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin>>n;
    int k;
    cin>>k;
    vector<int> pre;
    vector<int> v;
    pre.resize(n+1,0);
    for (int i=0; i<n;i++){
        int x;
        cin>>x;
        v.push_back(x);
    }
    for (int i=0; i<k;i++){
        int a,b;
        cin>>a>>b;
        a--;
        b--;
        pre[a]++;
        pre[b+1]--;
    }
    int ke=-1;
    int most=0;
    for (int i=0; i<n;i++){
        most+=pre[i];
        if (ke==-1 && most>0){
            ke=i;
        }
        if (most==0 && ke!=-1){
            sort(v.begin()+ke, v.begin()+i);
            ke=-1;
        }
    }
    if (ke!=-1) sort(v.begin()+ke,v.end());
    int ans=0;
    for (int i=0; i<n;i++){
        ans+=(v[i]==i+1);
    }
    cout<<ans<<endl;
}
SubtaskSumTestVerdictTimeMemory
base5/40
1Accepted0/03ms1844 KiB
2Wrong answer0/016ms2204 KiB
3Wrong answer0/23ms2212 KiB
4Wrong answer0/23ms2192 KiB
5Wrong answer0/23ms2440 KiB
6Wrong answer0/23ms2692 KiB
7Wrong answer0/23ms2908 KiB
8Wrong answer0/23ms3028 KiB
9Wrong answer0/23ms3244 KiB
10Wrong answer0/23ms3332 KiB
11Wrong answer0/2107ms5092 KiB
12Wrong answer0/2105ms5092 KiB
13Wrong answer0/2107ms5096 KiB
14Wrong answer0/1107ms5092 KiB
15Wrong answer0/2105ms5220 KiB
16Wrong answer0/2112ms5300 KiB
17Accepted2/2111ms5432 KiB
18Wrong answer0/2112ms5512 KiB
19Wrong answer0/2108ms5516 KiB
20Accepted1/1108ms5664 KiB
21Accepted2/2112ms5724 KiB
22Wrong answer0/2112ms5876 KiB
23Wrong answer0/2111ms5968 KiB