#include<bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define FOR(i,n) for(i=0;i<(n);++i)
#define FORe(i,n) for(i=1;i<=(n);++i)
#define FORr(i,a,b) for(i=(a);i<(b);++i)
#define FORrev(i,n) for(i=(n);i>=0;--i)
#define F0R(i,n) for(int i=0;i<(n);++i)
#define F0Re(i,n) for(int i=1;i<=(n);++i)
#define F0Rr(i,a,b) for(ll i=(a);i<(b);++i)
#define F0Rrev(i,n) for(int i=(n);i>=0;--i)
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define ff first
#define ss second
#define cd complex<double>
#define vcd vector<cd>
#define ldd long double
#define dbgLine cout<<"Line : "<<__LINE__<<'\n'
#define all(x) (x).begin(),(x).end()
using namespace std;
const short int __PRECISION = 10;
const ll MOD = 1e9+7;
const ll INF = 1e17 + 1101;
const ll LOGN = 17;
const ll MAXN = 3e5+5;
const ll ROOTN = 320;
const ldd PI = acos(-1);
const ldd EPS = 1e-7;
struct SegTree
{
int st[4*MAXN];
void upd(int node, int ss, int se, int i)
{
if(ss > i or se < i)
return;
if(ss == se)
{
++st[node];
return;
}
int mid = (ss + se)/2;
upd(node*2 + 1, ss, mid, i);
upd(node*2 + 2, mid+1, se, i);
st[node] = st[node*2+1] + st[node*2+2];
}
ll quer(int node, int ss, int se, int l, int r)
{
if(ss > r or se < l) return 0;
if(ss >= l and se <= r) return st[node];
int mid = (ss + se) / 2;
return quer(node*2+1, ss, mid,l,r) + quer(node*2+2,mid+1,se,l,r);
}
SegTree()
{
F0R(i, 4*MAXN)
st[i] = 0;
}
inline void update(int i)
{
upd(0, 0, MAXN, i);
}
inline ll query(int i, int ded)
{
ll a = quer(0, 0, MAXN, 0, i-1) - ded, b = quer(0, 0, MAXN, i+1, MAXN);
// cout<<"a = "<<a<<", b = "<<b<<'\n';
return (a*b);
}
} S;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int N;
cin>>N;
pair<ll, int> A[N];
F0R(i, N)
{
ll j;
cin>>j;
A[i] = mp(j, i+1);
}
sort(A, A + N);
ll previo = -1, tot = 0, ans = 0;
F0R(i, N)
{
// cout<<"for ("<<A[i].ff<<','<<A[i].ss<<") : ";
if(A[i].ff != previo)
tot = 0;
S.update(A[i].ss);
ans += S.query(A[i].ss, tot);
// cout<<"tot = "<<tot<<", previo = "<<previo<<", no. of combinations is "<<tmp<<'\n';
previo = A[i].ff;
++tot;
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4992 KB |
Output is correct |
2 |
Correct |
181 ms |
9856 KB |
Output is correct |
3 |
Correct |
183 ms |
9848 KB |
Output is correct |
4 |
Correct |
187 ms |
9728 KB |
Output is correct |
5 |
Correct |
182 ms |
9728 KB |
Output is correct |
6 |
Correct |
184 ms |
9848 KB |
Output is correct |
7 |
Correct |
194 ms |
9780 KB |
Output is correct |
8 |
Correct |
184 ms |
9804 KB |
Output is correct |
9 |
Correct |
192 ms |
9728 KB |
Output is correct |
10 |
Correct |
189 ms |
9728 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
9728 KB |
Output is correct |
2 |
Correct |
173 ms |
9908 KB |
Output is correct |
3 |
Correct |
172 ms |
9856 KB |
Output is correct |
4 |
Correct |
164 ms |
9856 KB |
Output is correct |
5 |
Correct |
168 ms |
9856 KB |
Output is correct |
6 |
Correct |
170 ms |
9904 KB |
Output is correct |
7 |
Correct |
165 ms |
9856 KB |
Output is correct |
8 |
Correct |
142 ms |
9856 KB |
Output is correct |
9 |
Correct |
142 ms |
9856 KB |
Output is correct |
10 |
Correct |
7 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
9728 KB |
Output is correct |
2 |
Correct |
173 ms |
9908 KB |
Output is correct |
3 |
Correct |
172 ms |
9856 KB |
Output is correct |
4 |
Correct |
164 ms |
9856 KB |
Output is correct |
5 |
Correct |
168 ms |
9856 KB |
Output is correct |
6 |
Correct |
170 ms |
9904 KB |
Output is correct |
7 |
Correct |
165 ms |
9856 KB |
Output is correct |
8 |
Correct |
142 ms |
9856 KB |
Output is correct |
9 |
Correct |
142 ms |
9856 KB |
Output is correct |
10 |
Correct |
7 ms |
4992 KB |
Output is correct |
11 |
Correct |
213 ms |
9976 KB |
Output is correct |
12 |
Correct |
205 ms |
9900 KB |
Output is correct |
13 |
Correct |
206 ms |
9856 KB |
Output is correct |
14 |
Correct |
217 ms |
9976 KB |
Output is correct |
15 |
Correct |
215 ms |
9976 KB |
Output is correct |
16 |
Correct |
213 ms |
9976 KB |
Output is correct |
17 |
Correct |
218 ms |
9976 KB |
Output is correct |
18 |
Correct |
142 ms |
9856 KB |
Output is correct |
19 |
Correct |
145 ms |
9856 KB |
Output is correct |
20 |
Correct |
7 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
4992 KB |
Output is correct |
3 |
Correct |
7 ms |
4992 KB |
Output is correct |
4 |
Correct |
7 ms |
4992 KB |
Output is correct |
5 |
Correct |
9 ms |
5120 KB |
Output is correct |
6 |
Correct |
7 ms |
4992 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
4992 KB |
Output is correct |
9 |
Correct |
7 ms |
4992 KB |
Output is correct |
10 |
Correct |
7 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
4992 KB |
Output is correct |
2 |
Correct |
7 ms |
4992 KB |
Output is correct |
3 |
Correct |
7 ms |
4992 KB |
Output is correct |
4 |
Correct |
7 ms |
4992 KB |
Output is correct |
5 |
Correct |
9 ms |
5120 KB |
Output is correct |
6 |
Correct |
7 ms |
4992 KB |
Output is correct |
7 |
Correct |
8 ms |
5120 KB |
Output is correct |
8 |
Correct |
7 ms |
4992 KB |
Output is correct |
9 |
Correct |
7 ms |
4992 KB |
Output is correct |
10 |
Correct |
7 ms |
4992 KB |
Output is correct |
11 |
Correct |
15 ms |
5120 KB |
Output is correct |
12 |
Correct |
15 ms |
5120 KB |
Output is correct |
13 |
Correct |
15 ms |
5248 KB |
Output is correct |
14 |
Correct |
14 ms |
5120 KB |
Output is correct |
15 |
Correct |
15 ms |
5248 KB |
Output is correct |
16 |
Correct |
15 ms |
5248 KB |
Output is correct |
17 |
Correct |
14 ms |
5120 KB |
Output is correct |
18 |
Correct |
15 ms |
5248 KB |
Output is correct |
19 |
Correct |
14 ms |
5248 KB |
Output is correct |
20 |
Correct |
7 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
163 ms |
9728 KB |
Output is correct |
2 |
Correct |
173 ms |
9908 KB |
Output is correct |
3 |
Correct |
172 ms |
9856 KB |
Output is correct |
4 |
Correct |
164 ms |
9856 KB |
Output is correct |
5 |
Correct |
168 ms |
9856 KB |
Output is correct |
6 |
Correct |
170 ms |
9904 KB |
Output is correct |
7 |
Correct |
165 ms |
9856 KB |
Output is correct |
8 |
Correct |
142 ms |
9856 KB |
Output is correct |
9 |
Correct |
142 ms |
9856 KB |
Output is correct |
10 |
Correct |
7 ms |
4992 KB |
Output is correct |
11 |
Correct |
213 ms |
9976 KB |
Output is correct |
12 |
Correct |
205 ms |
9900 KB |
Output is correct |
13 |
Correct |
206 ms |
9856 KB |
Output is correct |
14 |
Correct |
217 ms |
9976 KB |
Output is correct |
15 |
Correct |
215 ms |
9976 KB |
Output is correct |
16 |
Correct |
213 ms |
9976 KB |
Output is correct |
17 |
Correct |
218 ms |
9976 KB |
Output is correct |
18 |
Correct |
142 ms |
9856 KB |
Output is correct |
19 |
Correct |
145 ms |
9856 KB |
Output is correct |
20 |
Correct |
7 ms |
4992 KB |
Output is correct |
21 |
Correct |
257 ms |
9856 KB |
Output is correct |
22 |
Correct |
267 ms |
9856 KB |
Output is correct |
23 |
Correct |
248 ms |
9856 KB |
Output is correct |
24 |
Correct |
257 ms |
9856 KB |
Output is correct |
25 |
Correct |
258 ms |
9976 KB |
Output is correct |
26 |
Correct |
261 ms |
9976 KB |
Output is correct |
27 |
Correct |
247 ms |
9856 KB |
Output is correct |
28 |
Correct |
163 ms |
9856 KB |
Output is correct |
29 |
Correct |
159 ms |
9976 KB |
Output is correct |
30 |
Correct |
7 ms |
4992 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
4992 KB |
Output is correct |
2 |
Correct |
181 ms |
9856 KB |
Output is correct |
3 |
Correct |
183 ms |
9848 KB |
Output is correct |
4 |
Correct |
187 ms |
9728 KB |
Output is correct |
5 |
Correct |
182 ms |
9728 KB |
Output is correct |
6 |
Correct |
184 ms |
9848 KB |
Output is correct |
7 |
Correct |
194 ms |
9780 KB |
Output is correct |
8 |
Correct |
184 ms |
9804 KB |
Output is correct |
9 |
Correct |
192 ms |
9728 KB |
Output is correct |
10 |
Correct |
189 ms |
9728 KB |
Output is correct |
11 |
Correct |
163 ms |
9728 KB |
Output is correct |
12 |
Correct |
173 ms |
9908 KB |
Output is correct |
13 |
Correct |
172 ms |
9856 KB |
Output is correct |
14 |
Correct |
164 ms |
9856 KB |
Output is correct |
15 |
Correct |
168 ms |
9856 KB |
Output is correct |
16 |
Correct |
170 ms |
9904 KB |
Output is correct |
17 |
Correct |
165 ms |
9856 KB |
Output is correct |
18 |
Correct |
142 ms |
9856 KB |
Output is correct |
19 |
Correct |
142 ms |
9856 KB |
Output is correct |
20 |
Correct |
7 ms |
4992 KB |
Output is correct |
21 |
Correct |
213 ms |
9976 KB |
Output is correct |
22 |
Correct |
205 ms |
9900 KB |
Output is correct |
23 |
Correct |
206 ms |
9856 KB |
Output is correct |
24 |
Correct |
217 ms |
9976 KB |
Output is correct |
25 |
Correct |
215 ms |
9976 KB |
Output is correct |
26 |
Correct |
213 ms |
9976 KB |
Output is correct |
27 |
Correct |
218 ms |
9976 KB |
Output is correct |
28 |
Correct |
142 ms |
9856 KB |
Output is correct |
29 |
Correct |
145 ms |
9856 KB |
Output is correct |
30 |
Correct |
7 ms |
4992 KB |
Output is correct |
31 |
Correct |
7 ms |
4992 KB |
Output is correct |
32 |
Correct |
7 ms |
4992 KB |
Output is correct |
33 |
Correct |
7 ms |
4992 KB |
Output is correct |
34 |
Correct |
7 ms |
4992 KB |
Output is correct |
35 |
Correct |
9 ms |
5120 KB |
Output is correct |
36 |
Correct |
7 ms |
4992 KB |
Output is correct |
37 |
Correct |
8 ms |
5120 KB |
Output is correct |
38 |
Correct |
7 ms |
4992 KB |
Output is correct |
39 |
Correct |
7 ms |
4992 KB |
Output is correct |
40 |
Correct |
7 ms |
4992 KB |
Output is correct |
41 |
Correct |
15 ms |
5120 KB |
Output is correct |
42 |
Correct |
15 ms |
5120 KB |
Output is correct |
43 |
Correct |
15 ms |
5248 KB |
Output is correct |
44 |
Correct |
14 ms |
5120 KB |
Output is correct |
45 |
Correct |
15 ms |
5248 KB |
Output is correct |
46 |
Correct |
15 ms |
5248 KB |
Output is correct |
47 |
Correct |
14 ms |
5120 KB |
Output is correct |
48 |
Correct |
15 ms |
5248 KB |
Output is correct |
49 |
Correct |
14 ms |
5248 KB |
Output is correct |
50 |
Correct |
7 ms |
4992 KB |
Output is correct |
51 |
Correct |
257 ms |
9856 KB |
Output is correct |
52 |
Correct |
267 ms |
9856 KB |
Output is correct |
53 |
Correct |
248 ms |
9856 KB |
Output is correct |
54 |
Correct |
257 ms |
9856 KB |
Output is correct |
55 |
Correct |
258 ms |
9976 KB |
Output is correct |
56 |
Correct |
261 ms |
9976 KB |
Output is correct |
57 |
Correct |
247 ms |
9856 KB |
Output is correct |
58 |
Correct |
163 ms |
9856 KB |
Output is correct |
59 |
Correct |
159 ms |
9976 KB |
Output is correct |
60 |
Correct |
7 ms |
4992 KB |
Output is correct |
61 |
Correct |
286 ms |
9976 KB |
Output is correct |
62 |
Correct |
283 ms |
9984 KB |
Output is correct |
63 |
Correct |
279 ms |
9856 KB |
Output is correct |
64 |
Correct |
274 ms |
9976 KB |
Output is correct |
65 |
Correct |
278 ms |
9976 KB |
Output is correct |
66 |
Correct |
283 ms |
9976 KB |
Output is correct |
67 |
Correct |
275 ms |
9856 KB |
Output is correct |
68 |
Correct |
281 ms |
9856 KB |
Output is correct |
69 |
Correct |
247 ms |
9856 KB |
Output is correct |
70 |
Correct |
7 ms |
5120 KB |
Output is correct |