aboutsummaryrefslogtreecommitdiff
path: root/codeforces/yapapsai/main.cpp
blob: 2946e653792f3001cda75c09e5fc2d59c24bd812 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<bits/stdc++.h>

using namespace std;

int main () {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tt;
	cin >> tt;
	while(tt--){
    int n;
    cin >> n;
    vector<int> pos;
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
      int x;
      cin >> x;
      if (x < i) {
        auto it = lower_bound(pos.begin(), pos.end(), x);
        ans += it - pos.begin();
        pos.emplace_back(i);
      }
    }
    cout << ans << '\n';
	}
}