Advertisement
Ahmed_Negm

Untitled

Apr 21st, 2022
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.54 KB | None | 0 0
  1. #include<iostream>
  2. #include<cmath>
  3. #include<iomanip>
  4. #include<algorithm>
  5. #include<cstdlib>
  6. #include<cstring>
  7. #include<vector>
  8. #include<utility>
  9.  
  10. #define ll long long
  11. #define sz(x) int(x.size())
  12. #define all(x) x.begin(),x.end()
  13. #define rall(s)  s.rbegin(), s.rend()
  14. #define ceill(n, m) (((n) / (m)) + ((n) % (m) ? 1 : 0))
  15. using namespace std;
  16.  
  17. void Fast_IO(){
  18.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  19.     #ifndef ONLINE_JUDGE
  20.         freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  21.     #endif
  22. }
  23.  
  24.  
  25.  
  26.  
  27.  
  28. void solve(){
  29.   ll n,k; cin>>n>>k;
  30.   vector<ll>v;
  31.   vector<ll>negative(10000005);
  32.   vector<ll>positive(10000005);
  33.   while(n--){
  34.       ll x; cin>>x;
  35.       if(x<0){
  36.             if(negative[abs(x)]==0){
  37.               v.push_back(x);
  38.             }
  39.             negative[abs(x)]++;
  40.       }else{
  41.           if(positive[x]==0){
  42.               v.push_back(x);
  43.           }
  44.            positive[x]++;
  45.       }
  46.      
  47.   }
  48.   ll counter=0;
  49.   if(k==0){
  50. for(int i=0;i<sz(v);i++){
  51.     if(v[i]<0){
  52.         if(negative[abs(v[i])]>1) counter++;
  53.     }else{
  54.         if(positive[v[i]]>1) counter++;
  55.     }
  56.   }
  57.   }else{
  58.   for(int i=0;i<sz(v);i++){
  59.       if(v[i]<0){
  60. if(negative[abs(k-v[i])] and abs(k-v[i]) != abs(v[i])) counter++;
  61.  
  62.       }else{
  63.           if(positive[abs(k-v[i])] && abs(k-v[i]) != abs(v[i])) counter++;
  64.       }
  65.        
  66.   }
  67.   }
  68.  
  69.  
  70. cout<<counter;
  71.  
  72.  
  73.  
  74. }
  75.  
  76. int main(){
  77.     Fast_IO();
  78. int t =1;
  79. //cin>>t;
  80. while(t--){
  81. solve();
  82. }
  83. return 0;
  84. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement