Skip to content

Commit b0c4d57

Browse files
authored
Update day09sol02.cpp
1 parent b9064cd commit b0c4d57

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

Problems/Data-structures/Day-09/sol/day09sol02.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
//submission link- https://codeforces.com/contest/61/submission/356380170
22

33

4+
/*
5+
1. First, we change the big numbers into simple ranks (1, 2, 3...) so they are easy to count.
6+
2. We treat each number as the middle person and look at its neighbors.
7+
3. We count how many numbers to the left are bigger than our middle number.
8+
4. We count how many numbers to the right are smaller than our middle number.
9+
5. We multiply the bigger-left count by the smaller-right count to get the total triplets.
10+
6. We add up the triplets for every middle number to get the final answer.
11+
12+
Time Complexity: O(N \log N)
13+
Space Complexity: O(N)
14+
*/
15+
16+
417
#include <bits/stdc++.h>
518
using namespace std;
619

0 commit comments

Comments
 (0)