結果

問題 No.1496 不思議な数え上げ
ユーザー kotatsugamekotatsugame
提出日時 2021-05-02 04:21:52
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 664 ms / 3,000 ms
コード長 754 bytes
コンパイル時間 681 ms
コンパイル使用メモリ 74,700 KB
実行使用メモリ 16,828 KB
最終ジャッジ日時 2023-09-27 18:18:22
合計ジャッジ時間 26,688 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,368 KB
testcase_01 AC 2 ms
5,384 KB
testcase_02 AC 2 ms
5,456 KB
testcase_03 AC 509 ms
16,644 KB
testcase_04 AC 510 ms
16,664 KB
testcase_05 AC 513 ms
16,540 KB
testcase_06 AC 559 ms
16,600 KB
testcase_07 AC 558 ms
16,556 KB
testcase_08 AC 552 ms
16,708 KB
testcase_09 AC 553 ms
16,540 KB
testcase_10 AC 550 ms
16,728 KB
testcase_11 AC 564 ms
16,596 KB
testcase_12 AC 518 ms
16,540 KB
testcase_13 AC 533 ms
16,540 KB
testcase_14 AC 533 ms
16,548 KB
testcase_15 AC 532 ms
16,776 KB
testcase_16 AC 544 ms
16,624 KB
testcase_17 AC 643 ms
16,824 KB
testcase_18 AC 640 ms
16,604 KB
testcase_19 AC 653 ms
16,596 KB
testcase_20 AC 661 ms
16,556 KB
testcase_21 AC 640 ms
16,648 KB
testcase_22 AC 655 ms
16,544 KB
testcase_23 AC 652 ms
16,560 KB
testcase_24 AC 649 ms
16,548 KB
testcase_25 AC 660 ms
16,544 KB
testcase_26 AC 664 ms
16,828 KB
testcase_27 AC 637 ms
16,544 KB
testcase_28 AC 636 ms
16,544 KB
testcase_29 AC 631 ms
16,536 KB
testcase_30 AC 631 ms
16,544 KB
testcase_31 AC 631 ms
16,548 KB
testcase_32 AC 565 ms
15,256 KB
testcase_33 AC 290 ms
11,160 KB
testcase_34 AC 268 ms
10,748 KB
testcase_35 AC 7 ms
5,500 KB
testcase_36 AC 575 ms
15,596 KB
testcase_37 AC 309 ms
11,520 KB
testcase_38 AC 290 ms
11,108 KB
testcase_39 AC 408 ms
13,176 KB
testcase_40 AC 219 ms
10,024 KB
testcase_41 AC 428 ms
13,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:7:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
    7 | main()
      | ^~~~

ソースコード

diff #

#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.lower_bound(k);
		int R=*it,L=*--it;
		st.insert(k);
		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;
	}
}
0