Submission #863516

# Submission time Handle Problem Language Result Execution time Memory
863516 2023-10-20T13:46:13 Z ibm2006 Meteors (POI11_met) C++17
87 / 100
1806 ms 65536 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("avx")
using namespace std;
typedef long long int ll;
typedef __int128 lll;
struct FenwickTree {
    vector<lll> bit;  // binary indexed tree
    int n;

    FenwickTree(int n) {
        this->n = n;
        bit.assign(n, 0);
    }
    void Clear()
    {
        //bit.clear();
        bit.assign(n,0);
    }
    FenwickTree(vector<lll> const &a) : FenwickTree(a.size()) {
        for (size_t i = 0; i < a.size(); i++)
            add(i, a[i]);
    }

    lll sum(int r) {
        lll ret = 0;
        for (; r >= 0; r = (r & (r + 1)) - 1)
            ret += bit[r];
        return ret;
    }

    lll sum(int l, int r) {
        return sum(r) - sum(l - 1);
    }

    void add(int idx, ll delta) {
        for (; idx < n; idx = idx | (idx + 1))
            bit[idx] += delta;
    }
};
FenwickTree fw(300030);
ll x,z,w,l,r,m/*,lazy[1100000]*/;
ll le[330000],ri[330000],q,i,j,k,n,s,ee,a[330000];
ll te1,te2,te3;
lll /*seg[1100000],*/y;
vector<int> v[330000],u[330000];
pair<pair<int,int>,ll> upd[330000];
/*void h(ll x,ll y,ll z)
{
    if(lazy[z]==0)
        return;
    if(z>=524288)
    {
        seg[z]+=lazy[z];
        lazy[z]=0;
        return;
    }
    seg[z]+=(y-x+1)*lazy[z];
    lazy[z<<1]+=lazy[z];
    lazy[(z<<1)+1]+=lazy[z];
    lazy[z]=0;
    return;
}
void Clear()
{
    ll i;
    for(i=0;i<1100000;i++)
    {
        seg[i]=0;
        lazy[i]=0;
    }
}
void f(ll x,ll y,ll z,ll w)
{
    h(x,y,z);
    if(l>y||x>r)
        return;
    if(l<=x&&y<=r)
    {
        lazy[z]+=w;
        h(x,y,z);
        return;
    }
    f(x,(x+y)>>1,z<<1,w);
    f(((x+y)>>1)+1,y,(z<<1)+1,w);
    seg[z]=seg[z<<1]+seg[(z<<1)+1];
}
lll g(ll x,ll y,ll z)
{
    h(x,y,z);
    if(l>y||x>r)
        return 0;
    if(l<=x&&y<=r)
    {
        return seg[z];
    }
    return g(x,(x+y)>>1,z<<1)+g(((x+y)>>1)+1,y,(z<<1)+1);
}*/
int main()
{
    scanf("%lld %lld",&te1,&te2);
    n=te1;
    m=te2;
    for(i=1;i<=m;i++)
    {
        scanf("%lld",&te1);
        x=te1;
        //x=1;
        v[x].push_back(i);
    }
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&te1);
        a[i]=te1;
    //a[i]=1e9;
    }
    scanf("%lld",&te1);
    q=te1;
    for(i=1;i<=q;i++)
    {
        scanf("%lld %lld %lld",&te1,&te2,&te3);
        x=te1;
        w=te2;
        z=te3;
        //x=1;  w=m;  z=1;
        upd[i]={{x,w},z};
    }
    for(i=1;i<=n;i++)
    {
        le[i]=1;
        ri[i]=q+1;
    }
    for(ee=0;ee<19;ee++)
    {
        //printf("!");
        //for(i=1;i<=n;i++)
          //  printf("(%lld,%lld)\n",le[i],ri[i]);
        //Clear();
        s=1;
        fw.Clear();
        for(i=1;i<=q+1;i++)
        {
            u[i].clear();
        }
        for(i=1;i<=n;i++)
            u[(le[i]+ri[i])>>1].push_back(i);
        for(i=1;i<=q+1;i++)
        {
            //printf("%lld\n",i);
            if(i<=q)
            {x=upd[i].first.first;
            y=upd[i].first.second;
            z=upd[i].second;
            if(x<=y)
            {
                l=x;
                r=y;
                //f(1,524288,1,z);
                fw.add(l,z);
                fw.add(r+1,-z);
            }
            else
            {
                l=x;
                r=m;
                fw.add(l,z);
                fw.add(r+1,-z);
                l=1;
                r=y;
                fw.add(l,z);
                fw.add(r+1,-z);
            }
            }
            //printf("?");
            for(j=0;j<u[i].size();j++)
            {
                x=u[i][j];
                y=0;
                for(k=0;k<v[x].size();k++)
                {
                l=v[x][k];
                r=v[x][k];
                y+=fw.sum(1,r);}
                if(a[x]<=y)
                {
                    ri[x]=i;
                }
                else
                    le[x]=i+1;
                    le[x]=min(le[x],q+1);
       // printf("[%lld,%lld]\n",(le[x]+ri[x])/2,x);
                //p[s]={(le[x]+ri[x])/2,x};
                s++;

            }
        }
        //swap(p,pp);
    }
    for(i=1;i<=n;i++)
    {
        a[i]=le[i];
    }
    for(i=1;i<=n;i++)
    {
        te1=a[i];
        if(a[i]>=q+1)
        {
            printf("NIE\n");
        }
        else
            printf("%lld\n",te1);
    }
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:175:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  175 |             for(j=0;j<u[i].size();j++)
      |                     ~^~~~~~~~~~~~
met.cpp:179:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  179 |                 for(k=0;k<v[x].size();k++)
      |                         ~^~~~~~~~~~~~
met.cpp:188:17: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
  188 |                 else
      |                 ^~~~
met.cpp:190:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
  190 |                     le[x]=min(le[x],q+1);
      |                     ^~
met.cpp:101:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  101 |     scanf("%lld %lld",&te1,&te2);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
met.cpp:106:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  106 |         scanf("%lld",&te1);
      |         ~~~~~^~~~~~~~~~~~~
met.cpp:113:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  113 |         scanf("%lld",&te1);
      |         ~~~~~^~~~~~~~~~~~~
met.cpp:117:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |     scanf("%lld",&te1);
      |     ~~~~~^~~~~~~~~~~~~
met.cpp:121:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  121 |         scanf("%lld %lld %lld",&te1,&te2,&te3);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 25688 KB Output is correct
2 Correct 12 ms 25692 KB Output is correct
3 Correct 10 ms 25692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 25692 KB Output is correct
2 Correct 10 ms 25648 KB Output is correct
3 Correct 11 ms 25692 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 82 ms 30480 KB Output is correct
2 Correct 161 ms 32336 KB Output is correct
3 Correct 126 ms 32080 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 130 ms 31572 KB Output is correct
2 Correct 138 ms 31852 KB Output is correct
3 Correct 177 ms 32480 KB Output is correct
4 Correct 41 ms 29288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 110 ms 31060 KB Output is correct
2 Correct 144 ms 33000 KB Output is correct
3 Correct 156 ms 27932 KB Output is correct
4 Correct 136 ms 32544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 167 ms 27996 KB Output is correct
2 Correct 147 ms 31572 KB Output is correct
3 Correct 92 ms 28348 KB Output is correct
4 Correct 170 ms 33644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 885 ms 44216 KB Output is correct
2 Correct 585 ms 31240 KB Output is correct
3 Correct 1022 ms 31828 KB Output is correct
4 Correct 1651 ms 65536 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 904 ms 43144 KB Output is correct
2 Correct 611 ms 31232 KB Output is correct
3 Correct 620 ms 31992 KB Output is correct
4 Runtime error 1806 ms 65536 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -