Min-First Search
Min-First Search
单调性质
对于ai,找到前面第一个比他大的aj,从j到i-1都可以接上
如果没有,就是1到i-1都可以
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
void solve() {
int n; cin >> n;
vector<int> a(n + 1, 0);
for(int i = 1; i < n; i ++) a[i];
ll ans = 1;
int mx = a[1];
for(int i = 2; i <= n; i ++) {
if(a[i] > mx) ans = ans * (i - 1) % MOD, mx = a[i];
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int _ = 1; //cin >> _;
while(_--) solve();
return 0;
}

浙公网安备 33010602011771号