結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー 沙耶花沙耶花
提出日時 2021-03-12 22:03:46
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,113 bytes
コンパイル時間 4,755 ms
コンパイル使用メモリ 258,868 KB
実行使用メモリ 16,084 KB
最終ジャッジ日時 2024-04-22 13:01:23
合計ジャッジ時間 8,173 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 KB
testcase_02 AC 2 ms
5,248 KB
testcase_03 AC 2 ms
5,248 KB
testcase_04 AC 2 ms
5,248 KB
testcase_05 AC 2 ms
5,248 KB
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 WA -
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 WA -
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 1 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 56 ms
13,236 KB
testcase_23 AC 15 ms
5,992 KB
testcase_24 AC 13 ms
5,504 KB
testcase_25 AC 58 ms
13,772 KB
testcase_26 AC 69 ms
15,568 KB
testcase_27 AC 62 ms
14,144 KB
testcase_28 AC 77 ms
15,828 KB
testcase_29 AC 22 ms
7,212 KB
testcase_30 AC 18 ms
5,868 KB
testcase_31 AC 77 ms
15,560 KB
testcase_32 AC 21 ms
7,080 KB
testcase_33 AC 4 ms
5,376 KB
testcase_34 AC 25 ms
7,504 KB
testcase_35 AC 74 ms
14,832 KB
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
testcase_50 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
using mint = modint998244353;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define Inf 1000000000

int main(){
	
	int N;
	cin>>N;
	
	vector<int> A(N);
	rep(i,N){
		scanf("%d",&A[i]);
	}
	
	{
		auto B = A;
		sort(B.begin(),B.end());
		B.erase(unique(B.begin(),B.end()),B.end());
		
		rep(i,N){
			A[i] = distance(B.begin(),lower_bound(B.begin(),B.end(),A[i]));
		}
	}
	
	vector<vector<int>> inds(N+5);
	rep(i,N){
		inds[A[i]].push_back(i);
	}
	
	fenwick_tree<int> F(N);
	rep(i,N)F.add(i,1);
	
	
	int ans = 0;
	int pos = N;
	
	for(int i=N;i>=0;i--){
		if(inds[i].size()==0)continue;
		int d = distance(inds[i].begin(),upper_bound(inds[i].begin(),inds[i].end(),pos));
		d--;
		if(d<0)d += inds[i].size();
		
		rep(j,inds[i].size()){
			
			int cur = inds[i][d];
			F.add(cur,-1);
			if(cur<=pos){
				if(F.sum(cur,pos)>0)ans++;
			}
			else{
				if(F.sum(cur,N)+F.sum(0,pos)>0)ans++;
			}
			
			pos = cur;
			d--;
			if(d<0)d += inds[i].size();
			
		}
		
		
	}
	
	cout<<ans<<endl;
	
    return 0;
}
0