forked from itsyadavRajkumar/DSA
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTime.cpp
More file actions
108 lines (74 loc) · 1.82 KB
/
Time.cpp
File metadata and controls
108 lines (74 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
ContestName = Shinchu_itachi
" Walking on the road not taken with my own gutts.. "
*/
#include <bits/stdc++.h>
using namespace std ;
vector<int> bit(N);
int n ;
long long sum ( int i ) {
long long r = 0 ;
while ( i > 0) {
r += bit[i];
i -= ( i & -i);
}
return r;
}
void update ( int i , int val ) {
while ( i < n ) {
bit[i] += val;
i += (i & -i);
}
}
void cal ( vi &a ) {
vi b ;
for ( auto i : a ) b.pb(2 * i);
set <long long > st;
st.insert( a.begin() , a.end());
for ( auto i : b) st.insert(i);
for ( auto i : st) cout << i << " ";
cout << endl;
map<long long , int> mp;
cout << endl;
int p = 1;
for ( auto &i : st) mp[i] = p++;
for ( auto i : mp) cout << i.first << " -> " << i.second << endl;
cout << endl;
int c = 0 ;
for ( int i = b.size() - 1 ; i >= 0 ; i --) {
cout << a[i] << " -> " << mp[b[i]] << " -> " << sum(mp[b[i] / 2] ) << endl;
c += ( sum (mp[b[i] / 2 * 1LL] - 1));
update(mp[b[i]] , 1 );
}
cout << c << endl;
}
void solve() {
cin >> n ;
vi a( n , 0);
fin(a)
cout << endl;
cal ( a );
}
inline void testcases() {
int test = 1, testcase = 1 ;
//cin >> test ;
cout << setprecision(12) ;
cerr << setprecision(8) ;
while (test --) {
// cout << "Case #" << testcase++ << ": ";
solve () ;
}
}
int main () {
fastio();
#ifndef ONLINE_JUDGE
// freopen("output.txt", "w", stdout);
// freopen("input.txt", "r", stdin);
//freopen("error.txt", "w", stderr);
#endif
auto start = high_resolution_clock::now();
testcases();
auto end = high_resolution_clock::now();
auto duration = duration_cast<microseconds>(end - start);
cerr << "Time : " << duration.count() / 1000 ;
}