Submission #863272

# Submission time Handle Problem Language Result Execution time Memory
863272 2023-10-20T00:48:30 Z ibm2006 Meteors (POI11_met) C++17
0 / 100
137 ms 65536 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef __int128 lll;
ll n,e,i,j,k,x,z,w,l,r,m,q,lazy[1100000],a[330000],le[330000],ri[330000],s,ans[330000],b[330000],cc[330000],ans2[330000];
lll seg[1100000],y;
vector<ll> v[330000],u[330000];
pair<ll,ll> p[330000],pp[330000];
pair<pair<ll,ll>,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*2]+=lazy[z];
    lazy[z*2+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)/2,z*2,w);
    f((x+y)/2+1,y,z*2+1,w);
    seg[z]=seg[z*2]+seg[z*2+1];
}
ll 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)/2,z*2)+g((x+y)/2+1,y,z*2+1);
}
int main()
{
    srand(time(NULL));
    scanf("%lld %lld",&n,&m);
    //scanf("%lld",&q);
    //while(1)
    {

        for(i=1;i<=300000;i++)
        {
            v[i].clear();
            u[i].clear();
        }
        Clear();
        for(i=1;i<=m;i++)
    {
        scanf("%lld",&x);
        //x=rand()%n+1;
        //printf("%lld ",x);
        cc[i]=x;
        v[x].push_back(i);
    }
    //printf("\n");
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        //a[i]=rand()+1;
        //printf("%lld ",a[i]);
    }
    scanf("%lld",&q);
    for(i=1;i<=q;i++)
    {
        scanf("%lld %lld %lld",&x,&w,&z);
        //x=rand()%m+1;
        //w=rand()%m+1;
        //z=rand()%4+1;
       // printf("%lld %lld %lld\n",x,w,z);
        upd[i]={{x,w},z};
    }

    for(i=1;i<=n;i++)
    {
        le[i]=1;
        ri[i]=q+1;
        p[i]={(le[i]+ri[i])/2,i};
    }
    for(e=0;e<40;e++)
    {
        //printf("!");
        //for(i=1;i<=n;i++)
          //  printf("(%lld,%lld)\n",le[i],ri[i]);
        Clear();
        s=1;
        for(i=1;i<=q+1;i++)
        {
            u[i].clear();
        }
        for(i=1;i<=n;i++)
            u[p[i].first].push_back(p[i].second);
        for(i=1;i<=q+1;i++)
        {
            s+=u[i].size();
        }
        if(s<n+1)
        {
            return 0;
        }
        s=1;
        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);
            }
            else
            {
                l=x;
                r=m;
                f(1,524288,1,z);
                l=1;
                r=y;
                f(1,524288,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+=g(1,524288,1);}
                if(lll(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++;

            }
        }
        if(e==0)
        {
            if(s<n+1)
            {
               for(i=1;1;i++)
            {
                x=12904127%1923081;
            } 
            }
        }
        else
        assert(s==n+1);
        //swap(p,pp);
    }
    return 0;
    for(i=1;i<=n;i++)
    {
        if(le[i]!=ri[i])
        {
            for(i=1;1;i++)
            {
                x=12904127%1923081;
            }
            return 0;
        }
        ans[p[i].second]=p[i].first;
    }
    for(i=1;i<=n;i++)
    {
        if(ans[i]>=q+1)
        {
            printf("NIE\n");
        }
        else
            printf("%lld\n",ans[i]);
    }
    return 0;
    for(i=1;i<=n;i++)
    {
        b[i]=0;
        ans2[i]=q+1;
    }
    for(i=1;i<=q;i++)
    {
        x=upd[i].first.first;
        y=upd[i].first.second;
        z=upd[i].second;
        for(j=x;j!=y;j=j%m+1)
        {
            b[cc[j]]+=z;
        }
        b[cc[y]]+=z;
        /*for(j=1;j<=n;j++)
            printf("%lld ",b[j]);
        printf("\n");*/
        for(j=1;j<=n;j++)
        {
            if(b[j]>=a[j])
                ans2[j]=min(ans2[j],i);
        }
    }
    x=0;
    for(i=1;i<=n;i++)
    {
        if(ans2[i]>=q+1)
        {
            printf("NIE\n");
        }
        else
            printf("%lld\n",ans2[i]);
            if(ans[i]!=ans2[i])
            {
                x=1;
            }
    }
    //printf("%lld\n",x);
    if(x==1)
        return 0;
    }
}

Compilation message

met.cpp: In function 'int main()':
met.cpp:153:22: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  153 |             for(j=0;j<u[i].size();j++)
      |                     ~^~~~~~~~~~~~
met.cpp:157:26: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  157 |                 for(k=0;k<v[x].size();k++)
      |                         ~^~~~~~~~~~~~
met.cpp:166:17: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
  166 |                 else
      |                 ^~~~
met.cpp:168:21: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
  168 |                     le[x]=min(le[x],q+1);
      |                     ^~
met.cpp:243:9: warning: this 'else' clause does not guard... [-Wmisleading-indentation]
  243 |         else
      |         ^~~~
met.cpp:245:13: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'else'
  245 |             if(ans[i]!=ans2[i])
      |             ^~
met.cpp:64:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   64 |     scanf("%lld %lld",&n,&m);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~
met.cpp:77:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |         scanf("%lld",&x);
      |         ~~~~~^~~~~~~~~~~
met.cpp:86:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |         scanf("%lld",&a[i]);
      |         ~~~~~^~~~~~~~~~~~~~
met.cpp:90:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   90 |     scanf("%lld",&q);
      |     ~~~~~^~~~~~~~~~~
met.cpp:93:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   93 |         scanf("%lld %lld %lld",&x,&w,&z);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
met.cpp: In function 'void Clear()':
met.cpp:31:15: warning: iteration 1100000 invokes undefined behavior [-Waggressive-loop-optimizations]
   31 |         seg[i]=0;
      |         ~~~~~~^~
met.cpp:29:14: note: within this loop
   29 |     for(i=0;i<=1100000;i++)
      |             ~^~~~~~~~~
met.cpp:31:15: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [17600000, 17600015] is out of the bounds [0, 17600000] of object 'seg' with type 'lll [1100000]' {aka '__int128 [1100000]'} [-Warray-bounds]
   31 |         seg[i]=0;
      |         ~~~~~~^~
met.cpp:6:5: note: 'seg' declared here
    6 | lll seg[1100000],y;
      |     ^~~
met.cpp:32:16: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [8800000, 8800007] is out of the bounds [0, 8800000] of object 'lazy' with type 'll [1100000]' {aka 'long long int [1100000]'} [-Warray-bounds]
   32 |         lazy[i]=0;
      |         ~~~~~~~^~
met.cpp:5:28: note: 'lazy' declared here
    5 | ll n,e,i,j,k,x,z,w,l,r,m,q,lazy[1100000],a[330000],le[330000],ri[330000],s,ans[330000],b[330000],cc[330000],ans2[330000];
      |                            ^~~~
In function 'void Clear()',
    inlined from 'int main()' at met.cpp:74:14:
met.cpp:31:15: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [17600000, 17600015] is out of the bounds [0, 17600000] of object 'seg' with type 'lll [1100000]' {aka '__int128 [1100000]'} [-Warray-bounds]
   31 |         seg[i]=0;
      |         ~~~~~~^~
met.cpp: In function 'int main()':
met.cpp:6:5: note: 'seg' declared here
    6 | lll seg[1100000],y;
      |     ^~~
In function 'void Clear()',
    inlined from 'int main()' at met.cpp:74:14:
met.cpp:32:16: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [8800000, 8800007] is out of the bounds [0, 8800000] of object 'lazy' with type 'll [1100000]' {aka 'long long int [1100000]'} [-Warray-bounds]
   32 |         lazy[i]=0;
      |         ~~~~~~~^~
met.cpp: In function 'int main()':
met.cpp:5:28: note: 'lazy' declared here
    5 | ll n,e,i,j,k,x,z,w,l,r,m,q,lazy[1100000],a[330000],le[330000],ri[330000],s,ans[330000],b[330000],cc[330000],ans2[330000];
      |                            ^~~~
In function 'void Clear()',
    inlined from 'int main()' at met.cpp:112:14:
met.cpp:31:15: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [17600000, 17600015] is out of the bounds [0, 17600000] of object 'seg' with type 'lll [1100000]' {aka '__int128 [1100000]'} [-Warray-bounds]
   31 |         seg[i]=0;
      |         ~~~~~~^~
met.cpp: In function 'int main()':
met.cpp:6:5: note: 'seg' declared here
    6 | lll seg[1100000],y;
      |     ^~~
In function 'void Clear()',
    inlined from 'int main()' at met.cpp:112:14:
met.cpp:32:16: warning: 'void* __builtin_memset(void*, int, long unsigned int)' forming offset [8800000, 8800007] is out of the bounds [0, 8800000] of object 'lazy' with type 'll [1100000]' {aka 'long long int [1100000]'} [-Warray-bounds]
   32 |         lazy[i]=0;
      |         ~~~~~~~^~
met.cpp: In function 'int main()':
met.cpp:5:28: note: 'lazy' declared here
    5 | ll n,e,i,j,k,x,z,w,l,r,m,q,lazy[1100000],a[330000],le[330000],ri[330000],s,ans[330000],b[330000],cc[330000],ans2[330000];
      |                            ^~~~
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 55132 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 10 ms 55044 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 25 ms 59992 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 62288 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 60248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 24 ms 59972 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 137 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 122 ms 65536 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -