답안 #94188

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94188 2019-01-16T12:51:19 Z rkocharyan Growing Trees (BOI11_grow) C++14
0 / 100
290 ms 5880 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 1e5 + 7;

int n, m;
int t[4 * N];
int lazy[4 * N];

void push(int v, int tl, int tr) {
    if(lazy[v]) {
        t[v] += lazy[v] * (tr - tl + 1);
        if(tl != tr) {
            lazy[2 * v + 1] += lazy[v];
            lazy[2 * v + 2] += lazy[v];
        }
        lazy[v] = 0;
    }
}

void update(int v, int tl, int tr, int l, int r) {
    push(v, tl, tr);
    if(l > r) return;
    if(tl == l && tr == r) {
        lazy[v]++;
        push(v, tl, tr);
        return;
    }
    int tm = (tl + tr) >> 1;
    update(2 * v + 1, tl, tm, l, min(r, tm));
    update(2 * v + 2, tm + 1, tr, max(l, tm + 1), r);
    t[v] = t[2 * v + 1] + t[2 * v + 2];
}

int get(int v, int tl, int tr, int l, int r) {
    push(v, tl, tr);
    if(l > r) return 0;
    if(tl == l && tr == r) return t[v];
    int tm = (tl + tr) >> 1;
    int lf = get(2 * v + 1, tl, tm, l, min(r, tm));
    int rg = get(2 * v + 2, tm + 1, tr, max(l, tm + 1), r);
    return lf + rg;
}

int get(int pos) {
    return get(0, 1, n, pos, pos);
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    vector <int> a(n + 1, 0);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    a[0] = -1;
    sort(a.begin(), a.end());
    while(m--) {
        char type;
        cin >> type;
        if(type == 'F') {
            int c, h;
            cin >> c >> h;
            int low = 1, high = n, pos = n + 1;
            while(low <= high) {
                int mid = (low + high) >> 1;
                if(a[mid] + get(mid) >= h) {
                    pos = mid;
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            if(pos == n + 1) continue;
            int to = pos + c - 1;
            if(to == n || a[to + 1] + get(to + 1) != a[to]) {
                update(0, 1, n, pos, to);
            } else {
                int f = a[to];
                low = 1, high = n;
                int l = 0;
                while(low <= high) {
                    int mid = (low + high) >> 1;
                    if(a[mid] + get(mid) < f) {
                        l = mid;
                        low = mid + 1;
                    } else {
                        high = mid - 1;
                    }
                }
                low = 1, high = n;
                int r = n + 1;
                while(low <= high) {
                    int mid = (low + high) >> 1;
                    if(a[mid] + get(mid) > f) {
                        r = mid;
                        high = mid - 1;
                    } else {
                        low = mid + 1;
                    }
                }
                l++;
                r--;
                int len = to - l + 1;
                update(0, 1, n, pos, l - 1);
                update(0, 1, n, r - len + 1, r);
            }
        } else {
            int mn, mx;
            cin >> mn >> mx;
            int low = 1, high = n, l = n + 1;
            while(low <= high) {
                int mid = (low + high) >> 1;
                if(a[mid] + get(mid) >= mn) {
                    l = mid;
                    high = mid - 1;
                } else {
                    low = mid + 1;
                }
            }
            low = 1, high = n;
            int r = 0;
            while(low <= high) {
                int mid = (low + high) >> 1;
                if(a[mid] + get(mid) <= mx) {
                    r = mid;
                    low = mid + 1;
                } else {
                    high = mid - 1;
                }
            }
            if(l > r) {
                cout << "0\n";
                continue;
            }
            cout << r - l + 1 << '\n';
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 26 ms 5880 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 46 ms 1188 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 290 ms 1908 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 55 ms 3616 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 2424 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 13 ms 3448 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 18 ms 3832 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 34 ms 5752 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 20 ms 2808 KB Execution killed with signal 11 (could be triggered by violating memory limits)