# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1066311 | tamthegod | Mountains (NOI20_mountains) | C++17 | 171 ms | 19176 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e6 + 5;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, a[maxN];
vector<int> vc;
struct BIT
{
vector<int> bit;
int n;
void init(int _n)
{
n = _n;
bit.resize(n + 5, 0);
}
void update(int pos, int val)
{
for(; pos <= n; pos += (pos & (-pos)))
bit[pos] += val;
}
int get(int pos)
{
int res = 0;
for(; pos; pos -= (pos & (-pos)))
res += bit[pos];
return res;
}
};
void ReadInput()
{
cin >> n;
for(int i=1; i<=n; i++)
{
cin >> a[i];
vc.pb(a[i]);
}
sort(vc.begin(), vc.end());
vc.erase(unique(vc.begin(), vc.end()), vc.end());
for(int i=1; i<=n; i++)
a[i] = upper_bound(vc.begin(), vc.end(), a[i]) - vc.begin();
}
void Solve()
{
BIT pref, suff;
pref.init(n);
suff.init(n);
for(int i=2; i<=n; i++)
suff.update(a[i], 1);
pref.update(a[1], 1);
int res = 0;
for(int i=2; i<n; i++)
{
suff.update(a[i], - 1);
res += pref.get(a[i] - 1) * suff.get(a[i] - 1);
pref.update(a[i], 1);
}
cout << res;
}
#define taskname ""
int32_t main()
{
if (fopen(taskname ".inp", "r"))
{
freopen(taskname ".inp", "r", stdin);
freopen(taskname ".out", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
//cin >> T;
for(int itest=1; itest<=T; itest++)
{
ReadInput();
Solve();
}
}
Compilation message (stderr)
# | 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... |