fork download
  1. #include<bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void solve() {
  6. int n, cnt, pos2;
  7. cin >> n;
  8. vector<int> a(n), pos(n + 1), odd, even;
  9. for (int i = 0; i < n; i++) {
  10. cin >> a[i];
  11. pos[a[i]] = i;
  12. }
  13. for (int i = 0; i < n; i++) {
  14. if (a[i] & 1) odd.push_back(a[i]);
  15. else even.push_back(a[i]);
  16. }
  17. cnt = 1, pos2 = -1;
  18. for (int i = 1; i < n; i+=2) {
  19. if (pos[i] < pos2) cnt++;
  20. pos2 = pos[i];
  21. }
  22. cout << cnt << endl;
  23. cnt = 1, pos2 = -1;
  24. for (int i = 2; i <= n; i+=2) {
  25. if (pos[i] < pos2) cnt++;
  26. pos2 = pos[i];
  27. }
  28. cout << cnt << endl;
  29. }
  30. int main() {
  31. ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  32. #ifndef ONLINE_JUDGE
  33. freopen("input.txt", "r", stdin);
  34. freopen("output.txt", "w", stdout);
  35. #endif
  36. solve();
  37. }
Success #stdin #stdout 0.01s 5552KB
stdin
Standard input is empty
stdout
1
1