답안 #393761

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393761 2021-04-24T12:50:21 Z ak2006 Growing Trees (BOI11_grow) C++14
100 / 100
128 ms 3656 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll = long long;
using vb = vector<bool>;
using vvb = vector<vb>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vc = vector<char>;
using vvc = vector<vc>;
const ll mod = 1e9 + 7,inf = 1e18;
#define pb push_back
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define lc 2 * no
#define rc 2 * no + 1
int n = 1e5 + 5,q;
vi bit(n);
void update(int i,int inc)
{
    i++;
    for (;i<=n;i+=i&(-i))bit[i] += inc;
}
int sum(int i)
{
    i++;
    int ret = 0;
    for (;i>0;i-=i&(-i))ret += bit[i];
    return ret;
}
int lowerBound(int h)
{
    int l = 0,r = n - 1;
    while (l < r){
        int mid = (l + r)/2;
        if (sum(mid) >= h)r = mid;
        else l = mid + 1;
    }
    return l;
}
int Lower2(int h)
{
    int l = 0,r = n - 1;
    while (l < r){
        int mid = (l + r)/2;
        if (sum(mid + 1) <= h)l = mid + 1;
        else r = mid;
    }
    return l;
}
int32_t main()
{
    fast;
    cin>>n>>q;
    vi a(n + 1);
    for (int i = 1;i<=n ;i++)cin>>a[i];
    sort(a.begin() + 1,a.end());

    for (int i = 1;i<=n;i++)update(i - 1,a[i] - a[i - 1]);

    while (q--){
        char x;
        cin>>x;
        if (x == 'F'){
            int c,h;
            cin>>c>>h;

            if (sum(n - 1) < h)continue;

            int first = lowerBound(h);//first index to be updated

            int Last = min(n - 1,first + c - 1);//last index to be updated

            if (first + c - 1 >= n)c = n - first;

            int val = sum(Last);//height of the last index to be updated

            int pos1 = lowerBound(val),pos2 = Lower2(val);

            int rem = c - (pos1 - first);

            update(first,1);
            update(pos1,-1);
            update(pos2 - rem + 1,1);
            update(pos2 + 1,-1);


        }
        else{
            int mn,mx;
            cin>>mn>>mx;
            int L1 = lowerBound(mn),L2 = Lower2(mx);
            if (sum(0) > mx or sum(n - 1) < mn)cout<<0<<'\n';
            else cout<<L2 - L1 + 1<<'\n';
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 76 ms 1944 KB Output is correct
2 Correct 123 ms 3420 KB Output is correct
3 Correct 80 ms 3396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1100 KB Output is correct
2 Correct 3 ms 1100 KB Output is correct
3 Correct 3 ms 1100 KB Output is correct
4 Correct 2 ms 1100 KB Output is correct
5 Correct 51 ms 1348 KB Output is correct
6 Correct 64 ms 2352 KB Output is correct
7 Correct 5 ms 1228 KB Output is correct
8 Correct 36 ms 1924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 60 ms 1456 KB Output is correct
2 Correct 63 ms 2532 KB Output is correct
3 Correct 2 ms 1100 KB Output is correct
4 Correct 44 ms 2028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 56 ms 1572 KB Output is correct
2 Correct 73 ms 2444 KB Output is correct
3 Correct 7 ms 1228 KB Output is correct
4 Correct 63 ms 2508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 1780 KB Output is correct
2 Correct 106 ms 3064 KB Output is correct
3 Correct 19 ms 1612 KB Output is correct
4 Correct 72 ms 3184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 100 ms 1860 KB Output is correct
2 Correct 106 ms 3064 KB Output is correct
3 Correct 84 ms 3288 KB Output is correct
4 Correct 20 ms 1740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 80 ms 1864 KB Output is correct
2 Correct 77 ms 3140 KB Output is correct
3 Correct 85 ms 3396 KB Output is correct
4 Correct 19 ms 1616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 123 ms 1860 KB Output is correct
2 Correct 108 ms 2988 KB Output is correct
3 Correct 31 ms 2508 KB Output is correct
4 Correct 77 ms 2884 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 98 ms 2028 KB Output is correct
2 Correct 116 ms 3396 KB Output is correct
3 Correct 128 ms 3656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 115 ms 2384 KB Output is correct