Submission #630210

# Submission time Handle Problem Language Result Execution time Memory
630210 2022-08-16T03:56:41 Z Soul234 Growing Trees (BOI11_grow) C++14
0 / 100
110 ms 6104 KB
#include<bits/stdc++.h>
using namespace std;

void DBG() { cerr << "]\n"; }
template<class H, class... T> void DBG(H h, T... t) {
    cerr << h; if(sizeof...(t)) cerr << ", ";
    DBG(t...);
}
#ifdef LOCAL
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif // LOCAL

#define FOR(i,a,b) for(int i = (a) ; i<(b) ; i++)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for(int i = (b)-1 ; i>=(a) ; i--)
#define R0F(i,a) ROF(i,0,a)
#define each(e,a) for(auto &e : (a))
#define sz(v) (int)(v).size()
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back
#define tcT template<class T
#define nl "\n"

using ll = long long;
using vi = vector<int>;
using pi = pair<int,int>;
using str = string;
tcT> using V = vector<T>;
tcT> using pqg = priority_queue<T,vector<T>,greater<T>>;

void setIO(string NAME = "") {
    cin.tie(0)->sync_with_stdio(0);
    if(sz(NAME)) {
        freopen((NAME + ".inp").c_str(),"r",stdin);
        freopen((NAME + ".out").c_str(),"w",stdout);
    }
}

tcT> bool ckmin(T&a, const T&b) {
    return b < a ? a=b,1 : 0; }
tcT> bool ckmax(T&a, const T&b) {
    return b > a ? a=b,1 : 0; }

const int MOD = 1e9 + 7;

const int MX = 1e5+5;
int A[MX];

struct SegTree {
    int N; vi mx, lazy;
    const int ID = 0;
    int comb(int a, int b) { return max(a,b); }
    void build(int ind, int L, int R) {
        if(L == R) mx[ind] = A[L];
        else {
            int mid = (L + R) >> 1;
            build(ind<<1, L, mid);
            build(ind<<1|1, mid+1, R);
            mx[ind] = comb(mx[ind<<1], mx[ind<<1|1]);
        }
    }
    void init(int _N = 0) {
        N = _N;
        mx.assign(N*4 + 7, ID);
        lazy.assign(N*4 + 7, ID);
        build(1, 1, N);
    }

    void push(int ind) {
        if(lazy[ind] == 0) return;
        F0R(i, 2) {
            mx[ind*2 + i] += lazy[ind];
            lazy[ind*2 + i] += lazy[ind];
        }
        lazy[ind] = 0;
    }

    int getFst(int val, int ind, int L, int R) {
        if(L == R) return L;
        push(ind);
        int mid = (L + R) >> 1;
        if(mx[ind << 1] > val) return getFst(val, ind<<1, L, mid);
        else return getFst(val, ind<<1|1, mid+1, R);
    }
    int getFst(int val) {
        if(mx[1] <= val) return N+1;
        return getFst(val, 1, 1, N);
    }
    int getVal(int p, int ind, int L, int R) {
        if(L == R) return mx[ind];
        int mid = (L + R) >> 1;
        push(ind);
        if(p <= mid) return getVal(p, ind<<1, L, mid);
        return getVal(p, ind<<1|1, mid+1, R);
    }
    int getVal(int p) {
        return getVal(p, 1, 1, N);
    }

    void updInc(int l, int r, int ind, int L, int R) {
        if(l > R || r < L || L > R || l > r) return;
        if(l <= L && R <= r) {
            mx[ind]++;
            lazy[ind]++;
            return;
        }
        int mid = (L + R) >> 1;
        push(ind);
        updInc(l, r, ind<<1, L, mid);
        updInc(l, r, ind<<1|1, mid+1, R);
        mx[ind] = comb(mx[ind<<1], mx[ind<<1|1]);
    }
    void updInc(int l, int r) {
        updInc(l, r, 1, 1, N);
    }
};

int N, M;
SegTree st;

void solve() {
    cin >> N >> M;
    FOR(i,1,N+1) cin >> A[i];
    sort(A+1, A+N+1);
    st.init(N);
    while(M-- > 0) {
        char t;
        cin >> t;
        if(t == 'F') {
            int amt, mnH;
            cin >> amt >> mnH;
            int l = st.getFst(mnH-1);
            if(l == N+1) continue;
            int r = min(N, l + amt - 1);
            int val_at_r = st.getVal(r);
            int _l = st.getFst(val_at_r-1);
            st.updInc(l, _l-1);

            amt -= (_l - l);

            int _r = st.getFst(val_at_r);
            st.updInc(_r - amt, _r-1);
        }
        else {
            int mnH, mxH;
            cin >> mnH >> mxH;
            cout << st.getFst(mxH) - st.getFst(mnH-1) << nl;
        }
    }
}

int main() {
    setIO();

    int t=1;
    //cin>>t;
    while(t-->0) {
        solve();
    }

    return 0;
}

Compilation message

grow.cpp: In function 'void setIO(std::string)':
grow.cpp:37:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   37 |         freopen((NAME + ".inp").c_str(),"r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
grow.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen((NAME + ".out").c_str(),"w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 69 ms 4560 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Incorrect 2 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 1740 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 29 ms 1836 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 60 ms 3632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 3984 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 47 ms 4168 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 110 ms 4996 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 4732 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 67 ms 6104 KB Output isn't correct
2 Halted 0 ms 0 KB -