답안 #393759

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393759 2021-04-24T12:49:29 Z ak2006 Growing Trees (BOI11_grow) C++14
10 / 100
123 ms 2356 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 = 1,r = n ;
    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 = 1,r = n ;
    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,a[i] - a[i - 1]);

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

            if (sum(n) < h)continue;

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

            int Last = min(n,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(1) > mx or sum(n) < mn)cout<<0<<'\n';
            else cout<<L2 - L1 + 1<<'\n';
        }
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 58 ms 1860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 Incorrect 52 ms 2136 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 59 ms 1444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 52 ms 1308 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 81 ms 1632 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 90 ms 1768 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 64 ms 1776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 123 ms 2032 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 88 ms 1860 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 116 ms 2356 KB Output is correct