萌新求条A-B
  • 板块灌水区
  • 楼主BK小鹿
  • 当前回复13
  • 已保存回复13
  • 发布时间2024/8/31 20:29
  • 上次更新2024/9/1 07:20:09
查看原帖
萌新求条A-B
1345783
BK小鹿楼主2024/8/31 20:29

rt,题目

代码只有92分,不知道为啥

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

#define gc() (p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<20,stdin),p1==p2)?EOF:*p1++)
char *p1,*p2,buf[1<<20+5];
inline int read(){
int x=0;
char c=gc();
while(!isdigit(c)){
c=gc();
}while(isdigit(c)){
x=x*10+(c^48);
c=gc();
}return x;
}

const int N = 2e5 + 5;

int n, c;
map<long long, long long> m;
int a[N];
long long res;

int main()
{
    int cnt = 0, cnt1 = 0;
    n = read(), c = read();
    for (int i = 1; i <= n; i ++ )
    {
         a[i] = read();
         if (a[i] >= c) m[a[i]] ++ , a[i] -= c;
    }
/*    for (int i = 1; i <= n; i ++ )
      if (a[i] > c)
        b[++ b[0]] = a[i];
      else if (a[i] == c) cnt ++ ;
    
    for (int i = 1; i <= n; i ++ )
      if (a[i] == 0)
        cnt1 ++ ;

    sort(b + 1, b + n + 1);
    for (int i = n; i >= 1; i -- )
    {
      if (b[i] < c) break;
      for (int j = 1; j <= i; j ++ )
        if (b[i] - b[j] == c) res ++ ;
        else if (b[i] - b[j] < c) break;
    }
    res += cnt1 * cnt;*/
    for (int i = 1; i <= n; i ++ ) res += m[a[i]];
    printf("%lld\n", res);
    return 0;
}
2024/8/31 20:29
加载中...