Codeforces
CF Step
Youtube Linkedin Discord Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

Code: Right Maximum

#include <bits/stdc++.h>

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    int T;
    std::cin >> T;
    while (T--) {
        int n;
        std::cin >> n;
        std::vector<int> a(n);
        std::vector<std::pair<int, int>> pre(n + 1);
        for (int i = 0; i < n; i++) {
            std::cin >> a[i];
        }
        for (int i = 0; i < n; i++) {
            pre[i + 1] = std::max(pre[i], std::make_pair(a[i], i));
        }
        int ans = 0;
        int p = n;
        while (p) {
            ans++;
            p = pre[p].second;
        }
        std::cout << ans << std::endl;
    }
    return 0;
}