結果

問題 No.318 学学学学学
ユーザー eQeeQe
提出日時 2020-04-02 06:47:19
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 226 ms / 2,000 ms
コード長 2,080 bytes
コンパイル時間 1,675 ms
コンパイル使用メモリ 167,128 KB
実行使用メモリ 18,308 KB
最終ジャッジ日時 2023-09-10 08:21:31
合計ジャッジ時間 7,101 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
4,384 KB
testcase_01 AC 33 ms
5,932 KB
testcase_02 AC 40 ms
6,564 KB
testcase_03 AC 25 ms
5,180 KB
testcase_04 AC 33 ms
6,024 KB
testcase_05 AC 226 ms
18,308 KB
testcase_06 AC 179 ms
12,552 KB
testcase_07 AC 148 ms
11,984 KB
testcase_08 AC 121 ms
10,980 KB
testcase_09 AC 101 ms
9,888 KB
testcase_10 AC 75 ms
8,324 KB
testcase_11 AC 220 ms
18,092 KB
testcase_12 AC 147 ms
12,552 KB
testcase_13 AC 124 ms
11,444 KB
testcase_14 AC 101 ms
10,220 KB
testcase_15 AC 86 ms
9,328 KB
testcase_16 AC 74 ms
8,364 KB
testcase_17 AC 122 ms
12,532 KB
testcase_18 AC 109 ms
12,772 KB
testcase_19 AC 122 ms
12,552 KB
testcase_20 AC 52 ms
8,328 KB
testcase_21 AC 2 ms
4,380 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 1 ms
4,376 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,380 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 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 _add(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 {
      _add(a, b, x, k*2+1, l, (l+r)/2);
      _add(a, b, x, k*2+2, (l+r)/2, r);
      data[k]=data[k*2+1]+data[k*2+2];
    }
  }
  
  void add(ll a, ll b, ll x) {_add(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.add(a, b+1, x);
  }
  
  for(i=0; i<N; i++) cout << lst.sum(i, i+1) << " ";
  pt("");
  
  
}

0