結果

問題 No.318 学学学学学
ユーザー ciel
提出日時 2015-12-11 10:54:44
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 161 ms / 2,000 ms
コード長 531 bytes
コンパイル時間 735 ms
コンパイル使用メモリ 57,884 KB
実行使用メモリ 18,944 KB
最終ジャッジ日時 2024-06-22 15:24:07
合計ジャッジ時間 3,532 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 26
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:8:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
    8 |         scanf("%d",&N);
      |         ~~~~~^~~~~~~~~
main.cpp:12:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   12 |                 scanf("%d",&x);
      |                 ~~~~~^~~~~~~~~

ソースコード

diff #

#include <vector>
#include <map>
#include <set>
#include <cstdio>
using namespace std;
int main(){
	int N;
	scanf("%d",&N);
	map<int,pair<int,int> >m;
	vector<int>v(N);
	for(int i=0,x;i<N;i++){
		scanf("%d",&x);
		v[i]=x;
		if(m.find(x)==m.end())m[x]=make_pair(i,i);
		else m[x].second=i;
	}
	set<int>sa,sb,s;
	for(auto &e:m)sa.insert(e.second.first),sb.insert(e.second.second);
	for(int i=0;i<N;i++){
		if(sa.find(i)!=sa.end())s.insert(v[i]);
		printf(i<N-1?"%d ":"%d\n",*s.rbegin());
		if(sb.find(i)!=sb.end())s.erase(v[i]);
	}
}
0