#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define MS(x,y) memset((x),(y),sizeof((x)))
const ll MN = 1000000007;
using namespace std;
ll n;
ll tree[300001];
ll niza[300001];
ll query(ll pos) {
ll ret = 0;
while (pos > 0) {
ret += tree[pos];
pos -= pos&(-pos);
}
return ret;
}
void update(ll pos, ll val) {
while (pos <= n) {
tree[pos] += val;
pos += pos&(-pos);
}
}
ll presmetaj (ll pos) {
ll levo = query(pos-1);
ll site = query(n);
return levo*(site-levo-1);
}
int main()
{
#if LOCAL_DEBUG
fstream cin("in.txt");
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
MS(tree,0);
cin>>n;
for (ll i = 1; i<=n; i++) cin>>niza[i];
vector<pair<ll,ll>> sorti(n);
for (ll i = 1; i<=n; i++) sorti[i] = {niza[i],i};
sort(sorti.begin(),sorti.end());
vector<ll> moment;
ll sea = -1, res = 0;
for (ll i = 1; i<=n; i++) {
ll a = sorti[i].first;
if (a != sea) {
for (auto it:moment) res += presmetaj(it);
vector<ll> nov;
swap(moment,nov);
}
sea = a;
update(sorti[i].second,1);
moment.pb(sorti[i].second);
}
for (auto it:moment) res += presmetaj(it);
cout<<res<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
5204 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
63 ms |
12924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
63 ms |
12924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2644 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
63 ms |
12924 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
5204 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |