답안 #72178

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
72178 2018-08-26T05:47:20 Z cat > /dev/null(#2231, lobo_prix, jms100300, enochjung) 박스런 (FXCUP3_box) C++17
17 / 100
49 ms 4108 KB
#include<bits/stdc++.h>
using namespace std;
template<typename T>    
struct IT {    
    typedef size_t sint;    
    typedef function<T(const T&,const T&)> func;    
    T *arr;    
    T init_val;  

    sint N;    
    func F;    

    IT(sint n, func F):F(F) {    
        for (N = 1; N < n; N <<= 1);    
        arr = new T[N << 1]();    
        init_val = T();  
    }    

    IT(sint n, func F, T init_val):F(F),init_val(init_val) {  
        for (N = 1; N < n; N <<= 1);  
        arr = new T[N << 1];  
        fill(arr, arr + (N<<1), init_val);  
    }  

    void update(sint i, T val) {    
        i |= N;    
        arr[i] = val;    
        while (i >>= 1)    
            arr[i] = F(arr[i<<1], arr[i<<1 | 1]);    
    }    

    T query(sint l, sint r) {    
        l |= N, r |= N;    
        T lval = init_val, rval = init_val;    
        while (l <= r) {    
            if (l & 1)    
                lval = F(lval, arr[l++]);    
            if (!(r & 1))    
                rval = F(arr[r--], rval);    
            l >>= 1, r >>= 1;    
        }    
        return F(lval, rval);    
    }    
};  

const int MAX_N = 1e5;
pair<int, int> tmp[MAX_N];
int valcomp[MAX_N];
int arr[MAX_N];
int res[MAX_N];

int main(void) {
    ios_base::sync_with_stdio(false), cin.tie(NULL);
    vector<int> vals;

    int N;  cin >> N;
    for (int i = 0; i < N; i ++) {
        cin >> arr[i];
        tmp[i].first = arr[i];
        tmp[i].second = i;
    }

    sort(tmp, tmp + N);
    int cur_idx = -1;
    int prv_val = -1;
    for (int i = 0; i < N; i ++) {
        if (prv_val != tmp[i].first) 
            cur_idx++;
        valcomp[tmp[i].second] = cur_idx;
        prv_val = tmp[i].first;
    }
    cur_idx ++;

    IT<int> segtree(cur_idx+1, [](const int& a, const int& b) { return max(a,b); }, -1);
    int last = 0;

    memset(res, -1, sizeof res);
    segtree.update(valcomp[0], 0);
    for (int i = 1; i < N; i ++) {
        if (arr[i] > arr[i-1]) { 
            int qidx = segtree.query(valcomp[i], cur_idx);
            if (qidx != -1) {
                for (int k = qidx+1; k < i-last; k ++) 
                    res[i-k-1] = k+1;

                last = max(last, i-qidx-1);
            }
            else {
                for (; last < i; last ++)
                    res[last] = i-last;
            }
        }
        segtree.update(valcomp[i], i);
    }

    for (int i = 0; i < N; i ++)
        cout << res[i] << ' ';
    cout << endl;
}

Compilation message

box.cpp: In instantiation of 'IT<T>::IT(IT<T>::sint, IT<T>::func, T) [with T = int; IT<T>::sint = long unsigned int; IT<T>::func = std::function<int(const int&, const int&)>]':
box.cpp:74:87:   required from here
box.cpp:11:10: warning: 'IT<int>::F' will be initialized after [-Wreorder]
     func F;
          ^
box.cpp:8:7: warning:   'int IT<int>::init_val' [-Wreorder]
     T init_val;
       ^~~~~~~~
box.cpp:19:5: warning:   when initialized here [-Wreorder]
     IT(sint n, func F, T init_val):F(F),init_val(init_val) {
     ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 760 KB Output is correct
2 Correct 3 ms 868 KB Output is correct
3 Correct 3 ms 868 KB Output is correct
4 Correct 3 ms 868 KB Output is correct
5 Correct 3 ms 868 KB Output is correct
6 Correct 4 ms 896 KB Output is correct
7 Correct 4 ms 1044 KB Output is correct
8 Correct 3 ms 1044 KB Output is correct
9 Correct 3 ms 1044 KB Output is correct
10 Correct 3 ms 1076 KB Output is correct
11 Correct 3 ms 1076 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 760 KB Output is correct
2 Correct 3 ms 868 KB Output is correct
3 Correct 3 ms 868 KB Output is correct
4 Correct 3 ms 868 KB Output is correct
5 Correct 3 ms 868 KB Output is correct
6 Correct 4 ms 896 KB Output is correct
7 Correct 4 ms 1044 KB Output is correct
8 Correct 3 ms 1044 KB Output is correct
9 Correct 3 ms 1044 KB Output is correct
10 Correct 3 ms 1076 KB Output is correct
11 Correct 3 ms 1076 KB Output is correct
12 Correct 3 ms 1076 KB Output is correct
13 Correct 4 ms 1076 KB Output is correct
14 Correct 34 ms 2428 KB Output is correct
15 Correct 38 ms 3580 KB Output is correct
16 Correct 49 ms 4108 KB Output is correct
17 Runtime error 32 ms 4108 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Halted 0 ms 0 KB -