fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7. const int MOD = 998244353;
  8.  
  9. int N;
  10. if(!(cin >> N)) return 0;
  11. vector<int> A(N + 1);
  12. for (int i = 1; i <= N; ++i) cin >> A[i];
  13.  
  14. vector<int> p2(N + 3, 1);
  15. for (int i = 1; i < (int)p2.size(); ++i) p2[i] = (p2[i - 1] * 2LL) % MOD;
  16.  
  17. vector<int> nxt0(N + 3, 1), nxt1(N + 3, 1);
  18.  
  19. for (int i = N; i >= 2; --i) {
  20. vector<int> cur0(N + 3), cur1(N + 3);
  21. cur0[0] = cur1[0] = 0;
  22. bool asc = A[i - 1] < A[i];
  23. for (int q = 1; q <= N; ++q) {
  24. int pop = cur1[q - 1];
  25. int add = (long long)p2[q - 1] * nxt0[q + 1] % MOD;
  26. cur1[q] = (pop + add) % MOD;
  27. cur0[q] = pop;
  28. if (asc) cur0[q] = (cur0[q] + add) % MOD;
  29. }
  30. nxt0.swap(cur0);
  31. nxt1.swap(cur1);
  32. }
  33.  
  34. cout << nxt1[1] % MOD << '\n';
  35. return 0;
  36. }
  37.  
Success #stdin #stdout 0.01s 5308KB
stdin
5
1 3 2 4 5
stdout
17