답안 #393729

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393729 2021-04-24T12:07:53 Z ak2006 Growing Trees (BOI11_grow) C++14
0 / 100
122 ms 1612 KB
#include <bits/stdc++.h>
using namespace std;
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)
{
    for (;i<=n;i+=i&(-i))bit[i] += inc;
}
void update(int i,int j,int inc)
{
    update(i,inc);
    update(j + 1,-inc);
}
int sum(int i)
{
    int ret = 0;
    for (;i>0;i-=i&(-i))ret += bit[i];
    return ret;
}
int lowerBound(int h)
{
    int l = 1,r = n,ans = n;
    while (l <= r){
        int mid = (l + r)/2;
        if (sum(mid) >= h){
            ans = mid;
            r = mid - 1;
        }
        else l = mid + 1;
    }
    return ans;
}
int Bound(int pos,int h)
{
    int l = pos,r = n,ans = pos;
    while (l <= r){
        int mid = (l + r)/2;
        if (sum(mid) == h){
            ans = mid;
            l = mid + 1;
        }
        else r = mid - 1;
    }
    return ans;
}
int Lower(int h)
{
    int l = 1,r = n,ans = 0;
    while (l <= r){
        int mid = (l + r)/2;
        if (sum(mid) < h){
            ans = mid;
            l = mid + 1;
        }
        else r = mid - 1;
    }
    return ans;
}
int Lower2(int h)
{
    int l = 1,r = n,ans = -1;
    while (l <= r){
        int mid = (l + r)/2;
        if (sum(mid) <= h){
            ans = mid;
            l = mid + 1;
        }
        else r = mid - 1;
    }
    return ans;
}
int 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,i,a[i]);

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

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

            if (first == n && sum(first) < h)continue;

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

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

            int pos = Lower(val);//index before the height of the last index to be updated

            if (pos == 0)pos = Last;

            update(first,pos,1);

            int rem = c - (pos - first + 1);

            if (rem == 0)continue;
            int actLast = Bound(Last,val);
            update(actLast - rem + 1,actLast,1);

        }
        else{
            int mn,mx;
            cin>>mn>>mx;
            int L1 = lowerBound(mn),L2 = Lower2(mx);
            if (sum(1) > mx or sum(n) < mn)cout<<0<<'\n';
            else cout<<L2 - L1 + 1<<'\n';
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 63 ms 1064 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 716 KB Output is correct
2 Incorrect 3 ms 732 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 55 ms 884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 45 ms 884 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 74 ms 972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 81 ms 1056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 57 ms 1176 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 122 ms 1160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 86 ms 1076 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 113 ms 1612 KB Output isn't correct