結果

問題 No.1079 まお
ユーザー chocoruskchocorusk
提出日時 2020-06-12 23:09:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,466 bytes
コンパイル時間 1,582 ms
コンパイル使用メモリ 144,072 KB
実行使用メモリ 29,004 KB
最終ジャッジ日時 2023-09-06 11:15:38
合計ジャッジ時間 14,788 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 331 ms
15,960 KB
testcase_13 AC 391 ms
18,484 KB
testcase_14 AC 516 ms
21,272 KB
testcase_15 AC 590 ms
23,484 KB
testcase_16 AC 671 ms
26,056 KB
testcase_17 WA -
testcase_18 AC 699 ms
24,916 KB
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 790 ms
28,752 KB
testcase_23 AC 811 ms
28,744 KB
testcase_24 AC 817 ms
28,896 KB
testcase_25 AC 809 ms
28,756 KB
testcase_26 AC 820 ms
28,812 KB
testcase_27 AC 48 ms
4,380 KB
testcase_28 AC 377 ms
19,648 KB
testcase_29 AC 487 ms
29,004 KB
testcase_30 AC 500 ms
28,784 KB
testcase_31 AC 64 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#define popcount __builtin_popcount
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n, k;
int a[100010];
ll ans;
void solve(int l, int r){
	if(l==r){
		if(a[l]+a[r]==k) ans++;
		return;
	}
	int m=(l+r)/2;
	int mn=1e9+7, cnt=0;
	map<int, ll> mp1, mp11;
	map<P, ll> mp2, mp22;
	for(int i=m; i>=l; i--){
		if(mn>a[i]){
			mn=a[i], cnt=1;
		}else if(mn==a[i]){
			cnt++;
		}
		if(cnt==1){
			mp1[a[i]]++;
			mp2[{a[i], mn}]++;
			mp11[a[i]]+=(m+1-i);
			mp22[{a[i], mn}]+=(m+1-i);
		}
	}
	mn=1e9+7, cnt=0;
	for(int i=m+1; i<=r; i++){
		if(mn>a[i]){
			mn=a[i], cnt=1;
		}else if(mn==a[i]){
			cnt++;
		}
		if(cnt==1){
			auto itr1=mp1.find(k-a[i]);
			if(itr1!=mp1.end()){
				ans+=itr1->second*(i-m);
				ans+=mp11[k-a[i]];
				auto itr2=mp2.find({k-a[i], mn});
				if(itr2!=mp2.end()){
					ans-=itr2->second*(i-m);
					ans-=mp22[{k-a[i], mn}];
				}
			}
		}
	}
	solve(l, m); solve(m+1, r);
}
int main()
{
	cin>>n>>k;
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	solve(0, n-1);
	cout<<ans<<endl;
	return 0;
}
0