結果

問題 No.3128 Isosceles Triangle
ユーザー 沙耶花
提出日時 2025-04-25 21:35:00
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 371 ms / 2,500 ms
コード長 872 bytes
コンパイル時間 4,496 ms
コンパイル使用メモリ 257,632 KB
実行使用メモリ 20,436 KB
最終ジャッジ日時 2025-04-25 21:35:13
合計ジャッジ時間 9,662 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf32 1000000001
#define Inf64 4000000000000000001LL

int main(){
	
	int n;
	cin>>n;
	map<int,int> mp;
	rep(i,n){
		int a;
		cin>>a;
		mp[a]++;
	}
	
	vector<pair<long long,long long>> v;
	for(auto a:mp){
		v.push_back({a.first,a.second});
	}
	long long ans = 0;

	//a<b=c
	{
		long long sum = 0;
		rep(i,v.size()){
			long long t = v[i].second;
			ans += sum*t*(t-1)/2;
			sum += t;
		}
	}
	//a=b<c
	{
		long long sum = 0;
		int ci = v.size()-1;
		for(int i=v.size()-1;i>=0;i--){
			while(v[ci].first >= v[i].first * 2){
				sum -= v[ci].second;
				ci--;
			}
			long long t = v[i].second;
			ans += sum * t * (t-1) / 2 ;
			sum += t;
		}
	}
	cout<<ans<<endl;
	return 0;
}
0