Untitled

mail@pastecode.io avatar
unknown
c_cpp
a month ago
1.0 kB
5
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[x] = pre;
        }
        pre = x;
    }
    int group = 1;
    for (int i = 1; i <= n; i++) {
        if (conflict[i]) {
            if (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();
    }
}
Leave a Comment