# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1274721 | AgentPengin | Mountains (NOI20_mountains) | C++20 | 119 ms | 9972 KiB |
/**
* author: AgentPengin ( Độc cô cầu bại )
* created: 23.12.2022 10:08:02
* too lazy to update time
**/
#include<bits/stdc++.h>
#define EL '\n'
#define fi first
#define se second
#define NAME "TASK"
#define ll long long
#define lcm(a,b) (a/gcd(a,b))*b
#define db(val) "["#val" = " << (val) << "] "
#define bend(v) (v).begin(),(v).end()
#define sz(v) (int)(v).size()
#define ex exit(0)
#define int ll
using namespace std;
const ll mod = 1e9 + 7;
const int inf = 0x1FFFFFFF;
const int MAXN = 3e5 + 5;
int n, h[MAXN], bit[2][MAXN];
vector<int> compress;
void update(int type, int x, int val) {
for (;x < MAXN;x += x&-x) bit[type][x] += val;
}
int get(int type, int x) {
int res = 0;
if (x == 0) return 0;
for (;x;x-=x&-x) res += bit[type][x];
return res;
}
signed main() {
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
if (ifstream(NAME".inp")) {
freopen(NAME".inp","r",stdin);
freopen(NAME".out","w",stdout);
}
cin >> n;
for (int i = 1;i <= n;i++) {
cin >> h[i];
compress.push_back(h[i]);
}
sort(bend(compress));
for (int i = 1;i <= n;i++) {
h[i] = lower_bound(bend(compress), h[i]) - compress.begin() + 1;
}
// for (int i = 1;i <= n;i++) cout << h[i] << " ";
for (int i = n;i >= 3;i--) {
update(1, h[i], 1);
}
update(0, h[1], 1);
int ans = 0;
for (int i = 2;i <= n - 1;i++) {
ans += get(0, h[i] - 1) * get(1, h[i] - 1);
update(0, h[i], 1);
update(1, h[i + 1], -1);
}
cout << ans;
cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
return 0;
}
// agent pengin wants to take apio (with anya-san)
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... |