結果
問題 | No.1496 不思議な数え上げ |
ユーザー |
|
提出日時 | 2021-05-02 04:22:47 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 654 ms / 3,000 ms |
コード長 | 743 bytes |
コンパイル時間 | 803 ms |
コンパイル使用メモリ | 73,728 KB |
実行使用メモリ | 16,128 KB |
最終ジャッジ日時 | 2024-07-20 12:48:39 |
合計ジャッジ時間 | 25,040 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 39 |
コンパイルメッセージ
main.cpp:7:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type] 7 | main() | ^~~~
ソースコード
#include<iostream> #include<set> using namespace std; int N,P[2<<17]; long S[2<<17]; int inv[2<<17]; main() { cin>>N; for(int i=0;i<N;i++) { cin>>P[i]; inv[P[i]-1]=i; S[i+1]=S[i]+P[i]; } set<int>st({-1,N}); for(int i=0;i<N;i++) { long A;cin>>A; int k=inv[i]; auto it=st.insert(k).first; int R=*++it,L=*----it; long ans=0; if(k-L<R-k) { for(int x=L+1;x<=k;x++) { int l=k,r=R+1; while(r-l>1) { int mid=(l+r)/2; if(S[mid]-S[x]<=A)l=mid; else r=mid; } ans+=l-k; } } else { for(int y=k;y<R;y++) { int l=L-1,r=k; while(r-l>1) { int mid=(l+r)/2; if(S[y+1]-S[mid+1]<=A)r=mid; else l=mid; } ans+=k-r; } } cout<<ans<<endl; } }