結果
| 問題 | No.318 学学学学学 |
| コンテスト | |
| ユーザー |
gazelle
|
| 提出日時 | 2018-01-07 18:48:25 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,614 bytes |
| 記録 | |
| コンパイル時間 | 1,302 ms |
| コンパイル使用メモリ | 117,892 KB |
| 実行使用メモリ | 25,216 KB |
| 最終ジャッジ日時 | 2024-12-23 10:11:36 |
| 合計ジャッジ時間 | 5,631 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 WA * 2 |
| other | AC * 9 WA * 17 |
ソースコード
#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);
}
gazelle