結果

問題 No.318 学学学学学
ユーザー a_kawashiroa_kawashiro
提出日時 2017-12-24 15:56:40
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 3,006 bytes
コンパイル時間 877 ms
コンパイル使用メモリ 97,128 KB
実行使用メモリ 13,812 KB
最終ジャッジ日時 2023-09-04 20:59:57
合計ジャッジ時間 4,449 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 11 ms
6,348 KB
testcase_01 AC 20 ms
7,020 KB
testcase_02 AC 25 ms
7,188 KB
testcase_03 AC 16 ms
6,716 KB
testcase_04 AC 22 ms
7,036 KB
testcase_05 AC 141 ms
13,812 KB
testcase_06 AC 128 ms
10,700 KB
testcase_07 AC 119 ms
9,536 KB
testcase_08 AC 97 ms
8,760 KB
testcase_09 AC 83 ms
8,132 KB
testcase_10 AC 64 ms
7,548 KB
testcase_11 AC 141 ms
13,760 KB
testcase_12 AC 106 ms
10,688 KB
testcase_13 AC 85 ms
9,772 KB
testcase_14 AC 71 ms
8,692 KB
testcase_15 AC 58 ms
8,152 KB
testcase_16 AC 46 ms
7,620 KB
testcase_17 AC 98 ms
10,664 KB
testcase_18 AC 83 ms
10,740 KB
testcase_19 AC 98 ms
10,760 KB
testcase_20 AC 42 ms
7,808 KB
testcase_21 AC 1 ms
5,828 KB
testcase_22 AC 2 ms
5,620 KB
testcase_23 AC 2 ms
5,628 KB
testcase_24 AC 2 ms
5,752 KB
testcase_25 AC 2 ms
5,748 KB
testcase_26 AC 2 ms
5,600 KB
testcase_27 AC 2 ms
5,728 KB
testcase_28 AC 2 ms
5,540 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

const int MAX_N = 1 << 18;

class RangeUpdateRangeSum{
    public:
        int sz;
        LL node[MAX_N], lazy[MAX_N];

        RangeUpdateRangeSum(int n) {
            sz = 1;
            while (n > sz )sz *= 2;
            for (int i = 0; i < 2 * sz - 1; i++)lazy[i] = -1;
        }

        void lazy_evaluate_node(int k, int l, int r) {
            if (lazy[k] != -1) { 
                node[k] = lazy[k] * (r - l); 
                if (r - l > 1) {
                    lazy[k * 2 + 1] = lazy[k]; 
                    lazy[k * 2 + 2] = lazy[k]; 
                }
                lazy[k] = -1;
            }
        }

        void update(int a, int b, LL v){    update(a,b,v,0,0,sz);   }
        void update(int a, int b, LL v, int k, int l, int r) {
            lazy_evaluate_node(k, l, r); 
            if (r <= a || b <= l)return; 
            if (a <= l && r <= b) {
                lazy[k] = v;
                lazy_evaluate_node(k, l, r);
            }
            else {
                update(a, b, v, k * 2 + 1, l, (l + r) / 2);
                update(a, b, v, k * 2 + 2, (l + r) / 2, r);
                node[k] = node[k * 2 + 1] + node[k * 2 + 2];
            }
        }

        LL sum(int a, int b){   return sum(a,b,0,0,sz); }
        LL sum(int a, int b, int k, int l, int r) {
            lazy_evaluate_node(k, l, r);
            if (r <= a || b <= l)return 0;
            if (a <= l && r <= b)return node[k];
            LL x = sum(a, b, k * 2 + 1, l, (l + r) / 2); 
            LL y = sum(a, b, k * 2 + 2, (l + r) / 2, r);
            return x + y;
        }
};

int main(void){
    int n;GI(n);
    map<LL,pair<int,int> > ma;
    REP(i,n){
        LL a;GLL(a);
        if(ma.find(a) == ma.end())
            ma[a] = MP(i,i+1);
        else{
            auto p=ma[a];
            ma[a]=MP(min(p.first,i),max(p.second,i+1));
        }
    }
    RangeUpdateRangeSum seg(n);
    for(auto i : ma){
        seg.update(i.second.first,i.second.second,i.first);
    }
    REP(i,n)
        printf("%lld ",seg.sum(i,i+1));
     return 0;
}
0