답안 #499376

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499376 2021-12-28T08:05:01 Z sumit_kk10 Mountains (NOI20_mountains) C++17
100 / 100
123 ms 32584 KB
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL) 
using namespace std;
const int N = 1e6 + 5;
int n, fenwick[N];

void upd(int x, int val){
	for(int i = x; i < N; i += (i & -i))
		fenwick[i] += val;
}

int get(int x){
	int ans = 0;
	for(int i = x; i >= 1; i -= (i & -i))
		ans += fenwick[i];
	return ans;
}

void solve(){
	cin >> n;
	vector<pair<long long, int> > v(n);
	for(int i = 0; i < n; ++i){
		cin >> v[i].first;
		v[i].second = i;
	}
	vector<long long> a(n);
	sort(v.begin(), v.end());
	int ct = 1;
	a[v[0].second] = ct;
	for(int i = 1; i < n; ++i){
		if(v[i].first != v[i - 1].first)
			++ct;
		a[v[i].second] = ct;
	}
	// for(auto k : a) cout << k << ' ';
    // cout << endl;
	long long pre[N], suf[N];
	for(int i = 0; i < n; ++i){
		int x = get(a[i] - 1);
		upd(a[i], 1);
		// cout << x << ' ';
		pre[i] = x;
	}
	// cout << endl;
	memset(fenwick, 0, sizeof fenwick);
	for(int i = n - 1; i >= 0; --i){
		int x = get(a[i] - 1);
		upd(a[i], 1);
		suf[i] = x;
	}
	long long ans = 0;
	for(int i = 1; i < n - 1; ++i)
		ans += (pre[i] * suf[i]);
	cout << ans << '\n';
}

int main() {
    fast;
    int t = 1;
    // cin >> t;
    while(t--)
    	solve();
	return 0;
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:61:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
   61 |     while(t--)
      |     ^~~~~
Mountains.cpp:63:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
   63 |  return 0;
      |  ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19876 KB Output is correct
2 Correct 116 ms 32580 KB Output is correct
3 Correct 105 ms 32432 KB Output is correct
4 Correct 92 ms 32440 KB Output is correct
5 Correct 87 ms 32452 KB Output is correct
6 Correct 98 ms 32432 KB Output is correct
7 Correct 97 ms 32556 KB Output is correct
8 Correct 88 ms 32436 KB Output is correct
9 Correct 105 ms 32556 KB Output is correct
10 Correct 83 ms 32436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 27436 KB Output is correct
2 Correct 104 ms 27440 KB Output is correct
3 Correct 78 ms 27444 KB Output is correct
4 Correct 78 ms 27496 KB Output is correct
5 Correct 84 ms 27440 KB Output is correct
6 Correct 84 ms 27492 KB Output is correct
7 Correct 90 ms 27508 KB Output is correct
8 Correct 63 ms 27448 KB Output is correct
9 Correct 62 ms 27440 KB Output is correct
10 Correct 8 ms 19788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 27436 KB Output is correct
2 Correct 104 ms 27440 KB Output is correct
3 Correct 78 ms 27444 KB Output is correct
4 Correct 78 ms 27496 KB Output is correct
5 Correct 84 ms 27440 KB Output is correct
6 Correct 84 ms 27492 KB Output is correct
7 Correct 90 ms 27508 KB Output is correct
8 Correct 63 ms 27448 KB Output is correct
9 Correct 62 ms 27440 KB Output is correct
10 Correct 8 ms 19788 KB Output is correct
11 Correct 91 ms 27708 KB Output is correct
12 Correct 88 ms 27756 KB Output is correct
13 Correct 81 ms 27756 KB Output is correct
14 Correct 81 ms 27740 KB Output is correct
15 Correct 83 ms 27688 KB Output is correct
16 Correct 79 ms 27704 KB Output is correct
17 Correct 96 ms 27716 KB Output is correct
18 Correct 60 ms 27756 KB Output is correct
19 Correct 60 ms 27716 KB Output is correct
20 Correct 8 ms 19788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 19824 KB Output is correct
2 Correct 8 ms 19848 KB Output is correct
3 Correct 8 ms 19860 KB Output is correct
4 Correct 9 ms 19828 KB Output is correct
5 Correct 11 ms 19816 KB Output is correct
6 Correct 10 ms 19828 KB Output is correct
7 Correct 10 ms 19788 KB Output is correct
8 Correct 8 ms 19788 KB Output is correct
9 Correct 8 ms 19788 KB Output is correct
10 Correct 8 ms 19788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 19824 KB Output is correct
2 Correct 8 ms 19848 KB Output is correct
3 Correct 8 ms 19860 KB Output is correct
4 Correct 9 ms 19828 KB Output is correct
5 Correct 11 ms 19816 KB Output is correct
6 Correct 10 ms 19828 KB Output is correct
7 Correct 10 ms 19788 KB Output is correct
8 Correct 8 ms 19788 KB Output is correct
9 Correct 8 ms 19788 KB Output is correct
10 Correct 8 ms 19788 KB Output is correct
11 Correct 11 ms 20300 KB Output is correct
12 Correct 11 ms 20232 KB Output is correct
13 Correct 11 ms 20216 KB Output is correct
14 Correct 11 ms 20300 KB Output is correct
15 Correct 11 ms 20208 KB Output is correct
16 Correct 11 ms 20304 KB Output is correct
17 Correct 10 ms 20316 KB Output is correct
18 Correct 11 ms 20208 KB Output is correct
19 Correct 12 ms 20084 KB Output is correct
20 Correct 8 ms 19788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 79 ms 27436 KB Output is correct
2 Correct 104 ms 27440 KB Output is correct
3 Correct 78 ms 27444 KB Output is correct
4 Correct 78 ms 27496 KB Output is correct
5 Correct 84 ms 27440 KB Output is correct
6 Correct 84 ms 27492 KB Output is correct
7 Correct 90 ms 27508 KB Output is correct
8 Correct 63 ms 27448 KB Output is correct
9 Correct 62 ms 27440 KB Output is correct
10 Correct 8 ms 19788 KB Output is correct
11 Correct 91 ms 27708 KB Output is correct
12 Correct 88 ms 27756 KB Output is correct
13 Correct 81 ms 27756 KB Output is correct
14 Correct 81 ms 27740 KB Output is correct
15 Correct 83 ms 27688 KB Output is correct
16 Correct 79 ms 27704 KB Output is correct
17 Correct 96 ms 27716 KB Output is correct
18 Correct 60 ms 27756 KB Output is correct
19 Correct 60 ms 27716 KB Output is correct
20 Correct 8 ms 19788 KB Output is correct
21 Correct 96 ms 28612 KB Output is correct
22 Correct 87 ms 28584 KB Output is correct
23 Correct 88 ms 28648 KB Output is correct
24 Correct 83 ms 28592 KB Output is correct
25 Correct 90 ms 28716 KB Output is correct
26 Correct 83 ms 28520 KB Output is correct
27 Correct 81 ms 28584 KB Output is correct
28 Correct 60 ms 28596 KB Output is correct
29 Correct 68 ms 28592 KB Output is correct
30 Correct 8 ms 19788 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 19876 KB Output is correct
2 Correct 116 ms 32580 KB Output is correct
3 Correct 105 ms 32432 KB Output is correct
4 Correct 92 ms 32440 KB Output is correct
5 Correct 87 ms 32452 KB Output is correct
6 Correct 98 ms 32432 KB Output is correct
7 Correct 97 ms 32556 KB Output is correct
8 Correct 88 ms 32436 KB Output is correct
9 Correct 105 ms 32556 KB Output is correct
10 Correct 83 ms 32436 KB Output is correct
11 Correct 79 ms 27436 KB Output is correct
12 Correct 104 ms 27440 KB Output is correct
13 Correct 78 ms 27444 KB Output is correct
14 Correct 78 ms 27496 KB Output is correct
15 Correct 84 ms 27440 KB Output is correct
16 Correct 84 ms 27492 KB Output is correct
17 Correct 90 ms 27508 KB Output is correct
18 Correct 63 ms 27448 KB Output is correct
19 Correct 62 ms 27440 KB Output is correct
20 Correct 8 ms 19788 KB Output is correct
21 Correct 91 ms 27708 KB Output is correct
22 Correct 88 ms 27756 KB Output is correct
23 Correct 81 ms 27756 KB Output is correct
24 Correct 81 ms 27740 KB Output is correct
25 Correct 83 ms 27688 KB Output is correct
26 Correct 79 ms 27704 KB Output is correct
27 Correct 96 ms 27716 KB Output is correct
28 Correct 60 ms 27756 KB Output is correct
29 Correct 60 ms 27716 KB Output is correct
30 Correct 8 ms 19788 KB Output is correct
31 Correct 8 ms 19824 KB Output is correct
32 Correct 8 ms 19848 KB Output is correct
33 Correct 8 ms 19860 KB Output is correct
34 Correct 9 ms 19828 KB Output is correct
35 Correct 11 ms 19816 KB Output is correct
36 Correct 10 ms 19828 KB Output is correct
37 Correct 10 ms 19788 KB Output is correct
38 Correct 8 ms 19788 KB Output is correct
39 Correct 8 ms 19788 KB Output is correct
40 Correct 8 ms 19788 KB Output is correct
41 Correct 11 ms 20300 KB Output is correct
42 Correct 11 ms 20232 KB Output is correct
43 Correct 11 ms 20216 KB Output is correct
44 Correct 11 ms 20300 KB Output is correct
45 Correct 11 ms 20208 KB Output is correct
46 Correct 11 ms 20304 KB Output is correct
47 Correct 10 ms 20316 KB Output is correct
48 Correct 11 ms 20208 KB Output is correct
49 Correct 12 ms 20084 KB Output is correct
50 Correct 8 ms 19788 KB Output is correct
51 Correct 96 ms 28612 KB Output is correct
52 Correct 87 ms 28584 KB Output is correct
53 Correct 88 ms 28648 KB Output is correct
54 Correct 83 ms 28592 KB Output is correct
55 Correct 90 ms 28716 KB Output is correct
56 Correct 83 ms 28520 KB Output is correct
57 Correct 81 ms 28584 KB Output is correct
58 Correct 60 ms 28596 KB Output is correct
59 Correct 68 ms 28592 KB Output is correct
60 Correct 8 ms 19788 KB Output is correct
61 Correct 108 ms 32428 KB Output is correct
62 Correct 117 ms 32584 KB Output is correct
63 Correct 123 ms 32432 KB Output is correct
64 Correct 107 ms 32452 KB Output is correct
65 Correct 118 ms 32528 KB Output is correct
66 Correct 109 ms 32440 KB Output is correct
67 Correct 107 ms 32360 KB Output is correct
68 Correct 117 ms 32488 KB Output is correct
69 Correct 92 ms 28704 KB Output is correct
70 Correct 8 ms 19788 KB Output is correct