Backrooms Hill

Backrooms Hill

寻找不变量
峰值必然是n,而且从n-1开始到1,必然往当前序列的两端增加,所以[x, n]构成了一个连续区间,这个区间内,奇偶小标的差值不能超过1

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

void solve() {
    int n; cin >> n;
    vector<int> a(n + 1, 0), pos(n + 1);
    for(int i = 1; i <= n; i ++) {
        cin >> a[i];
        pos[a[i]] = i % 2;
    }

    int b = 0;
    for(int i = n; i >= 1; i --) {
        if(pos[i] % 2 == 0) b ++;
        else b --;
        if(abs(b) > 1) {cout << "NO\n"; return;}
    }
    cout << "YES\n";
}

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int _ = 1; cin >> _;
    while(_--) solve();
    return 0;
}
posted @ 2026-10-26 14:21  thenrify  阅读(5)  评论(0)    收藏  举报