#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define endl '\n'
const ll inf=1e15;
const ll mod=1e9+7;
const ll maxn=2000+5;
ll arr[maxn];
vector<ll> v;
ll fen[2*maxn];
void upd(ll pos){
while (pos<2*maxn){
fen[pos]++;
pos+=(pos&-pos);
}
}
ll query(ll pos){
ll ans=0;
while (pos){
ans+=fen[pos];
pos-=(pos&-pos);
}
return ans;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
ll n;
cin>>n;
for (int i=0;i<n;i++){
cin>>arr[i];
v.emplace_back(arr[i]);
}
sort(v.begin(),v.end());
for (int i=0;i<n;i++){
arr[i]=lower_bound(v.begin(),v.end(),arr[i])-v.begin();
}
ll ans=0;
for (int i=0;i<=n;i++){
ll tot=0;
memset(fen,0,sizeof(fen));
upd(2001);
for (int j=0;j<n;j++){
if (arr[j]==i){
tot++;
}else{
tot--;
}
upd(tot+2001);
ans+=query(tot+2000);
}
}
cout<<ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
284 KB |
Output is correct |
7 |
Correct |
16 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
63 ms |
372 KB |
Output is correct |
10 |
Correct |
56 ms |
332 KB |
Output is correct |
11 |
Correct |
56 ms |
380 KB |
Output is correct |
12 |
Correct |
57 ms |
380 KB |
Output is correct |
13 |
Correct |
56 ms |
380 KB |
Output is correct |
14 |
Correct |
58 ms |
332 KB |
Output is correct |
15 |
Correct |
70 ms |
372 KB |
Output is correct |
16 |
Correct |
57 ms |
376 KB |
Output is correct |
17 |
Correct |
57 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
588 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
2 ms |
336 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
2 ms |
332 KB |
Output is correct |
6 |
Correct |
2 ms |
284 KB |
Output is correct |
7 |
Correct |
16 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
63 ms |
372 KB |
Output is correct |
10 |
Correct |
56 ms |
332 KB |
Output is correct |
11 |
Correct |
56 ms |
380 KB |
Output is correct |
12 |
Correct |
57 ms |
380 KB |
Output is correct |
13 |
Correct |
56 ms |
380 KB |
Output is correct |
14 |
Correct |
58 ms |
332 KB |
Output is correct |
15 |
Correct |
70 ms |
372 KB |
Output is correct |
16 |
Correct |
57 ms |
376 KB |
Output is correct |
17 |
Correct |
57 ms |
332 KB |
Output is correct |
18 |
Runtime error |
1 ms |
588 KB |
Execution killed with signal 11 |
19 |
Halted |
0 ms |
0 KB |
- |