結果

問題 No.1709 Indistinguishable by MEX
ユーザー publflpublfl
提出日時 2021-10-15 21:56:10
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 109 ms / 2,000 ms
コード長 1,146 bytes
コンパイル時間 611 ms
コンパイル使用メモリ 59,376 KB
実行使用メモリ 7,564 KB
最終ジャッジ日時 2023-10-17 20:16:29
合計ジャッジ時間 3,214 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,212 KB
testcase_01 AC 2 ms
5,212 KB
testcase_02 AC 2 ms
5,216 KB
testcase_03 AC 2 ms
5,216 KB
testcase_04 AC 2 ms
5,212 KB
testcase_05 AC 3 ms
5,216 KB
testcase_06 AC 2 ms
5,212 KB
testcase_07 AC 2 ms
5,216 KB
testcase_08 AC 89 ms
6,992 KB
testcase_09 AC 64 ms
6,620 KB
testcase_10 AC 67 ms
6,340 KB
testcase_11 AC 49 ms
6,252 KB
testcase_12 AC 51 ms
6,240 KB
testcase_13 AC 73 ms
6,684 KB
testcase_14 AC 67 ms
6,636 KB
testcase_15 AC 68 ms
6,668 KB
testcase_16 AC 89 ms
7,564 KB
testcase_17 AC 80 ms
7,564 KB
testcase_18 AC 106 ms
7,564 KB
testcase_19 AC 98 ms
7,564 KB
testcase_20 AC 109 ms
7,564 KB
testcase_21 AC 93 ms
7,564 KB
testcase_22 AC 93 ms
7,564 KB
testcase_23 AC 62 ms
7,564 KB
testcase_24 AC 63 ms
7,564 KB
testcase_25 AC 63 ms
7,564 KB
testcase_26 AC 2 ms
5,212 KB
testcase_27 AC 26 ms
6,276 KB
testcase_28 AC 23 ms
6,240 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <vector>
#include <algorithm>
#define MOD 998244353

struct segTree{
	int value[800010];
	void setValue(int ind, int val, int l=1, int r=200000, int v=1)
	{
		if(l==r) value[v] = val;
		else
		{
			int h = (l+r)/2;
			if(ind<=h) setValue(ind,val,l,h,2*v);
			else setValue(ind,val,h+1,r,2*v+1);
			value[v] = value[2*v] + value[2*v+1];
		}
	}
	
	int getSum(int L, int R, int l=1, int r=200000, int v=1)
	{
		if(L<=l&&r<=R) return value[v];
		else if(r<L) return 0;
		else if(R<l) return 0;
		else
		{
			int h = (l+r)/2;
			int s1 = getSum(L,R,l,h,2*v);
			int s2 = getSum(L,R,h+1,r,2*v+1);
			return s1+s2;
		}
	}
}T;

int x[200010];
std::vector< std::pair<int,int> > V;
int main()
{
	int a;
	scanf("%d",&a);
	for(int i=1;i<=a;i++) scanf("%d",&x[i]);
	
	for(int i=1;i<=a;i++) V.push_back(std::make_pair(x[i],i));
	std::sort(V.begin(),V.end());
	int L = a+1, R = 0;
	
	long long int ans = 1;
	for(int i=0;i<V.size();i++)
	{
		int t = V[i].second;
		
		if(L<=t&&t<=R)
		{
			int val = (R-L+1) - T.getSum(L,R);
			ans *= val, ans %= MOD;
		}
		L = L<t?L:t;
		R = R>t?R:t;
		T.setValue(t,1);
	}
	
	printf("%lld",ans);
	
}
0