| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1313392 | lev | Mountains (NOI20_mountains) | C++20 | 144 ms | 23924 KiB |
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int, int>
#define all(a) a.begin(), a.end()
using namespace std;
#ifdef LOCAL
#include "C:\Users\Dell\Downloads\template\template\icpc-notebook\Utilities\debug.h"
#else
#define debug(...) 42
#endif
const int mn = 5e5 + 5, mod = 1e9 + 7, inf = 2e9;
int n, a[mn];
vector <int> line[mn];
int bit[mn];
void add(int u, int val){
while(u <= n){
bit[u] += val;
u += (u & -u);
}
}
int get(int u){
int r = 0;
while(u){
r += bit[u];
u -= (u & -u);
}
return r;
}
int get(int l, int r){
return get(r) - get(l - 1);
}
void solve() {
cin >> n;
vector <int> comp;
// Compressed
for(int i = 1; i <= n; i++){
cin >> a[i]; comp.push_back(a[i]);
}
sort(all(comp)); comp.erase(unique(all(comp)), comp.end());
for(int i = 1; i <= n; i++){
a[i] = lower_bound(all(comp), a[i]) - comp.begin() + 1;
line[a[i]].push_back(i);
}
int res = 0;
for(int i = 1; i <= (int)comp.size(); i++){
for(auto x : line[i]){
if(x > 1 && x < n) res += get(1, x - 1) * get(x + 1, n);
}
for(auto x : line[i]) add(x, 1);
}
cout << res << '\n';
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
#define task "Kawabata"
if (fopen(task".INP", "r")) {
freopen(task".INP", "r", stdin);
freopen(task".OUT", "w", stdout);
}
int t = 1;
// cin >> t;
while (t--) solve();
return 0;
}
// Don't wanna lose anymore T_T
// Never let me go - Kazuo Ishiguro
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... | ||||
