# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
516448 | Jomnoi | Mountains (NOI20_mountains) | C++17 | 548 ms | 36828 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define DEBUG 0
using namespace std;
const int MX = 3e5 + 10;
long long h[MX];
class Fenwick {
protected :
int N;
vector <int> fenwick;
public :
Fenwick(const int &n) : N(n) {
fenwick.resize(N + 10, 0);
}
int lsb(const int &x) const {
return x & -x;
}
void update(const int &i, const int &val) {
for(int idx = i; idx <= N; idx += lsb(idx)) {
fenwick[idx] += val;
}
}
int query(const int &i) const {
int res = 0;
for(int idx = i; idx > 0; idx -= lsb(idx)) {
res += fenwick[idx];
}
return res;
}
};
int main() {
int n;
scanf(" %d", &n);
set <long long> s;
unordered_map <long long, int> mp;
for(int i = 1; i <= n; i++) {
scanf(" %lld", &h[i]);
s.insert(h[i]);
}
int cnt = 0;
for(auto v : s) {
mp[v] = ++cnt;
}
Fenwick fw1(cnt), fw2(cnt);
for(int i = 2; i <= n; i++) {
fw2.update(mp[h[i]], 1);
}
fw1.update(mp[h[1]], 1);
long long ans = 0;
for(int i = 2; i < n; i++) {
fw2.update(mp[h[i]], -1);
ans += 1ll * fw1.query(mp[h[i]] - 1) * fw2.query(mp[h[i]] - 1);
fw1.update(mp[h[i]], 1);
}
printf("%lld", ans);
return 0;
}
컴파일 시 표준 에러 (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... |