Submission #72189

# Submission time Handle Problem Language Result Execution time Memory
72189 2018-08-26T05:51:28 Z cat > /dev/null(#2231, lobo_prix, jms100300, enochjung) Box Run (FXCUP3_box) C++17
17 / 100
62 ms 3700 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);    
    }    

    ~IT() {
        delete[] arr;
    }
};  

const int MAX_N = 1e5;
pair<int, int> tmp[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++;
        arr[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(arr[0], 0);
    for (int i = 1; i < N; i ++) {
        if (arr[i] > arr[i-1]) { 
            int qidx = segtree.query(arr[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(arr[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:77: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) {
     ^~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 832 KB Output is correct
3 Correct 3 ms 1032 KB Output is correct
4 Correct 3 ms 1032 KB Output is correct
5 Correct 3 ms 1032 KB Output is correct
6 Correct 2 ms 1032 KB Output is correct
7 Correct 2 ms 1032 KB Output is correct
8 Correct 3 ms 1032 KB Output is correct
9 Correct 4 ms 1032 KB Output is correct
10 Correct 3 ms 1032 KB Output is correct
11 Correct 3 ms 1032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 760 KB Output is correct
2 Correct 3 ms 832 KB Output is correct
3 Correct 3 ms 1032 KB Output is correct
4 Correct 3 ms 1032 KB Output is correct
5 Correct 3 ms 1032 KB Output is correct
6 Correct 2 ms 1032 KB Output is correct
7 Correct 2 ms 1032 KB Output is correct
8 Correct 3 ms 1032 KB Output is correct
9 Correct 4 ms 1032 KB Output is correct
10 Correct 3 ms 1032 KB Output is correct
11 Correct 3 ms 1032 KB Output is correct
12 Correct 3 ms 1032 KB Output is correct
13 Correct 5 ms 1100 KB Output is correct
14 Correct 28 ms 2260 KB Output is correct
15 Correct 43 ms 3172 KB Output is correct
16 Correct 62 ms 3700 KB Output is correct
17 Runtime error 24 ms 3700 KB Execution killed with signal 11 (could be triggered by violating memory limits)
18 Halted 0 ms 0 KB -