Submission #2598359


Source Code Expand

Copy
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//cout<<setprecision(20)
//cin.tie(0);
//ios::sync_with_stdio(false);
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
llint LBI(vector<llint>&ar,llint in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
llint UBI(vector<llint>&ar,llint in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	llint n,i,ans=0,D;cin>>n>>D;
	vector<llint>x(n);
	for(i=0;i<n;i++){cin>>x[i];}
	for(i=0;i<n;i++){
		llint L=i-LBI(x,x[i]-D);
		llint R=UBI(x,x[i]+D)-i-1;
		//cerr<<L<<" "<<R<<endl;
		ans+=L*R;
		ans-=L*(L-1)/2;
	}
	cout<<ans<<endl;
}

Submission Info

Submission Time
Task C - 徒歩圏内
User WA_TLE
Language C++14 (GCC 5.4.1)
Score 400
Code Size 1702 Byte
Status
Exec Time 50 ms
Memory 1024 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
All 400 / 400 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt
Case Name Status Exec Time Memory
01.txt 49 ms 1024 KB
02.txt 50 ms 1024 KB
03.txt 45 ms 1024 KB
04.txt 49 ms 1024 KB
05.txt 49 ms 1024 KB
06.txt 47 ms 1024 KB
07.txt 39 ms 1024 KB
08.txt 37 ms 896 KB
09.txt 1 ms 256 KB
10.txt 47 ms 1024 KB
11.txt 49 ms 1024 KB
12.txt 46 ms 1024 KB
sample-01.txt 1 ms 256 KB
sample-02.txt 1 ms 256 KB
sample-03.txt 1 ms 256 KB
sample-04.txt 1 ms 256 KB