답안 #539376

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
539376 2022-03-18T19:19:33 Z singlabharat Mountains (NOI20_mountains) C++17
100 / 100
1041 ms 27084 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int long long
using vi = vector<int>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vector<int>>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
using si = set<int>;
using mii = map<int, int>;
template<typename T> using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sz(x) (int)size(x)
#define pb emplace_back
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define fr first
#define sc second
#define f(i, end) for (int i = 0; i < end; i++)
#define ff(i, start, end) for (int i = start; i < end; i++)
template<typename T, typename U> inline void domin(T &x, U y) {if (y < x) x = y;}
template<typename T, typename U> inline void domax(T &x, U y) {if (y > x) x = y;}
template<typename T, typename U> ostream& operator<<(ostream &os, const pair<T, U> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template < typename T_container, typename T = typename enable_if < !is_same<T_container, string>::value, typename T_container::value_type >::type > ostream & operator<<(ostream &os, const T_container &a) { os << '{'; string sep; for (const T &x : a) os << sep << x, sep = ", "; return os << '}';}
void debug() {cerr << endl;}
template <typename Head, typename... Tail> void debug(Head h, Tail... t) {cerr << h << ' '; debug(t...);}
#ifdef singlabharat
#define debug(...) cerr << "(" << #__VA_ARGS__ << ") : ", debug(__VA_ARGS__)
#else
#define debug(...)
#endif
#define endl '\n'
const int MX = 2e5 + 2, INF = 1e18;

void solve() {

	int n;
	cin >> n;
	vi a(n);
	f(i, n) cin >> a[i];
	int ans = 0;
	pbds<pii> osl, osr;
	f(i, n) osr.insert({a[i], i});
	debug(osl, osr);
	f(i, n) {
		osr.erase({a[i], i});
		ans += osl.order_of_key({a[i], 0}) * osr.order_of_key({a[i], 0});
		osl.insert({a[i], i});
	}
	cout << ans;
}

int32_t main() {

#ifdef singlabharat
	freopen("error.txt", "w", stderr);
#endif

	cin.tie(0)->sync_with_stdio(0);

	int t = 1;
	// cin >> t;

	for (int tc = 0; tc < t; tc++) solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 568 ms 26972 KB Output is correct
3 Correct 565 ms 26984 KB Output is correct
4 Correct 631 ms 26888 KB Output is correct
5 Correct 601 ms 27084 KB Output is correct
6 Correct 598 ms 26996 KB Output is correct
7 Correct 766 ms 26980 KB Output is correct
8 Correct 667 ms 26928 KB Output is correct
9 Correct 589 ms 27020 KB Output is correct
10 Correct 534 ms 27044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 326 ms 21964 KB Output is correct
2 Correct 369 ms 21948 KB Output is correct
3 Correct 314 ms 21964 KB Output is correct
4 Correct 327 ms 21948 KB Output is correct
5 Correct 383 ms 22000 KB Output is correct
6 Correct 327 ms 21936 KB Output is correct
7 Correct 350 ms 22036 KB Output is correct
8 Correct 550 ms 22060 KB Output is correct
9 Correct 525 ms 22040 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 326 ms 21964 KB Output is correct
2 Correct 369 ms 21948 KB Output is correct
3 Correct 314 ms 21964 KB Output is correct
4 Correct 327 ms 21948 KB Output is correct
5 Correct 383 ms 22000 KB Output is correct
6 Correct 327 ms 21936 KB Output is correct
7 Correct 350 ms 22036 KB Output is correct
8 Correct 550 ms 22060 KB Output is correct
9 Correct 525 ms 22040 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 686 ms 22232 KB Output is correct
12 Correct 698 ms 22300 KB Output is correct
13 Correct 668 ms 22240 KB Output is correct
14 Correct 696 ms 22200 KB Output is correct
15 Correct 720 ms 22204 KB Output is correct
16 Correct 704 ms 22252 KB Output is correct
17 Correct 762 ms 22268 KB Output is correct
18 Correct 549 ms 22212 KB Output is correct
19 Correct 548 ms 22268 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 328 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 13 ms 1260 KB Output is correct
12 Correct 11 ms 1152 KB Output is correct
13 Correct 13 ms 1100 KB Output is correct
14 Correct 12 ms 1104 KB Output is correct
15 Correct 12 ms 1108 KB Output is correct
16 Correct 11 ms 1104 KB Output is correct
17 Correct 11 ms 1108 KB Output is correct
18 Correct 12 ms 1216 KB Output is correct
19 Correct 14 ms 1076 KB Output is correct
20 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 326 ms 21964 KB Output is correct
2 Correct 369 ms 21948 KB Output is correct
3 Correct 314 ms 21964 KB Output is correct
4 Correct 327 ms 21948 KB Output is correct
5 Correct 383 ms 22000 KB Output is correct
6 Correct 327 ms 21936 KB Output is correct
7 Correct 350 ms 22036 KB Output is correct
8 Correct 550 ms 22060 KB Output is correct
9 Correct 525 ms 22040 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 686 ms 22232 KB Output is correct
12 Correct 698 ms 22300 KB Output is correct
13 Correct 668 ms 22240 KB Output is correct
14 Correct 696 ms 22200 KB Output is correct
15 Correct 720 ms 22204 KB Output is correct
16 Correct 704 ms 22252 KB Output is correct
17 Correct 762 ms 22268 KB Output is correct
18 Correct 549 ms 22212 KB Output is correct
19 Correct 548 ms 22268 KB Output is correct
20 Correct 1 ms 328 KB Output is correct
21 Correct 970 ms 23204 KB Output is correct
22 Correct 978 ms 23084 KB Output is correct
23 Correct 967 ms 23092 KB Output is correct
24 Correct 1041 ms 23140 KB Output is correct
25 Correct 958 ms 23156 KB Output is correct
26 Correct 981 ms 23176 KB Output is correct
27 Correct 894 ms 23076 KB Output is correct
28 Correct 525 ms 23116 KB Output is correct
29 Correct 540 ms 23164 KB Output is correct
30 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 568 ms 26972 KB Output is correct
3 Correct 565 ms 26984 KB Output is correct
4 Correct 631 ms 26888 KB Output is correct
5 Correct 601 ms 27084 KB Output is correct
6 Correct 598 ms 26996 KB Output is correct
7 Correct 766 ms 26980 KB Output is correct
8 Correct 667 ms 26928 KB Output is correct
9 Correct 589 ms 27020 KB Output is correct
10 Correct 534 ms 27044 KB Output is correct
11 Correct 326 ms 21964 KB Output is correct
12 Correct 369 ms 21948 KB Output is correct
13 Correct 314 ms 21964 KB Output is correct
14 Correct 327 ms 21948 KB Output is correct
15 Correct 383 ms 22000 KB Output is correct
16 Correct 327 ms 21936 KB Output is correct
17 Correct 350 ms 22036 KB Output is correct
18 Correct 550 ms 22060 KB Output is correct
19 Correct 525 ms 22040 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 686 ms 22232 KB Output is correct
22 Correct 698 ms 22300 KB Output is correct
23 Correct 668 ms 22240 KB Output is correct
24 Correct 696 ms 22200 KB Output is correct
25 Correct 720 ms 22204 KB Output is correct
26 Correct 704 ms 22252 KB Output is correct
27 Correct 762 ms 22268 KB Output is correct
28 Correct 549 ms 22212 KB Output is correct
29 Correct 548 ms 22268 KB Output is correct
30 Correct 1 ms 328 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 1 ms 328 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 1 ms 340 KB Output is correct
37 Correct 1 ms 340 KB Output is correct
38 Correct 1 ms 328 KB Output is correct
39 Correct 1 ms 340 KB Output is correct
40 Correct 1 ms 324 KB Output is correct
41 Correct 13 ms 1260 KB Output is correct
42 Correct 11 ms 1152 KB Output is correct
43 Correct 13 ms 1100 KB Output is correct
44 Correct 12 ms 1104 KB Output is correct
45 Correct 12 ms 1108 KB Output is correct
46 Correct 11 ms 1104 KB Output is correct
47 Correct 11 ms 1108 KB Output is correct
48 Correct 12 ms 1216 KB Output is correct
49 Correct 14 ms 1076 KB Output is correct
50 Correct 1 ms 324 KB Output is correct
51 Correct 970 ms 23204 KB Output is correct
52 Correct 978 ms 23084 KB Output is correct
53 Correct 967 ms 23092 KB Output is correct
54 Correct 1041 ms 23140 KB Output is correct
55 Correct 958 ms 23156 KB Output is correct
56 Correct 981 ms 23176 KB Output is correct
57 Correct 894 ms 23076 KB Output is correct
58 Correct 525 ms 23116 KB Output is correct
59 Correct 540 ms 23164 KB Output is correct
60 Correct 0 ms 212 KB Output is correct
61 Correct 902 ms 26896 KB Output is correct
62 Correct 859 ms 27044 KB Output is correct
63 Correct 891 ms 26872 KB Output is correct
64 Correct 908 ms 26980 KB Output is correct
65 Correct 842 ms 26916 KB Output is correct
66 Correct 920 ms 27080 KB Output is correct
67 Correct 895 ms 27060 KB Output is correct
68 Correct 891 ms 27004 KB Output is correct
69 Correct 903 ms 23184 KB Output is correct
70 Correct 1 ms 212 KB Output is correct