记录编号 | 73235 | 评测结果 | AAAAAAAAAAA | ||
---|---|---|---|---|---|
题目名称 | 数对的个数 | 最终得分 | 100 | ||
用户昵称 | 是否通过 | 通过 | |||
代码语言 | C++ | 运行时间 | 0.080 s | ||
提交时间 | 2013-10-20 21:22:31 | 内存使用 | 0.31 MiB | ||
- #include <fstream>
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <climits>
- using namespace std;
- ifstream in("dec.in");
- ofstream out("dec.out");
- struct node
- {
- node(long i,long n):index(i),num(n){}
- long index;
- long num;
- };
- node make(long i,long n)
- {
- node ret(i,n);
- return ret;
- }
- long n,c;
- long *f;
- long ans(0);
- void input();
- void proc();
- void output();
- int main()
- {
- input();
- proc();
- output();
- return 0;
- }
- void input()
- {
- in>>n>>c;
- f=new long [n];
- for(int i=0;i!=n;++i)
- {
- in>>f[i];
- }
- return ;
- }
- void proc()
- {
- if(n==1)
- {
- return ;
- }
- vector<node> nvector;
- nvector.reserve(n);
- stable_sort(f,f+n);
- long comp(f[0]);
- long num(0);
- //long j(0);
- for(int i=0;i!=n;++i)
- {
- if(f[i]==comp)
- {
- ++num;
- continue;
- }
- if(f[i]>comp)
- {
- nvector.push_back(make(comp,num));
- //out<<nvector[j].index<<' '<<nvector[j].num<<endl;
- //++j;
- comp=f[i];
- num=1;
- }
- }
- nvector.push_back(make(comp,num));
- //out<<nvector[j].index<<' '<<nvector[j].num<<endl;
- unsigned long i(0);
- #define nv nvector
- for(unsigned long j=0;j!=nv.size();)
- {
- if(nv[j].index-nv[i].index==c)
- {
- ans+=nv[j].num*nv[i].num;
- ++i;
- ++j;
- continue;
- }
- if(nv[j].index-nv[i].index<c)
- {
- ++j;
- continue;
- }
- if(nv[j].index-nv[i].index>c)
- {
- ++i;
- continue;
- }
- }
- return ;
- }
- void output()
- {
- out<<ans<<endl;
- return ;
- }
- /* if(f[i]>comp)
- {
- nlist.push_back(make(comp,num));
- out<<(*(nlist.end()-1)).index<<' '<<(*(nlist.end()-1)).num<<endl;
- if(comp-lmin==c)
- {
- node ntemp(nlist.front());
- ans+=ntemp.num*num;
- nlist.pop_front();
- lmin=nlist.front().index;
- }
- if(comp-lmin>c)
- {
- nlist.pop_front();
- lmin=nlist.front().index;
- }
- comp=f[i];
- num=1;
- }
- */