Submission #100954

# Submission time Handle Problem Language Result Execution time Memory
100954 2019-03-15T11:49:59 Z shafinalam Growing Trees (BOI11_grow) C++14
0 / 100
1000 ms 5836 KB
#include <bits/stdc++.h>

using namespace std;

const int mx = 1e5+5;
typedef long long ll;

#define  sf scanf
#define  pf printf

ll tree[mx<<2];
ll lazy[mx<<2];
ll arr[mx];
ll n, m;

void push(ll node, ll b,ll e)
{
    if(lazy[node])
    {
        ll left = node<<1;
        ll right = left|1;
        tree[node]+=((e-b+1)*lazy[node]);
        if(b!=e)
        {
            lazy[left]+=lazy[node];
            lazy[right]+=lazy[node];
        }
        lazy[node] = 0;
    }
    return;
}
void update(ll node, ll b, ll e, ll l, ll r)
{
    push(node, b, e);
    if(b>r || e<l) return;
    if(b>=l && e<=r)
    {
        lazy[node]++;
        push(node, b, e);
        return;
    }
    ll mid = (b+e)>>1;
    ll left = node<<1;
    ll right = left|1;
    update(left, b, mid, l, r);
    update(right, mid+1, e, l, r);
    tree[node] = tree[left]+tree[right];
}
ll query(ll node, ll b, ll e, ll pos)
{
    push(node, b, e);
    if(b>pos || e<pos) return 0;
    if(b>=pos && e<=pos) return tree[node];
    ll mid = (b+e)>>1;
    ll left = node<<1;
    ll right = left|1;
    return query(left, b, mid, pos)+query(right, mid+1, e, pos);
}
ll get(ll pos)
{
    return query(1, 1, n, pos);
}
int main()
{
    sf("%lld%lld", &n, &m);

    for(ll i = 1; i <= n; i++) sf("%lld", &arr[i]);
    sort(arr+1, arr+n+1);

    while(m--)
    {
        char type;
        cin >> type;

        if(type=='F')
        {
            ll h, c;
            sf("%lld%lld", &c, &h);

            ll lo = 1, hi = n, pos = -1;
            while(lo<=hi)
            {
                ll mid = (lo+hi)>>1;
                if(arr[mid]+get(mid)>=h)
                {
                    pos = mid;
                    hi = mid-1;
                }
                else
                    lo = mid+1;
            }
            if(pos==-1) continue;
            ll last = pos+c-1;
            last = min(last, n);
            if(last==n || arr[last]+get(last)!=arr[last+1]+get(last+1)) update(1, 1, n, pos, last);
            else
            {
                ll l = 0, r = n+1, val = arr[last]+get(last);
                lo = 1, hi = n;
                while(lo<=hi)
                {
                    ll mid = (lo+hi)>>1;
                    if(arr[mid]+get(mid)<val)
                    {
                        lo = mid+1;
                        l = mid;
                    }
                    else hi = mid-1;
                }
                lo = 1, hi = n;
                while(lo<=hi)
                {
                    ll mid = (lo+hi)>>1;
                    if(arr[mid]+get(mid)>val)
                    {
                        r = mid;
                        hi = mid-1;
                    }
                    else lo = mid+1;
                }
                l++;
                r--;
                ll len = last-l+1;
                update(1, 1, n, pos, l-1);
                update(1, 1, n, r-len+1, r);

            }
        }
        else
        {
            ll a, b;
            sf("%lld%lld", &a, &b);

            ll l = -1, r = -1, lo = 1, hi = n;

            while(lo<=hi)
            {
                ll mid = (lo+hi)>>1;
                if(arr[mid]+get(mid)>=a)
                {
                    l = mid;
                    hi = mid-1;
                }
                else lo = mid+1;
            }
            if(l==-1)
            {
                pf("0\n");
                continue;
            }
            lo = 1, hi = n;
            while(lo<=hi)
            {
                ll mid = (lo+hi)>>1;
                if(arr[mid]+get(mid)<=b)
                {
                    r = mid;
                    lo = mid+1;
                }
                else hi = mid-1;
            }
            pf("%lld\n", r-l+1);
        }
    }
    return 0;
}

Compilation message

grow.cpp: In function 'int main()':
grow.cpp:65:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     sf("%lld%lld", &n, &m);
       ^
grow.cpp:67:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     for(ll i = 1; i <= n; i++) sf("%lld", &arr[i]);
                                  ^
grow.cpp:78:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             sf("%lld%lld", &c, &h);
               ^
grow.cpp:132:15: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             sf("%lld%lld", &a, &b);
               ^
# Verdict Execution time Memory Grader output
1 Incorrect 962 ms 5476 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 10 ms 384 KB Output is correct
2 Incorrect 23 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 644 ms 1060 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 578 ms 1248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 837 ms 3184 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1083 ms 5224 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 816 ms 5416 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 990 ms 5528 KB Output is correct
2 Execution timed out 1026 ms 5344 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1053 ms 5452 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 1070 ms 5836 KB Time limit exceeded