結果

問題 No.1079 まお
ユーザー tko919tko919
提出日時 2020-05-12 14:12:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,464 bytes
コンパイル時間 1,747 ms
コンパイル使用メモリ 174,980 KB
実行使用メモリ 13,884 KB
最終ジャッジ日時 2024-04-09 22:09:41
合計ジャッジ時間 10,149 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
13,884 KB
testcase_01 AC 1 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,944 KB
testcase_07 AC 4 ms
6,944 KB
testcase_08 AC 4 ms
6,944 KB
testcase_09 AC 4 ms
6,940 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 144 ms
8,320 KB
testcase_13 AC 165 ms
9,472 KB
testcase_14 AC 216 ms
10,240 KB
testcase_15 AC 242 ms
11,136 KB
testcase_16 AC 269 ms
12,160 KB
testcase_17 AC 311 ms
10,880 KB
testcase_18 AC 291 ms
11,392 KB
testcase_19 AC 324 ms
10,368 KB
testcase_20 AC 310 ms
10,752 KB
testcase_21 AC 302 ms
11,008 KB
testcase_22 AC 331 ms
13,440 KB
testcase_23 AC 328 ms
13,440 KB
testcase_24 AC 338 ms
13,440 KB
testcase_25 AC 343 ms
13,568 KB
testcase_26 AC 342 ms
13,696 KB
testcase_27 TLE -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;

//template
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll;
const int inf = 0x3fffffff; const ll INF = 0x1fffffffffffffff; const double eps=1e-12;
template<typename T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T>inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
//end

typedef pair<int,int> P;
typedef pair<int,P> T;
const int m=101010;
int n,k,a[m]; ll res=0;
void rec(int lb,int rb){
   if(rb-lb<=2){
      if(rb-lb==1 and a[lb]*2==k)res++;
      else if(rb-lb==2){
         if(a[lb]+a[lb+1]==k and a[lb]!=a[lb+1])res+=2;
         if(a[lb]*2==k)res++;
         if(a[lb+1]*2==k)res++;
      }
      return;
   }
   int mid=(lb+rb)/2; rec(lb,mid); rec(mid,rb);
   map<int,vector<T>> num; int mi=inf,cnt=1;
   for(int i=mid;i<rb;i++){
      if(mi==a[i])cnt++;
      if(chmin(mi,a[i]))cnt=1;
      num[a[i]].push_back({i,{mi,cnt}});
   }
   mi=inf; cnt=1;
   for(int i=mid-1;i>=lb;i--){
      if(mi==a[i])cnt++;
      if(chmin(mi,a[i]))cnt=1;
      if(num[k-a[i]].empty())continue;
      for(auto p:num[k-a[i]]){
         int idx=p.first,opp=p.second.first,add=p.second.second;
         if(opp<mi and add==1)res+=idx-i+1;
         else if(opp>mi and cnt==1)res+=idx-i+1;
      }
   }
}

int main(){
   cin>>n>>k; rep(i,0,n)cin>>a[i];
   rec(0,n); cout<<res<<endl;
   return 0;
}
0