fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const int Mod=1e9+7;
  5. const ll INF = 10000000000000;
  6. const int N = 1e6+7;
  7.  
  8. void solve() {
  9. int n;
  10. cin >> n;
  11. vector<int>a(n);
  12. for(int i=0;i<n;i++) cin >> a[i];
  13. int cnt = 0;
  14. int last = -2;
  15. for(int i=0;i<n;i++){
  16. if(a[i] > last + 1){
  17. cnt++;
  18. last = a[i];
  19. }
  20. }
  21. cout << cnt << "\n";
  22. }
  23.  
  24. int main(){
  25. ios::sync_with_stdio(false);
  26. cin.tie(nullptr);
  27.  
  28. int t;
  29. cin >> t;
  30. while (t--) solve();
  31.  
  32.  
  33. return 0;
  34. }
  35.  
Success #stdin #stdout 0.01s 5320KB
stdin
6
6
1 2 3 4 5 6
3
1 2 3
4
1 2 2 4
1
2
3
1 4 8
2
1 1
stdout
3
2
2
1
3
1