結果

問題 No.318 学学学学学
ユーザー kkktymkkktym
提出日時 2020-01-22 21:32:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 254 ms / 2,000 ms
コード長 2,463 bytes
コンパイル時間 793 ms
コンパイル使用メモリ 86,912 KB
実行使用メモリ 20,204 KB
最終ジャッジ日時 2023-09-23 01:48:18
合計ジャッジ時間 7,292 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 14 ms
4,532 KB
testcase_01 AC 32 ms
6,280 KB
testcase_02 AC 40 ms
6,688 KB
testcase_03 AC 24 ms
5,424 KB
testcase_04 AC 34 ms
6,608 KB
testcase_05 AC 254 ms
19,960 KB
testcase_06 AC 184 ms
13,936 KB
testcase_07 AC 152 ms
11,764 KB
testcase_08 AC 118 ms
9,916 KB
testcase_09 AC 93 ms
8,756 KB
testcase_10 AC 68 ms
7,484 KB
testcase_11 AC 254 ms
20,204 KB
testcase_12 AC 148 ms
13,836 KB
testcase_13 AC 119 ms
11,708 KB
testcase_14 AC 95 ms
9,864 KB
testcase_15 AC 76 ms
8,808 KB
testcase_16 AC 55 ms
7,556 KB
testcase_17 AC 127 ms
13,808 KB
testcase_18 AC 109 ms
14,128 KB
testcase_19 AC 126 ms
13,880 KB
testcase_20 AC 39 ms
8,056 KB
testcase_21 AC 1 ms
4,376 KB
testcase_22 AC 1 ms
4,376 KB
testcase_23 AC 1 ms
4,380 KB
testcase_24 AC 1 ms
4,384 KB
testcase_25 AC 1 ms
4,376 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
testcase_28 AC 1 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
typedef long long ll;
template <typename X>
class DST
{
private:
  int n;
  vector<X> dat,delay;
  X init;

  void eval(int k,int l,int r)
  {
    if(delay[k] != 0){
      //      dat[k] += delay[k];
      dat[k] = delay[k];      
      if(k < n-1){
	// delay[2*k+1] += delay[k]/2;
	// delay[2*k+2] += delay[k]/2;
	delay[2*k+1] = delay[k];
	delay[2*k+2] = delay[k];	
      }
      delay[k] = 0;
    }
  }
  

  
public:  
  DST(int _n)
  {
    n = 1;
    while(n < _n) n *= 2;
    dat.assign(2*n-1,0);
    delay.assign(2*n-1,0);
  }

  void update(int a,int b,X x,int k,int l,int r)
  {
    eval(k,l,r);
    
    if(r<=a||b<=l) return ;
    
    if(a<=l&&r<=b){
      //      delay[k] += (r-l)*x;
      delay[k] = x;      
      eval(k,l,r);
    }
    else{
      update(a,b,x,2*k+1,l,(l+r)/2);
      update(a,b,x,2*k+2,(l+r)/2,r);
      //      dat[k] = dat[2*k+1] + dat[2*k+2];
      dat[k] = dat[2*k+1];
      dat[k] = dat[2*k+2];      
    }
  }

  X query(int a,int b,int k,int l,int r)
  {
    eval(k,l,r);
    
    if(r<=a||b<=l) return 0;

    if(a<=l&&r<=b) return dat[k];    
    else{
      X vl = query(a,b,2*k+1,l,(l+r)/2);
      X vr = query(a,b,2*k+2,(l+r)/2,r);
      return vl + vr;
    }
  }

  int size(){
    return n;
  }

  int get_dat(int x){
    return dat[n-1+x];
  }    
  
  void all_eval(){
    rep(i,2*n-1){
      eval(i,0,0);
    }
  }
  
  void show(){
    int index = 0;
    int num = 1;
    while(index<n){
      rep(i,num){
	cout << dat[i+index] << " ";
      }
      cout << "\n";
      num *= 2;
      index = index*2+1;
    }
    index = 0;
    num = 1;
    while(index<n){
      rep(i,num){
	cout << delay[i+index] << " ";
      }
      cout << "\n";
      num *= 2;
      index = index*2+1;    
    }
  }

  
};

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n){
    cin >> a[i];
  }

  map<int,ll> fro,bac;
  rep(i,n){
    if(fro[a[i]]>0){
      bac[a[i]]=i+1;
    }
    else{
      fro[a[i]]=i+1;
      bac[a[i]]=i+1;
    }
  }

  DST<ll> dst(n);
  for(auto it=fro.begin();it!=fro.end();++it){
    int x = it->first;
    dst.update(fro[x]-1,bac[x],x,0,0,dst.size());
    //    dst.show();
  }
  dst.all_eval();
  //  dst.show();

  rep(i,n){
    cout << dst.get_dat(i) << " ";
  }
  cout << "\n";
  
  return 0;
}
0