답안 #753378

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
753378 2023-06-05T06:19:41 Z bgnbvnbv 푸드 코트 (JOI21_foodcourt) C++14
0 / 100
459 ms 66704 KB
#include<bits/stdc++.h>
#define TASKNAME "codeforce"
#define pb push_back
#define pli pair<int,int>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
using ll=long long;
const ll maxN=3e5;
const ll inf=1e18;
const ll mod=1e9+7;
struct node
{
    ll sum,pre;
    node()
    {
        sum=0,pre=0;
    }
    node operator+(const node&o)
    {
        node ans;
        ans.sum=sum+o.sum;
        ans.pre=min(pre,sum+o.pre);
        return ans;
    }
}st[4*maxN];
ll q;
void update(ll pos,ll val,ll id=1,ll l=1,ll r=q)
{
    if(l==r)
    {
        st[id].sum+=val;
        st[id].pre=min(st[id].sum,0ll);
        return;
    }
    ll mid=l+r>>1;
    if(pos<=mid) update(pos,val,id*2,l,mid);
    else update(pos,val,id*2+1,mid+1,r);
    st[id]=st[id*2]+st[id*2+1];
}
node get(ll i,ll j,ll id=1,ll l=1,ll r=q)
{
    if(j<l||r<i) return node();
    if(i<=l&&r<=j) return st[id];
    ll mid=l+r>>1;
    return get(i,j,id*2,l,mid)+get(i,j,id*2+1,mid+1,r);
}
ll seg[4*maxN];
void upd(ll pos,ll val,ll id=1,ll l=1,ll r=q)
{
    if(l==r)
    {
        seg[id]+=val;
        return;
    }
    ll mid=l+r>>1;
    if(pos<=mid) upd(pos,val,id*2,l,mid);
    else upd(pos,val,id*2+1,mid+1,r);
    seg[id]=seg[id*2]+seg[id*2+1];
}

ll quer(ll x)
{
    ll l=1,r=q,id=1;
    while(true)
    {
        ll mid=l+r>>1;
        if(l==r) return l;
        if(seg[id*2+1]<=x)
        {
            x-=seg[id*2+1];
            id=id*2;
            r=mid;
        }
        else
        {
            l=mid+1;
            id=id*2+1;
        }
    }
}
ll n,m,c[maxN];
vector<pli>in[maxN],add[maxN],vec[maxN];
ll ans[maxN];
ll vc[maxN];
void solve()
{
    cin >> n >> m >> q;
    for(int i=1;i<=q;i++)
    {
        ll t;
        cin >> t;
        vc[i]=t;
        if(t==1)
        {
            ll l,r,k;
            cin >> l >> r >> c[i] >> k;
            in[l].pb({i,k});
            in[r+1].pb({i,-k});
            add[l].pb({i,k});
            add[r+1].pb({i,-k});
        }
        else if(t==2)
        {
            ll l,r,k;
            cin >> l >> r >> k;
            in[l].pb({i,-k});
            in[r+1].pb({i,k});
        }
        else
        {
            ll a,b;
            cin >> a >> b;
            vec[a].pb({i,b});
        }
    }
    for(int i=1;i<=n;i++)
    {
        for(auto zz:in[i])
        {
            update(zz.fi,zz.se);
        }
        for(auto zz:add[i])
        {
            upd(zz.fi,zz.se);
        }
        for(auto zz:vec[i])
        {
            auto cc=get(1,zz.fi);
            ll con=cc.sum-cc.pre;
            if(con>=zz.se)
            {
                ans[zz.fi]=c[quer(con-zz.se)];
            }
            else
            {
                ans[zz.fi]=0;
            }
        }
    }
    for(int i=1;i<=q;i++)
    {
        if(vc[i]==3)
        {
            cout << ans[i]<<'\n';
        }
    }

}
int main()
{
    fastio
    //freopen(TASKNAME".INP","r",stdin);
    //freopen(TASKNAME".OUT","w",stdout);
    solve();
}

Compilation message

foodcourt.cpp: In function 'void update(ll, ll, ll, ll, ll)':
foodcourt.cpp:37:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   37 |     ll mid=l+r>>1;
      |            ~^~
foodcourt.cpp: In function 'node get(ll, ll, ll, ll, ll)':
foodcourt.cpp:46:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   46 |     ll mid=l+r>>1;
      |            ~^~
foodcourt.cpp: In function 'void upd(ll, ll, ll, ll, ll)':
foodcourt.cpp:57:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   57 |     ll mid=l+r>>1;
      |            ~^~
foodcourt.cpp: In function 'll quer(ll)':
foodcourt.cpp:68:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   68 |         ll mid=l+r>>1;
      |                ~^~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 40396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 40396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 88 ms 47340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 459 ms 66704 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 40396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 102 ms 47468 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 40396 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 19 ms 40396 KB Output isn't correct
2 Halted 0 ms 0 KB -