結果

問題 No.1031 いたずら好きなお姉ちゃん
ユーザー kotatsugamekotatsugame
提出日時 2020-04-22 14:23:15
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 302 ms / 3,500 ms
コード長 1,900 bytes
コンパイル時間 650 ms
コンパイル使用メモリ 74,628 KB
実行使用メモリ 240,768 KB
最終ジャッジ日時 2024-04-19 15:01:25
合計ジャッジ時間 13,743 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 1 ms
5,376 KB
testcase_03 AC 11 ms
13,056 KB
testcase_04 AC 10 ms
12,928 KB
testcase_05 AC 10 ms
12,288 KB
testcase_06 AC 9 ms
12,160 KB
testcase_07 AC 9 ms
13,056 KB
testcase_08 AC 9 ms
12,288 KB
testcase_09 AC 8 ms
12,288 KB
testcase_10 AC 9 ms
12,288 KB
testcase_11 AC 216 ms
198,400 KB
testcase_12 AC 196 ms
196,864 KB
testcase_13 AC 247 ms
239,232 KB
testcase_14 AC 202 ms
205,440 KB
testcase_15 AC 229 ms
225,152 KB
testcase_16 AC 190 ms
194,560 KB
testcase_17 AC 231 ms
226,688 KB
testcase_18 AC 222 ms
218,112 KB
testcase_19 AC 231 ms
228,096 KB
testcase_20 AC 250 ms
239,232 KB
testcase_21 AC 219 ms
217,984 KB
testcase_22 AC 189 ms
194,560 KB
testcase_23 AC 205 ms
200,832 KB
testcase_24 AC 239 ms
229,760 KB
testcase_25 AC 246 ms
237,440 KB
testcase_26 AC 219 ms
221,184 KB
testcase_27 AC 204 ms
206,336 KB
testcase_28 AC 247 ms
240,640 KB
testcase_29 AC 250 ms
240,640 KB
testcase_30 AC 247 ms
240,768 KB
testcase_31 AC 263 ms
240,732 KB
testcase_32 AC 256 ms
240,768 KB
testcase_33 AC 247 ms
240,676 KB
testcase_34 AC 302 ms
240,716 KB
testcase_35 AC 283 ms
240,600 KB
testcase_36 AC 290 ms
240,600 KB
testcase_37 AC 298 ms
240,768 KB
testcase_38 AC 300 ms
236,800 KB
testcase_39 AC 276 ms
231,168 KB
testcase_40 AC 276 ms
235,264 KB
testcase_41 AC 274 ms
236,800 KB
testcase_42 AC 269 ms
235,264 KB
testcase_43 AC 264 ms
237,568 KB
testcase_44 AC 269 ms
235,264 KB
testcase_45 AC 301 ms
228,864 KB
testcase_46 AC 259 ms
234,496 KB
testcase_47 AC 243 ms
232,192 KB
testcase_48 AC 264 ms
239,872 KB
testcase_49 AC 254 ms
239,232 KB
testcase_50 AC 250 ms
236,672 KB
testcase_51 AC 243 ms
240,768 KB
testcase_52 AC 243 ms
240,768 KB
testcase_53 AC 244 ms
240,768 KB
testcase_54 AC 1 ms
5,376 KB
testcase_55 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:32:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   32 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
const int B=330;
const int MAXN=100010;
//const int MAXN=100;
int N;
int p[MAXN];
int MAX[MAXN/B],MIN[MAXN/B],CR[MAXN/B][MAXN],CL[MAXN/B][MAXN];
void calc(const vector<int>&A,int ans[MAXN])
{
	for(int i=0;i<MAXN;i++)ans[i]=-2e5;
	int cummin=N+1;
	int now=0;
	for(int i=A.size();i--;)
	{
		if(cummin>A[i])
		{
			cummin=A[i];
			ans[A[i]]=-now;
			now++;
		}
	}
	for(int i=1;i<MAXN;i++)ans[i]=max(ans[i],ans[i-1]);
	for(int i=0;i<MAXN;i++)
	{
		ans[i]+=now;
		if(ans[i]<0)ans[i]=0;
	}
}
main()
{
	cin>>N;
	for(int i=0;i<N;i++)cin>>p[i];
	for(int i=0;i+B<=N;i+=B)
	{
		vector<int>A(p+i,p+i+B);
		int id=i/B;
		calc(A,CR[id]);
		reverse(A.begin(),A.end());
		calc(A,CL[id]);
		MAX[id]=MIN[id]=A[0];
		for(int a:A)
		{
			if(MAX[id]<a)MAX[id]=a;
			if(MIN[id]>a)MIN[id]=a;
		}
	}
	long ans=0;
	for(int i=0;i<N;i++)
	{
		int now=0;
		int l=i,r=i+1;
		int P=p[i];
		bool fl=true,fr=true;
		int LM=P,RM=P;
		while(l%B!=0)
		{
			l--;
			if(p[l]<LM)
			{
				now++;
				LM=p[l];
			}
			else if(P<p[l])
			{
				fl=false;
				break;
			}
		}
		if(fl)
		{
			while(l>=B)
			{
				int id=l/B-1;
				if(MAX[id]<P)
				{
					now+=CR[id][LM];
					if(LM>MIN[id])LM=MIN[id];
					l-=B;
				}
				else break;
			}
			while(l>0)
			{
				l--;
				if(p[l]<LM)
				{
					now++;
					LM=p[l];
				}
				else if(P<p[l])
				{
					break;
				}
			}
		}
		while(r<N&&r%B!=0)
		{
			r++;
			if(p[r-1]<RM)
			{
				now++;
				RM=p[r-1];
			}
			else if(P<p[r-1])
			{
				fr=false;
				break;
			}
		}
		if(fr)
		{
			while(r+B<=N)
			{
				int id=r/B;
				if(MAX[id]<P)
				{
					now+=CL[id][RM];
					if(RM>MIN[id])RM=MIN[id];
					r+=B;
				}
				else break;
			}
			while(r<N)
			{
				r++;
				if(p[r-1]<RM)
				{
					now++;
					RM=p[r-1];
				}
				else if(P<p[r-1])
				{
					break;
				}
			}
		}
		ans+=now;
	}
	cout<<ans<<endl;
}
0