-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathE. Enemy is weak.cpp
184 lines (110 loc) · 4.57 KB
/
E. Enemy is weak.cpp
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/// BISMILLAHIR RAHMANIR RAHEEM
/// ALLAH IS WATCHING ME
/// Every soul shall taste death.
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
/// order_of_key return number of elements less than x.
/// find_by_order return index.
using namespace std;
using namespace __gnu_pbds;
#define MUHAMMAD ios::sync_with_stdio(0);cin.tie(0);
#define all(x) (x).begin(), (x).end()
#define AE cout << fixed << setprecision(10);
#define ld double
#define f first
#define ss second
/// faster.
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}; // 8-direction.......
int dy8[] = {1,-1, 1, -1, 0, 0, -1, 1};
int dx4[]= {1,-1,0,0}; // 4-direction...........
int dy4[]= {0,0,1,-1};
using ll = long long;
const ll MOD = 1e9+7;
const ld PI = acos(-1.0);
typedef tree< int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree< int, null_type, greater<int>, rb_tree_tag,tree_order_statistics_node_update> Rordered_set;
typedef tree<pair<int, int>,null_type,less<pair<int, int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
//debug
template<typename F,typename S>ostream&operator<<(ostream&os,const pair<F,S>&p){return os<<"("<<p.first<<", "<<p.second<<")";}
template<typename T>ostream&operator<<(ostream&os,const vector<T>&v){os<<"{";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"}";}
template<typename T>ostream&operator<<(ostream&os,const set<T>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<",";os<<*it;}return os<<"]";}
template<typename T>ostream&operator<<(ostream&os,const multiset<T>&v) {os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<*it;}return os<<"]";}
template<typename F,typename S>ostream&operator<<(ostream&os,const map<F,S>&v){os<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<it->first<<" = "<<it->second;}return os<<"]";}
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu(){cerr << endl;}
template<typename T>void faltu(T a[],int n){for(int i=0;i<n;++i)cerr<<a[i]<<' ';cerr<<endl;}
template<typename T,typename...hello>void faltu(T arg,const hello&...rest){cerr<<arg<<' ';faltu(rest...);}
//#else
//#define dbg(args...)
/// Modular arithmetic
inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); } /// When MOD is prime.
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }
/// Geometry section.
ld degree_to_radian( ld x ){
ld ans = ((ld)(acos(-1.0)/180.0)*x);
return ans;
}
//*********************************************** The END **********************************************************************************************************************************
const int N = 1e6 + 5;
const ll INF = 1e18;
const ld EPS = 1e-9;
const ll limit = (1LL<<32) - 1;
const ll K = 1e12;
/// --------------------------------------------------------------
ll arr[N];
ll brr[N];
ll res = 0;
int n , q;
void Solution ( int tc ){
cin >> n;
ordered_set coto;
Rordered_set boro;
for ( int i = 1 ; i<=n ; ++i ) {
cin >> arr[i];
coto.insert ( arr[i] );
}
for ( int i = 1 ; i <= n ; ++i ) {
coto.erase ( arr[i] );
res+=(1LL*boro.order_of_key ( arr[i] )*coto.order_of_key ( arr[i] ) );
boro.insert ( arr[i] );
}
cout << res << "\n";
return;
}
int main()
{
MUHAMMAD;
/// AE;
/*
#ifdef OJ
freopen("window.in", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
*/
int testcase = 1 , tc = 0;
/// cin >> testcase;
for ( int i = 1 ; i <= testcase ; ++i ){
Solution( ++tc );
}
return 0;
}
/// __mhs, Do you check
/// -> overflow
/// -> array bound.
/*
LCA:
https://codeforces.com/contest/1304/problem/E
Explanation:
Time :
----------------------------------------------------------------------------------------------------------------
Alhamdulillah
*/