답안 #994380

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
994380 2024-06-07T14:14:35 Z Khanhcsp2 Growing Trees (BOI11_grow) C++14
0 / 100
652 ms 10836 KB
#include<bits/stdc++.h>
#define el '\n'
#define fi first
#define sc second
#define int ll
#define pii pair<int, int>
#define all(v) v.begin(), v.end()
using namespace std;
using ll=long long;
using ull=unsigned long long;
using ld=long double;
const int mod=1e9+7;
const int N=1e5+11;
struct node
{
    int sum, lazy;
    node* l;
    node* r;
    node()
    {
        sum=0, lazy=0;
        l=r=NULL;
    }
};
node* root;
int n, a[N], q;
void down(node* pos, int l, int r)
{
    if(pos->lazy==0) return;
    int mid=(l+r)>>1;
    pos->l->lazy+=pos->lazy;
    pos->r->lazy+=pos->lazy;
    pos->l->sum+=(pos->lazy)*(mid-l+1);
    pos->r->sum+=(pos->lazy)*(r-mid);
}
void update(node* pos, int l, int r, int u, int v, int val)
{
    if(r<u || v<l) return;
    if(u<=l && r<=v)
    {
        pos->sum+=val*(r-l+1);
        pos->lazy+=val;
        return;
    }
    if(pos->l==NULL) pos->l = new node();
    if(pos->r==NULL) pos->r = new node();
    int mid=(l+r)/2;
    down(pos, l, r);
    update(pos->l, l, mid, u, v, val);
    update(pos->r, mid+1, r, u, v, val);
    pos->sum=pos->l->sum+pos->r->sum;
}
int get(node* pos, int l, int r, int u, int v)
{
    if(r<u || v<l) return 0;
    if(u<=l && r<=v)
    {
        return pos->sum;
    }
    if(pos->l==NULL) pos->l = new node();
    if(pos->r==NULL) pos->r = new node();
    int mid=(l+r)/2;
    down(pos, l, r);
    return get(pos->l, l, mid, u, v)+get(pos->r, mid+1, r, u, v);
}
int f1(int x)
{
    int l=1, r=n, ans=n+1;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(get(root, 1, n, mid, mid)>=x)
        {
            r=mid-1;
            ans=min(ans, mid);
        }
        else l=mid+1;
    }
    return ans;
}
int f2(int x)
{
    int l=1, r=n, ans=n+1;
    while(l<=r)
    {
        int mid=(l+r)/2;
        if(get(root, 1, n, mid, mid)>x)
        {
            r=mid-1;
            ans=min(ans, mid);
        }
        else l=mid+1;
    }
    return ans;
}
void sol()
{
    root = new node();
    cin >> n >> q;
    for(int i=1, x; i<=n; i++) cin >> a[i];
    sort(a+1, a+n+1);
    for(int i=1; i<=n; i++) update(root, 1, n, i, i, a[i]);
    while(q--)
    {
        char tt;
        cin >> tt;
        if(tt=='F')
        {
            int c, h;
            cin >> c >> h;
            int pos=f1(h);
            if(pos>n) continue;
            int val=min(n, pos+c-1);
            int l=f1(val);
            int r=f2(val);
            int v=val-l+1;
            update(root, 1, n, pos, l-1, 1);
            update(root, 1, n, r-v, r-1, 1);
        }
        else
        {
            int l, r;
            cin >> l >> r;
            cout << f2(r)-f1(l) << el;
        }
    }
}
signed main()
{
//    freopen("divisor.INP", "r", stdin);
//    freopen("divisor.OUT", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1;
    //cin >> t;
    while(t--)
    {
        sol();
    }
}

Compilation message

grow.cpp: In function 'void sol()':
grow.cpp:100:18: warning: unused variable 'x' [-Wunused-variable]
  100 |     for(int i=1, x; i<=n; i++) cin >> a[i];
      |                  ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 497 ms 9456 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 307 ms 1500 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 326 ms 1620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 491 ms 7160 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 531 ms 8156 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 535 ms 8600 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 652 ms 9296 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 616 ms 9252 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 583 ms 10836 KB Output isn't correct
2 Halted 0 ms 0 KB -