-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBCFRIEND.cpp
More file actions
65 lines (58 loc) · 1.26 KB
/
BCFRIEND.cpp
File metadata and controls
65 lines (58 loc) · 1.26 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
#include<bits/stdc++.h>
using namespace std;
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Ford(i, a, b) for(int i = a; i >= b; i--)
#define ll long long
#define here cout<<"I am Here"<<endl;
int const maxn = 1000000;
int const base = 1e9 + 7;
map <ll, ll> Mp, Xp;
long long Ar[maxn];
int main(void){
int N;
long long B;
cin>>N>>B;
For(i, 1, N){
cin>>Ar[i];
if(Ar[i] >= 0) Mp[Ar[i]]++;
if(Ar[i] < 0) Xp[abs(Ar[i])]++;
}
long long res = 0;
For(i, 1, N){
long long K = B - Ar[i];
if(Ar[i] >= 0){
if(K < 0){
if(Mp[Ar[i]] > 0 && Xp[abs(K)] > 0){
res += Xp[abs(K)] * Mp[Ar[i]];
Xp[abs(K)] = 0;
Mp[Ar[i]] = 0;
}
}
if(K >= 0){
if(Mp[Ar[i]] > 0 && Mp[K] > 0){
res += Mp[K] * Mp[Ar[i]];
Mp[K] = 0;
Mp[Ar[i]] = 0;
}
}
}
if(Ar[i] < 0){
if(K >= 0){
if(Xp[abs(Ar[i])] > 0 && Mp[K] > 0){
res += Mp[K] * Xp[abs(Ar[i])];
Mp[K] = 0;
Xp[abs(Ar[i])] = 0;
}
}
if(K < 0){
if(Xp[abs(Ar[i])] > 0 && Xp[abs(K)] > 0){
res += Xp[abs(K)] * Xp[abs(Ar[i])];
Xp[abs(K)] = 0;
Xp[abs(Ar[i])] = 0;
}
}
}
}
cout<<res;
return 0;
}