結果
問題 | No.1496 不思議な数え上げ |
ユーザー | 👑 kmjp |
提出日時 | 2021-04-30 22:50:41 |
言語 | C++17 (gcc 13.2.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 584 ms / 3,000 ms |
コード長 | 1,681 bytes |
コンパイル時間 | 2,222 ms |
コンパイル使用メモリ | 205,204 KB |
実行使用メモリ | 17,720 KB |
最終ジャッジ日時 | 2023-09-26 07:28:27 |
合計ジャッジ時間 | 24,358 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,408 KB |
testcase_01 | AC | 2 ms
5,408 KB |
testcase_02 | AC | 2 ms
5,408 KB |
testcase_03 | AC | 419 ms
17,652 KB |
testcase_04 | AC | 413 ms
17,456 KB |
testcase_05 | AC | 420 ms
17,444 KB |
testcase_06 | AC | 467 ms
17,584 KB |
testcase_07 | AC | 463 ms
17,568 KB |
testcase_08 | AC | 472 ms
17,448 KB |
testcase_09 | AC | 465 ms
17,448 KB |
testcase_10 | AC | 463 ms
17,500 KB |
testcase_11 | AC | 470 ms
17,448 KB |
testcase_12 | AC | 420 ms
17,444 KB |
testcase_13 | AC | 434 ms
17,444 KB |
testcase_14 | AC | 437 ms
17,456 KB |
testcase_15 | AC | 433 ms
17,492 KB |
testcase_16 | AC | 429 ms
17,440 KB |
testcase_17 | AC | 572 ms
17,588 KB |
testcase_18 | AC | 584 ms
17,504 KB |
testcase_19 | AC | 573 ms
17,456 KB |
testcase_20 | AC | 579 ms
17,452 KB |
testcase_21 | AC | 565 ms
17,452 KB |
testcase_22 | AC | 569 ms
17,588 KB |
testcase_23 | AC | 566 ms
17,532 KB |
testcase_24 | AC | 578 ms
17,656 KB |
testcase_25 | AC | 574 ms
17,512 KB |
testcase_26 | AC | 576 ms
17,708 KB |
testcase_27 | AC | 548 ms
17,516 KB |
testcase_28 | AC | 550 ms
17,452 KB |
testcase_29 | AC | 555 ms
17,644 KB |
testcase_30 | AC | 542 ms
17,508 KB |
testcase_31 | AC | 550 ms
17,720 KB |
testcase_32 | AC | 497 ms
16,012 KB |
testcase_33 | AC | 250 ms
11,536 KB |
testcase_34 | AC | 239 ms
11,164 KB |
testcase_35 | AC | 6 ms
5,808 KB |
testcase_36 | AC | 504 ms
16,216 KB |
testcase_37 | AC | 269 ms
11,876 KB |
testcase_38 | AC | 253 ms
11,524 KB |
testcase_39 | AC | 360 ms
13,564 KB |
testcase_40 | AC | 200 ms
10,532 KB |
testcase_41 | AC | 379 ms
13,944 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef signed long long ll; #define _P(...) (void)printf(__VA_ARGS__) #define FOR(x,to) for(x=0;x<(to);x++) #define FORR(x,arr) for(auto& x:arr) #define FORR2(x,y,arr) for(auto& [x,y]:arr) #define ALL(a) (a.begin()),(a.end()) #define ZERO(a) memset(a,0,sizeof(a)) #define MINUS(a) memset(a,0xff,sizeof(a)) template<class T> bool chmax(T &a, const T &b) { if(a<b){a=b;return 1;}return 0;} template<class T> bool chmin(T &a, const T &b) { if(a>b){a=b;return 1;}return 0;} //------------------------------------------------------- int N; int P[202020],R[202020]; set<int> invalid; ll S[202020]; ll A[202020]; ll hoge(int x) { auto it=invalid.lower_bound(x); int R=*it-1; int L=*prev(it)+1; int i,j; ll ret=0; if(x-L<R-x) { for(i=L;i<=x;i++) { if(S[x]-S[i-1]>A[x]) continue; int tar=x; for(j=20;j>=0;j--) if(tar+(1<<j)<=R&&S[tar+(1<<j)]-S[i-1]<=A[x]) tar+=1<<j; ret+=tar-x+1; } } else { for(i=x;i<=R;i++) { ll lef=A[x]-(S[i]-S[x-1]); if(S[i]-S[x-1]>A[x]) continue; int tar=x; for(j=20;j>=0;j--) if(tar-(1<<j)>=L&&S[i]-S[tar-(1<<j)-1]<=A[x]) tar-=1<<j; ret+=x-tar+1; } } return ret; } void solve() { int i,j,k,l,r,x,y; string s; cin>>N; for(i=1;i<=N;i++) { cin>>P[i]; R[P[i]]=i; S[i]=S[i-1]+P[i]; } for(i=1;i<=N;i++) cin>>A[R[i]]; invalid.insert(0); invalid.insert(N+1); for(i=1;i<=N;i++) { x=R[i]; cout<<hoge(x)<<endl; invalid.insert(x); } } int main(int argc,char** argv){ string s;int i; if(argc==1) ios::sync_with_stdio(false), cin.tie(0); FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin); cout.tie(0); solve(); return 0; }