結果
問題 | No.1079 まお |
ユーザー | Chanyuh |
提出日時 | 2020-07-22 12:21:51 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,382 bytes |
コンパイル時間 | 884 ms |
コンパイル使用メモリ | 111,732 KB |
実行使用メモリ | 49,216 KB |
最終ジャッジ日時 | 2023-09-02 08:53:55 |
合計ジャッジ時間 | 20,975 ms |
ジャッジサーバーID (参考情報) |
judge11 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,376 KB |
testcase_02 | AC | 1 ms
4,380 KB |
testcase_03 | AC | 2 ms
4,376 KB |
testcase_04 | WA | - |
testcase_05 | AC | 4 ms
4,376 KB |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | WA | - |
testcase_11 | WA | - |
testcase_12 | AC | 547 ms
27,256 KB |
testcase_13 | AC | 636 ms
28,756 KB |
testcase_14 | AC | 825 ms
32,392 KB |
testcase_15 | AC | 953 ms
37,576 KB |
testcase_16 | AC | 1,067 ms
40,800 KB |
testcase_17 | WA | - |
testcase_18 | AC | 1,121 ms
35,124 KB |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | AC | 1,309 ms
49,216 KB |
testcase_23 | AC | 1,301 ms
46,748 KB |
testcase_24 | AC | 1,308 ms
46,568 KB |
testcase_25 | AC | 1,298 ms
44,872 KB |
testcase_26 | AC | 1,360 ms
48,360 KB |
testcase_27 | AC | 33 ms
4,376 KB |
testcase_28 | WA | - |
testcase_29 | WA | - |
testcase_30 | AC | 646 ms
35,196 KB |
testcase_31 | AC | 43 ms
4,376 KB |
ソースコード
#include<iostream> #include<string> #include<cstdio> #include<vector> #include<cmath> #include<algorithm> #include<functional> #include<iomanip> #include<queue> #include<ciso646> #include<random> #include<map> #include<set> #include<complex> #include<bitset> #include<stack> #include<unordered_map> #include<utility> #include<tuple> using namespace std; typedef long long ll; typedef unsigned int ui; const ll mod = 1000000007; const ll INF = (ll)1000000007 * 1000000007; typedef pair<int, int> P; #define stop char nyaa;cin>>nyaa; #define rep(i,n) for(int i=0;i<n;i++) #define per(i,n) for(int i=n-1;i>=0;i--) #define Rep(i,sta,n) for(int i=sta;i<n;i++) #define Per(i,sta,n) for(int i=n-1;i>=sta;i--) #define rep1(i,n) for(int i=1;i<=n;i++) #define per1(i,n) for(int i=n;i>=1;i--) #define Rep1(i,sta,n) for(int i=sta;i<=n;i++) typedef long double ld; const ld eps = 1e-8; const ld pi = acos(-1.0); typedef pair<ll, ll> LP; typedef pair<P, ll> PP; int dx[4]={1,-1,0,0}; int dy[4]={0,0,1,-1}; int n,k; int a[100010]; ll rec(int l,int r){ if(r-l<=0) return 0; if(r-l==1){ if(2*a[l]==k) return 1; else return 0; } map<int,ll> ma1,ma2; map<int,ll> ma3,ma4; int mid=(l+r)/2; ll res=0; P pl=P(mod,0); int pos_r=mid,min_r=mod; Per(i,l,mid){ int mi=pl.first,cnt=pl.second; if(a[i]<mi){ mi=a[i]; cnt=1; } else if(a[i]==mi) cnt+=1; while(pos_r<r && mi<min(min_r,a[pos_r])){ min_r=min(min_r,a[pos_r]); ma1[a[pos_r]]+=pos_r-mid+1; ma2[a[pos_r]]+=1; pos_r+=1; } if(cnt==1)res+=ma1[k-a[i]]+(ll)(mid-i)*ma2[k-a[i]]; pl=P(mi,cnt); } P pr=P(mod,0); int pos_l=mid,min_l=mod; Rep(i,mid,r){ int mi=pr.first,cnt=pr.second; if(a[i]<mi){ mi=a[i]; cnt=1; } else if(a[i]==mi) cnt+=1; while(pos_l>=l && mi<min(min_l,a[pos_l-1])){ pos_l-=1; min_l=min(min_l,a[pos_l]); ma3[a[pos_l]]+=mid-pos_l; ma4[a[pos_l]]+=1; } if(cnt==1)res+=ma3[k-a[i]]+(ll)(i-mid+1)*ma4[k-a[i]]; pr=P(mi,cnt); } //cout << l << " " << r << endl; //cout << mid << endl; //cout << res << endl; return res+rec(l,mid)+rec(mid,r); } void solve(){ cin >> n >> k; a[0]=mod; rep(i,n){ cin >> a[i+1]; } cout << rec(0,n+1) << endl; } int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(50); solve(); }