結果

問題 No.318 学学学学学
ユーザー eQeeQe
提出日時 2020-04-02 08:04:11
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 217 ms / 2,000 ms
コード長 2,107 bytes
コンパイル時間 1,507 ms
コンパイル使用メモリ 159,588 KB
実行使用メモリ 18,064 KB
最終ジャッジ日時 2023-09-10 10:28:36
合計ジャッジ時間 6,901 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
4,404 KB
testcase_01 AC 30 ms
5,908 KB
testcase_02 AC 37 ms
6,164 KB
testcase_03 AC 25 ms
5,204 KB
testcase_04 AC 33 ms
5,964 KB
testcase_05 AC 217 ms
18,044 KB
testcase_06 AC 171 ms
12,632 KB
testcase_07 AC 145 ms
11,936 KB
testcase_08 AC 123 ms
10,884 KB
testcase_09 AC 102 ms
9,972 KB
testcase_10 AC 77 ms
8,340 KB
testcase_11 AC 215 ms
18,064 KB
testcase_12 AC 142 ms
12,568 KB
testcase_13 AC 119 ms
11,244 KB
testcase_14 AC 100 ms
10,308 KB
testcase_15 AC 86 ms
9,444 KB
testcase_16 AC 69 ms
8,448 KB
testcase_17 AC 117 ms
12,776 KB
testcase_18 AC 108 ms
12,564 KB
testcase_19 AC 118 ms
12,464 KB
testcase_20 AC 53 ms
8,280 KB
testcase_21 AC 1 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 1 ms
4,376 KB
testcase_28 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <string>
#define ft first
#define sc second
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) (a)=max(a, b)
#define chmin(a, b) (a)=min(a, b)
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;


/*
 for(i=0; i<N; i++)
   cin >> a[i];
*/

class LazySegTree {
public:
  ll n, height;
  vector<ll> data, lazy;
  
  LazySegTree(ll _n) {
    n=1;
    height=1;
    while(n<_n) {
      n*=2;
      height++;
    }
    data=vector<ll>(2*n-1);
    lazy=vector<ll>(2*n-1);
  }
  
  void eval(ll k, ll l, ll r) {
    if(lazy[k]!=0) {
      data[k]=lazy[k];
      
      if(r-l>1) {
        lazy[k*2+1]=lazy[k]/2;
        lazy[k*2+2]=lazy[k]/2;
      }
      lazy[k]=0;
    }
  }
  
  void _change(ll a, ll b, ll x, ll k, ll l, ll r) {
    eval(k, l, r);
    if(r<=a || b<=l) return;
    
    if(a<=l && r<=b) {
      lazy[k]=(r-l)*x;
      eval(k, l, r);
    }else {
      _change(a, b, x, k*2+1, l, (l+r)/2);
      _change(a, b, x, k*2+2, (l+r)/2, r);
      //data[k]=func(data[k*2+1], data[k*2+2]);
    }
  }
  
  void change(ll a, ll b, ll x) {_change(a, b, x, 0, 0, n);}
  
  //[a, b):要求区間,[l, r):今見ている区間
  ll _sum(ll a, ll b, ll k, ll l, ll r) {
    if(r<=a || b<=l) return 0;
    
    eval(k, l, r);
    if(a<=l && r<=b) {
      return data[k];
    }else {
      ll s=_sum(a, b, k*2+1, l, (l+r)/2);
      ll t=_sum(a, b, k*2+2, (l+r)/2, r);
      return s+t;
    }
  }
  
  ll sum(ll a, ll b) {return _sum(a, b, 0, 0, n);}
  
};



int main(void) {
  ll i, j, k;
  
  ll N;
  cin >> N;
  ll a[MAX];
  
  map<ll, vector<ll>> mv;
  for(i=0; i<N; i++) {
    ll a;
    cin >> a;
    mv[a].push_back(i);
  }
  
  LazySegTree lst=LazySegTree(N);
  
  for(auto it=mv.begin(); it!=mv.end(); it++) {
    ll x=it->ft;
    
    sort(mv[x].begin(), mv[x].end());
    ll a=mv[x][0], b=mv[x][(ll)mv[x].size()-1];
    lst.change(a, b+1, x);
  }
  
  for(i=0; i<N; i++) cout << lst.sum(i, i+1) << " ";
  pt("");
  
  
}

0