?
# | Author | Problem | Lang | Verdict | Time | Memory | Sent | Judged | |
---|---|---|---|---|---|---|---|---|---|
214310316 |
Practice: frank66884 |
1744F - 21 | C++17 (GCC 7-32) | Accepted | 265 ms | 1576 KB | 2023-07-18 10:39:53 | 2023-07-18 10:39:53 |
#include<bits/stdc++.h> using namespace std; typedef long long ll; ll pos[200010],x,l,r,res; int main() { int t; cin>>t; while(t--) { int n; cin>>n; for(ll i=1;i<=n;i++) { cin>>x; pos[x]=i; } l=r=pos[0]; res=1; for(ll i=2;i<=n;i++) { int me=(i-1)/2; l = min(min(l, pos[me]), n + 1 -i); r = max({r, pos[me], i}); res += max(0ll, i - (r - l)); } cout<<res<<endl; } return 0; }
?
?
?
?