Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
1.0 kB
1
Indexable
Never
// #define Many_SubTask
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(a) begin(a), end(a)
#define pb push_back
#define pii pair<int, int>
#define F first
#define S second
#define mp make_pair
const int mod = 998244353;
const int inf = 1e18;
const int MAXN = 1000005;

int conflict[MAXN];
set<int> cur_group;

void solve() {
    int n, m;
    cin >> n >> m;
    int pre = inf;
    for (int i = 1; i <= m; i++) {
        int x;
        cin >> x;
        if (pre < x) {
            conflict[pre] = x;
        }
        pre = x;
    }
    int group = 1;
    for (int i = n; i >= 1; i--) {
        if (conflict[i] && cur_group.count(conflict[i])) {
            group++;
            cur_group.clear();
        }
        cur_group.insert(i);
    }
    cout << max(2ll, group);
}

signed main() {
    cin.sync_with_stdio(0), cin.tie(0);
    int N = 1;
#ifdef Many_SubTask
    cin >> N;
#endif
    for (int i = 1; i <= N; i++) {
        solve();
    }
}

// 1 2 3 4 5 6 7
// 1 3 5 7 6 4 2

// 1 6 2 5 3 4
Leave a Comment