답안 #1008319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1008319 2024-06-26T09:18:36 Z DucNguyen2007 Meteors (POI11_met) C++14
74 / 100
845 ms 58880 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=6e5+5;
const ll inf=2e18;
int n,m,a[maxN+1],k,ans[maxN+1];
vector<int> v[maxN+1],pos[maxN+1];
struct query
{
    int l,r;
    ll x;
}q[maxN+1];
struct met
{
    int l,r,mid,b;
}p[maxN+1];
struct fenwick
{
    ll bit[maxN+1];
    void clr()
    {
        memset(bit,0,sizeof(bit));
    }
    void update(int u,ll val)
    {
        for(int i=u;i<=2*m;i+=(i&(-i)))
        {
            bit[i]+=val;
        }
    }
    void update_range(int l,int r,ll val)
    {
        update(l,val);
        update(r+1,-val);
    }
    ll get(int u)
    {
        ll ans=0;
        for(int i=u;i>0;i-=(i&(-i)))
        {
            ans+=bit[i];
        }
        return ans;
    }
}f;
int main()
{
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=m;i++)
    {
        cin>>a[i];
        assert(a[i]<=maxN);
        pos[a[i]].push_back(i);
    }
    for(int i=m+1;i<=2*m;i++)
    {
        a[i]=a[i-m];
        assert(a[i]<=maxN);
        pos[a[i]].push_back(i);
    }
    for(int i=1;i<=n;i++)
    {
        cin>>p[i].b;
    }
    cin>>k;
    for(int i=1;i<=k;i++)
    {
        cin>>q[i].l>>q[i].r>>q[i].x;
        if(q[i].l>q[i].r)
        {
            q[i].r+=m;
        }
        assert(q[i].l<=maxN);
        assert(q[i].r<=maxN);
    }
    for(int i=1;i<=n;i++)
    {
        p[i].l=1;
        p[i].r=k;
        ans[i]=-1;
    }
    while(1)
    {
        bool ok=false;
        for(int i=1;i<=n;i++)
        {
            if(p[i].l<=p[i].r)
            {
                p[i].mid=(p[i].l+p[i].r)/2;
                ok=true;
                assert(p[i].mid>=0&&p[i].mid<=maxN);
                v[p[i].mid].push_back(i);
            }
        }
        if(!ok)
        {
            break;
        }
        f.clr();
        for(int i=1;i<=k;i++)
        {
            f.update_range(q[i].l,q[i].r,q[i].x);
            for(auto j:v[i])
            {
                ll res=0;
                for(auto id:pos[j])
                {
                    res+=f.get(id);
                }
                if(res>=p[j].b)
                {
                    ans[j]=p[j].mid;
                    p[j].r=p[j].mid-1;
                }
                else p[j].l=p[j].mid+1;
            }
            v[i].clear();
        }
    }
    for(int i=1;i<=n;i++)
    {
        if(ans[i]==-1)
        {
            cout<<"NIE";
        }
        else
        {
            assert(ans[i]>=1&&ans[i]<=k);
            cout<<ans[i];
        }
        cout<<'\n';
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 11 ms 35932 KB Output is correct
2 Correct 12 ms 35928 KB Output is correct
3 Correct 12 ms 36000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 36024 KB Output is correct
2 Correct 12 ms 35928 KB Output is correct
3 Correct 13 ms 35932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 64 ms 37968 KB Output is correct
2 Correct 98 ms 40272 KB Output is correct
3 Correct 86 ms 39760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 86 ms 39280 KB Output is correct
2 Correct 76 ms 39252 KB Output is correct
3 Correct 104 ms 40276 KB Output is correct
4 Correct 37 ms 38480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 38480 KB Output is correct
2 Correct 67 ms 40528 KB Output is correct
3 Correct 37 ms 36696 KB Output is correct
4 Correct 86 ms 40016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 77 ms 37636 KB Output is correct
2 Correct 81 ms 39140 KB Output is correct
3 Correct 61 ms 37940 KB Output is correct
4 Correct 98 ms 41296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 819 ms 58880 KB Output is correct
2 Incorrect 391 ms 45224 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 845 ms 57444 KB Output is correct
2 Incorrect 756 ms 45256 KB Output isn't correct
3 Halted 0 ms 0 KB -