結果
問題 |
No.318 学学学学学
|
ユーザー |
|
提出日時 | 2020-10-19 03:14:51 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 134 ms / 2,000 ms |
コード長 | 968 bytes |
コンパイル時間 | 2,406 ms |
コンパイル使用メモリ | 206,136 KB |
最終ジャッジ日時 | 2025-01-15 11:41:47 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 26 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:37:21: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 37 | int n; scanf("%d",&n); | ~~~~~^~~~~~~~~ main.cpp:39:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 39 | rep(i,n) scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #define rep(i,n) for(int i=0;i<(n);i++) using namespace std; const int INF=1<<29; class segment_tree_dual{ int n; vector<int> seg; void chmax(int l,int r,int a,int b,int u,int x){ if(l<=a && b<=r){ seg[u]=max(seg[u],x); return; } int c=(a+b+1)/2; if(l<c && a<r) chmax(l,r,a,c,2*u ,x); if(l<b && c<r) chmax(l,r,c,b,2*u+1,x); } public: segment_tree_dual(int N){ for(n=1;n<N;n*=2); seg.assign(2*n,-INF); } void chmax(int l,int r,int x){ chmax(l,r,0,n,1,x); } int get(int u){ u+=n; int res=seg[u]; for(u/=2;u>=1;u/=2) res=max(res,seg[u]); return res; } }; int main(){ int n; scanf("%d",&n); vector<int> a(n); rep(i,n) scanf("%d",&a[i]); map<int,vector<int>> f; rep(i,n) f[a[i]].emplace_back(i); segment_tree_dual ST(n); for(auto [x,v]:f){ int l=INF,r=-INF; for(auto i:v){ l=min(l,i); r=max(r,i+1); } ST.chmax(l,r,x); } rep(i,n) printf("%d%c",ST.get(i),i<n-1?' ':'\n'); return 0; }