結果

問題 No.1079 まお
ユーザー tko919tko919
提出日時 2020-05-18 15:17:59
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 511 ms / 2,000 ms
コード長 1,322 bytes
コンパイル時間 1,741 ms
コンパイル使用メモリ 176,340 KB
実行使用メモリ 11,156 KB
最終ジャッジ日時 2024-04-09 22:09:30
合計ジャッジ時間 10,072 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,944 KB
testcase_03 AC 1 ms
6,944 KB
testcase_04 AC 2 ms
6,944 KB
testcase_05 AC 3 ms
6,940 KB
testcase_06 AC 3 ms
6,944 KB
testcase_07 AC 4 ms
6,940 KB
testcase_08 AC 4 ms
6,940 KB
testcase_09 AC 4 ms
6,944 KB
testcase_10 AC 4 ms
6,944 KB
testcase_11 AC 4 ms
6,940 KB
testcase_12 AC 212 ms
7,260 KB
testcase_13 AC 224 ms
7,776 KB
testcase_14 AC 305 ms
8,916 KB
testcase_15 AC 340 ms
9,184 KB
testcase_16 AC 356 ms
9,828 KB
testcase_17 AC 440 ms
9,700 KB
testcase_18 AC 355 ms
6,944 KB
testcase_19 AC 464 ms
9,352 KB
testcase_20 AC 463 ms
9,668 KB
testcase_21 AC 442 ms
9,200 KB
testcase_22 AC 462 ms
10,616 KB
testcase_23 AC 469 ms
10,604 KB
testcase_24 AC 484 ms
10,672 KB
testcase_25 AC 491 ms
11,156 KB
testcase_26 AC 511 ms
11,040 KB
testcase_27 AC 49 ms
6,944 KB
testcase_28 AC 217 ms
8,016 KB
testcase_29 AC 241 ms
11,088 KB
testcase_30 AC 249 ms
10,768 KB
testcase_31 AC 61 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

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

int n,k; vector<int> a;

ll f(vector<int> b,vector<int> c){
   int idx=0; ll res=0;
   int mi=inf,cnt=1;
   map<int,ll> vs,ss;
   rep(i,0,b.size()){
      if(b[i]==mi)cnt++;
      else if(b[i]<mi){
         mi=b[i]; cnt=1;
      }
      if(cnt>1)continue;
      while(idx<c.size()){
         int v=c[idx];
         if(v>mi){
            vs[v]++; ss[v]+=idx+1;
         }
         else break;
         idx++;
      }
      int key=k-b[i];
      if(vs.count(key)){
         res+=vs[key]*(i+1)+ss[key];
      }
   } return res;
}

ll rec(int lb,int rb){
   if(rb-lb==1)return a[lb]*2==k;
   int m=(lb+rb)/2;
   ll res=rec(lb,m)+rec(m,rb);
   vector<int> x(a.begin()+lb,a.begin()+m),y(a.begin()+m,a.begin()+rb);
   reverse(ALL(x)); res+=f(x,y)+f(y,x); return res;
}

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