답안 #531378

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531378 2022-02-28T14:43:42 Z OttoTheDino Growing Trees (BOI11_grow) C++17
100 / 100
327 ms 3484 KB
#include <bits/stdc++.h>
using namespace std;

#define rep(i,s,e)                  for (int i = s; i <= e; ++i)
#define rrep(i,s,e)                 for (int i = s; i >= e; --i)
#define pb                          push_back
#define pf                          push_front
#define fi                          first
#define se                          second
#define all(a)                      a.begin(), a.end()
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
 
const int mx = 1e5;
int seg[4*mx+1] = {}, n;

void upd (int x, int l, int r, int bl, int br, int id) {
    if (l==bl && r==br) {
        seg[id] += x;
        return;
    }
    int mid = (bl+br)/2;
    if (r<=mid) upd (x, l, r, bl, mid, 2*id);
    else if (l>mid) upd (x, l, r, mid+1, br, 2*id+1);
    else {
        upd (x, l, mid, bl, mid, 2*id);
        upd (x, mid+1, r, mid+1, br, 2*id+1);
    }
}

int qry (int x, int bl, int br, int id, int res) {
    res += seg[id];
    if (bl==br) return res;
    int mid = (bl+br)/2;
    if (x<=mid) return qry (x, bl, mid, 2*id, res);
    return qry (x, mid+1, br, 2*id+1, res);
}

int get_min (int x) {
    int lo = 1, hi = n+1;
    while (lo<hi) {
        int mid = (lo+hi)/2;
        if (qry(mid,1,mx,1,0)>=x) hi = mid;
        else lo = mid+1;
    }
    return lo;
}

int get_max(int x) {
    int lo = 0, hi = n;
    while (lo<hi) {
        int mid = (lo+hi+1)/2;
        if (qry(mid,1,mx,1,0)>x) hi = mid-1;
        else lo = mid;
    }
    return lo;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    int m; cin >> n >> m;
    int a[n+1];
    rep (i,1,n) cin>>a[i];
    sort(a+1,a+n+1);
    rep (i,1,n) upd (a[i], i, i, 1, mx, 1);

    rep (i,1,m) {
        char tp; cin>>tp;
        if (tp=='F') {
            int c, h; cin >> c >> h;
            int j = get_min(h);

            if (j==n+1) continue;

            if (j+c-1>=n) {
                upd (1, j, n, 1, mx, 1);
                continue;
            }

            int h2 = qry (j+c-1, 1, mx, 1, 0);
            int mi = get_min(h2);
            int ma = get_max(h2);

            int cnt = j+c-mi;
            if (j<mi) upd (1, j, mi-1, 1, mx, 1);
            upd (1, ma-cnt+1, ma, 1, mx, 1);
        }

        else {
            int mini, maxi; cin >> mini >> maxi;
            if (qry(get_max(maxi), 1, mx, 1, 0)<mini) cout << "0\n";
            else cout << get_max(maxi) - get_min(mini) + 1 << "\n";
        }
    }


    return 0;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 158 ms 1816 KB Output is correct
2 Correct 296 ms 3284 KB Output is correct
3 Correct 79 ms 3144 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 332 KB Output is correct
4 Correct 3 ms 328 KB Output is correct
5 Correct 124 ms 1456 KB Output is correct
6 Correct 153 ms 1608 KB Output is correct
7 Correct 10 ms 460 KB Output is correct
8 Correct 67 ms 1408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 117 ms 708 KB Output is correct
2 Correct 143 ms 1724 KB Output is correct
3 Correct 3 ms 460 KB Output is correct
4 Correct 80 ms 1348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 107 ms 836 KB Output is correct
2 Correct 163 ms 1740 KB Output is correct
3 Correct 17 ms 552 KB Output is correct
4 Correct 146 ms 1920 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 172 ms 1444 KB Output is correct
2 Correct 267 ms 2628 KB Output is correct
3 Correct 40 ms 936 KB Output is correct
4 Correct 62 ms 2732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 234 ms 1416 KB Output is correct
2 Correct 264 ms 1780 KB Output is correct
3 Correct 78 ms 2984 KB Output is correct
4 Correct 41 ms 928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 163 ms 1640 KB Output is correct
2 Correct 161 ms 2836 KB Output is correct
3 Correct 75 ms 3144 KB Output is correct
4 Correct 42 ms 968 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 294 ms 1844 KB Output is correct
2 Correct 267 ms 1552 KB Output is correct
3 Correct 47 ms 2556 KB Output is correct
4 Correct 135 ms 2692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 218 ms 1788 KB Output is correct
2 Correct 281 ms 3304 KB Output is correct
3 Correct 327 ms 3484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 254 ms 2172 KB Output is correct