#include<bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t,n;
cin>>t;
while(t--){
cin>>n;
vector<int> v;
long long int tmp, cnt=0;
for(int i=1; i<=n; i++){
cin>>tmp;
if(tmp<i){
cnt+=upper_bound(v.begin(),v.end(),tmp-1)-lower_bound(v.begin(),v.end(),1);
v.push_back(i);
}
}
cout<<cnt<<"\n";
}
}
걍 누적합 세면댐
먼소리임
V가 정렬돼서 안들어가는데 upperbound 쓰는게 맞음?
맞네 이걸로 고침
나는 큰거부터 우선순위큐에 박고 빼면서 돌림 구현 개간단
누적합으로 O(n)으로 풀 수 있음
그니까 뭔소리임
일단 a[i] < i인거 구해서 1~i 까지 그런 것들의 개수를 누적합(prefix)으로 구한 다음에 모든 a[i] < i인 인덱스에 대해 a[i] != 0일때 prefix[min(n, a[i] - 1)]을 모두 더해주면 됨
나도 일케풀었으