20602022-12-16 08:19:47kohumarkRendezéscpp11Time limit exceeded 25/40370ms5864 KiB
#include <bits/stdc++.h>
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    int r[m][2];
    int s[n]; int m1, m2; bool ok=true;
    for(int i=0; i<n; i++) cin >> s[i];
    for(int i=0; i<m; i++) cin >> r[i][0] >> r[i][1];
    while(ok){
        ok = false;
        for(int i=0; i<m; i++){
            m1 = r[i][0]; m2=r[i][1];
            for(int i=m1-1; i<m2; i++){
                for(int j=i; j<m2; j++) if(s[i]>s[j]){
                    int x = s[j];
                    s[j] = s[i];
                    s[i] = x;
                    ok = true;
                }
            }
        }
    }
    int j=0;
    for(int i=0; i<n; i++) if(s[i]==i+1) j++;
    cout << j;
}
SubtaskSumTestVerdictTimeMemory
base25/40
1Accepted0/03ms1744 KiB
2Accepted0/034ms2340 KiB
3Accepted2/22ms2116 KiB
4Accepted2/22ms2316 KiB
5Accepted2/22ms2524 KiB
6Accepted2/22ms2732 KiB
7Accepted2/23ms2988 KiB
8Accepted2/23ms3192 KiB
9Accepted2/23ms3248 KiB
10Accepted2/23ms3252 KiB
11Accepted2/2103ms5564 KiB
12Accepted2/2100ms5712 KiB
13Accepted2/2100ms5756 KiB
14Accepted1/1100ms5864 KiB
15Accepted2/2101ms5860 KiB
16Time limit exceeded0/2352ms4052 KiB
17Time limit exceeded0/2344ms4120 KiB
18Time limit exceeded0/2349ms4128 KiB
19Time limit exceeded0/2352ms4384 KiB
20Time limit exceeded0/1365ms4248 KiB
21Time limit exceeded0/2370ms4132 KiB
22Time limit exceeded0/2356ms4324 KiB
23Time limit exceeded0/2361ms4384 KiB