結果

問題 No.318 学学学学学
ユーザー gazellegazelle
提出日時 2018-01-07 18:48:25
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 1,614 bytes
コンパイル時間 1,082 ms
コンパイル使用メモリ 115,128 KB
実行使用メモリ 25,092 KB
最終ジャッジ日時 2023-08-24 23:37:07
合計ジャッジ時間 7,255 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
5,604 KB
testcase_01 AC 22 ms
7,744 KB
testcase_02 WA -
testcase_03 AC 19 ms
7,064 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 124 ms
21,512 KB
testcase_20 WA -
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,380 KB
testcase_24 AC 1 ms
4,380 KB
testcase_25 AC 1 ms
4,380 KB
testcase_26 AC 1 ms
4,380 KB
testcase_27 WA -
testcase_28 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<iostream>
#include<iomanip>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<bitset>
#include<random>
#define INF 1000000000ll
#define MOD 1000000007ll
#define EPS 1e-10
#define REP(i,m) for(long long i=0; i<m; i++)
#define FOR(i,n,m) for(long long i=n; i<m; i++)
#define DUMP(a) for(long long dump=0; dump<(ll)a.size(); dump++) { cout<<a[dump]; if(dump!=(ll)a.size()-1) cout<<" "; else cout<<endl; }
#define ALL(v) v.begin(),v.end()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef long double ld;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n;
	cin>>n;
	vector<ll> a(n);
	REP(i,n) cin>>a[i];
	map<ll,set<ll>> m;
	REP(i,n) m[a[i]].insert(i);
	set<P> s;
	REP(i,n) {
		s.insert(P(i,a[i]));
	}
	vector<pair<P,ll>> buf;
	vector<ll> ans(n);
	REP(i,n) ans[i]=a[i];
	for(auto tmp: m) {
		set<ll> vec=tmp.second;
		if((ll)vec.size()<2) continue;
		auto ite=vec.begin();
		ll l=*ite;
		ite=vec.end();
		ite--;
		ll r=*ite;
		auto ite2=s.lower_bound(P(l,-1));
		while(ite2!=s.end()&&((*ite2).first)<=r) {
			m[(*ite2).second].erase((*ite2).first);
			s.erase(ite2);
			ite2=s.lower_bound(P(l,-1));
		}
		buf.pb(make_pair(P(l,r),tmp.first));
	}
	set<ll> unused;
	REP(i,n) unused.insert(i);
	reverse(ALL(buf));
	REP(i,(ll)buf.size()) {
		auto ite=unused.lower_bound(buf[i].first.first);
		while(ite!=unused.end()&&*ite<=buf[i].first.second) {
			ans[*ite]=buf[i].second;
			unused.erase(ite);
			ite=unused.lower_bound(buf[i].first.first);
		}
	}
	DUMP(ans);
}
0