71992024-01-03 12:43:48horvathabelRendezéscpp17Wrong answer 5/40112ms5364 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++){
        if (v[i]==i+1) ans++;
    }
    cout<<ans<<endl;
}
SubtaskSumTestVerdictTimeMemory
base5/40
1Accepted0/03ms1812 KiB
2Wrong answer0/016ms2264 KiB
3Wrong answer0/23ms2364 KiB
4Wrong answer0/23ms2364 KiB
5Wrong answer0/23ms2536 KiB
6Wrong answer0/23ms2512 KiB
7Wrong answer0/23ms2524 KiB
8Wrong answer0/23ms2520 KiB
9Wrong answer0/23ms2632 KiB
10Wrong answer0/23ms2908 KiB
11Wrong answer0/2105ms4632 KiB
12Wrong answer0/2105ms4756 KiB
13Wrong answer0/2105ms4868 KiB
14Wrong answer0/1108ms4780 KiB
15Wrong answer0/2107ms4788 KiB
16Wrong answer0/2109ms5000 KiB
17Accepted2/2111ms5076 KiB
18Wrong answer0/2112ms5128 KiB
19Wrong answer0/2108ms5268 KiB
20Accepted1/1108ms5256 KiB
21Accepted2/2108ms5340 KiB
22Wrong answer0/2112ms5340 KiB
23Wrong answer0/2111ms5364 KiB