結果
| 問題 |
No.318 学学学学学
|
| コンテスト | |
| ユーザー |
koyumeishi
|
| 提出日時 | 2015-12-11 00:17:55 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 62 ms / 2,000 ms |
| コード長 | 1,259 bytes |
| コンパイル時間 | 728 ms |
| コンパイル使用メモリ | 87,872 KB |
| 実行使用メモリ | 7,936 KB |
| 最終ジャッジ日時 | 2024-06-22 14:36:22 |
| 合計ジャッジ時間 | 3,031 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:42:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
42 | scanf("%d", &a[i]);
| ~~~~~^~~~~~~~~~~~~
ソースコード
#include <iostream>
#include <vector>
#include <cstdio>
#include <sstream>
#include <map>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <set>
using namespace std;
vector<int> b;
int sz;
template<class T>
vector<T> compress(vector<T> a){
b = a;
sort(b.begin(), b.end());
b.erase( unique(b.begin(), b.end()), b.end());
sz = b.size();
for(int i=0; i<a.size(); i++){
a[i] = lower_bound(b.begin(), b.end(), a[i]) - b.begin();
}
return a;
}
template<class T>
ostream& operator << (ostream& os, vector<T> vec){
for(int i=0; i<vec.size(); i++){
os << vec[i] << " ";
}
return os;
}
int main(){
int n;
cin >> n;
vector<int> a(n);
for(int i=0; i<n; i++){
scanf("%d", &a[i]);
}
auto c = compress(a);
vector<int> left(sz, sz);
vector<int> right(sz, -1);
for(int i=0; i<n; i++){
right[c[i]] = i;
}
for(int i=n-1; i>=0; i--){
left[c[i]] = i;
}
//cerr << c << endl;
//cerr << left << endl;
//cerr << right << endl;
set<int> unko;
vector<int> d(n, 0);
for(int i=0; i<n; i++){
if(left[c[i]] == i){
unko.insert(c[i]);
}
d[i] = b[*unko.rbegin()];
if(right[c[i]] == i){
unko.erase(c[i]);
}
}
for(int i=0; i<n; i++){
printf("%d%s", d[i], (i==n-1?"\n":" "));
}
return 0;
}
koyumeishi