結果

問題 No.318 学学学学学
ユーザー a_kawashiroa_kawashiro
提出日時 2017-12-24 15:43:09
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 256 ms / 2,000 ms
コード長 3,160 bytes
コンパイル時間 1,499 ms
コンパイル使用メモリ 96,908 KB
実行使用メモリ 17,036 KB
最終ジャッジ日時 2023-09-04 20:58:17
合計ジャッジ時間 6,307 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
6,516 KB
testcase_01 AC 36 ms
7,692 KB
testcase_02 AC 44 ms
7,924 KB
testcase_03 AC 29 ms
7,124 KB
testcase_04 AC 39 ms
7,776 KB
testcase_05 AC 255 ms
16,888 KB
testcase_06 AC 202 ms
11,876 KB
testcase_07 AC 170 ms
10,576 KB
testcase_08 AC 142 ms
9,520 KB
testcase_09 AC 123 ms
8,320 KB
testcase_10 AC 101 ms
7,736 KB
testcase_11 AC 256 ms
17,036 KB
testcase_12 AC 172 ms
12,052 KB
testcase_13 AC 150 ms
10,704 KB
testcase_14 AC 127 ms
9,552 KB
testcase_15 AC 107 ms
8,480 KB
testcase_16 AC 88 ms
7,336 KB
testcase_17 AC 141 ms
12,120 KB
testcase_18 AC 119 ms
12,060 KB
testcase_19 AC 142 ms
12,252 KB
testcase_20 AC 71 ms
7,552 KB
testcase_21 AC 2 ms
5,568 KB
testcase_22 AC 2 ms
5,544 KB
testcase_23 AC 2 ms
5,548 KB
testcase_24 AC 2 ms
5,564 KB
testcase_25 AC 2 ms
5,556 KB
testcase_26 AC 2 ms
5,548 KB
testcase_27 AC 2 ms
5,548 KB
testcase_28 AC 2 ms
5,768 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()
{
    int n;
    cin >> n;

    vector<int> a(n);
    REP(i, n)cin >> a[i];

    map<int, int>left, right;
    REP(i, n) {
        if (left.count(a[i]) == 0)
            left[a[i]] = i;
    }

    for (int i = n - 1; i >= 0; i--) {
        if (right.count(a[i]) == 0) {
            right[a[i]] = i;
        }
    }

    RangeUpdateRangeSum seg(n);
    REP(i, n)seg.update(i,i+1,a[i]);

    for (auto v : left) {
        if (right.count(v.first)) {
            seg.update(v.second, right[v.first] + 1, v.first);
        }
    }

    REP(i, n)printf("%d ",(int)seg.sum(i,i+1));
    printf("\n");
    return 0;
}
0