답안 #1008352

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1008352 2024-06-26T09:47:21 Z DucNguyen2007 Meteors (POI11_met) C++14
100 / 100
1193 ms 61416 KB
#include<bits/stdc++.h>
using namespace std;
#define ll unsigned long long
#define ld long double
#define pll pair<ll,ll>
#define fi first
#define se second
const int maxN=3e5+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 BIT
{
    ll a[maxN+1];
    BIT()
    {
        memset(a, 0, sizeof a);
    }
    void clr()
    {
        memset(a, 0, sizeof a);
    }
    void Update(int p, ll v)
    {
        for(; p <= m; p += p & -p)
            a[p] += v;
    }
    void update_range(int l,int r,ll v)
    {
        Update(l,v);
        Update(r+1,-v);
    }
    ll get(int p)
    {
        ll ans = 0;
        for(; p > 0; p -= p & -p)
            ans += a[p];
        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=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;
        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);
            }
        }
        f.clr();
        if(!ok)
        {
            break;
        }
        for(int i=1;i<=k;i++)
        {
            if(q[i].l>q[i].r)
            {
                f.update_range(q[i].l,m,q[i].x);
                f.update_range(1,q[i].r,q[i].x);
            }
            else 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++)
    {
        assert(p[i].l>p[i].r);
        if(p[i].l>k)
        {
            cout<<"NIE";
        }
        else
        {
            assert(ans[i]>=1&&ans[i]<=k);
            cout<<p[i].l;
        }
        cout<<'\n';
    }
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:114:23: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
  114 |                 if(res>=p[j].b)
      |                    ~~~^~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 17752 KB Output is correct
2 Correct 5 ms 18008 KB Output is correct
3 Correct 6 ms 16944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 17752 KB Output is correct
2 Correct 6 ms 17756 KB Output is correct
3 Correct 7 ms 17012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 18512 KB Output is correct
2 Correct 90 ms 21776 KB Output is correct
3 Correct 65 ms 20312 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 73 ms 20704 KB Output is correct
2 Correct 63 ms 20616 KB Output is correct
3 Correct 85 ms 20820 KB Output is correct
4 Correct 21 ms 20060 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 49 ms 20048 KB Output is correct
2 Correct 58 ms 22344 KB Output is correct
3 Correct 38 ms 18836 KB Output is correct
4 Correct 60 ms 21588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 67 ms 18012 KB Output is correct
2 Correct 76 ms 20816 KB Output is correct
3 Correct 44 ms 19388 KB Output is correct
4 Correct 73 ms 22996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 735 ms 37592 KB Output is correct
2 Correct 558 ms 24928 KB Output is correct
3 Correct 154 ms 21840 KB Output is correct
4 Correct 1002 ms 57436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 706 ms 35640 KB Output is correct
2 Correct 538 ms 25096 KB Output is correct
3 Correct 127 ms 21092 KB Output is correct
4 Correct 1193 ms 61416 KB Output is correct