이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
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+1);
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);
for (auto it:moment) update(it,1);
vector<ll> nov;
swap(moment,nov);
}
sea = a;
moment.pb(sorti[i].second);
}
for (auto it:moment) res += presmetaj(it);
cout<<res<<endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |