Submission #931956

#TimeUsernameProblemLanguageResultExecution timeMemory
931956sleepntsheepStreet Lamps (APIO19_street_lamps)C++17
20 / 100
5071 ms14152 KiB
#include<stdio.h> #include<stdlib.h> #define N 300005 void f_u(int*t,int p,int k){ for(;p<N;p+=p&-p)t[p]+=k; } int f_q(int*t,int p){int z=0;for(;p;p-=p&-p)z+=t[p];return z;} int f_lb(int*t,int k){if(!k)return 0;int p=0,z=0;for(int j=1<<19;j>>=1;)if(p+j<N&&z+t[p+j]<k)z+=t[p+=j];return p+1;} int f[2][N],p[1<<20][3],pn,q[1<<20][4],qn,n,Q;char s[N],op[7]; void A(int a,int b,int t){if(a<1)a=1;if(b>n)b=n;p[pn][0]=a,p[pn][1]=b,p[pn++][2]=t;} int main(){scanf("%d%d%s",&n,&Q,s+1); for(int r=1;r<=n;++r)if(s[r]=='1'){int l=r;while(s[r]=='1')++r;A(l,r-1,0);} for(int i=1;i<=n;++i)f_u(f[s[i]&1],i,1); for(int i=1,a,b;i<=Q;++i){scanf("%s%d",op,&a); if(*op=='q'){scanf("%d",&b);q[qn][0]=a,q[qn][1]=--b,q[qn][2]=i;++qn;} else{ if(s[a]=='1') { int x=f_q(*f,a),l=f_lb(*f,x),r=f_lb(*f,x+1); A(l+1,r-1,-i);if(l+1<=a-1)A(l+1,a-1,i);if(a+1<=r-1)A(a+1,r-1,i); } else { int x=f_q(f[1],a),l=f_lb(f[1],x),r=f_lb(f[1],x+1); if(l==a-1&&a+1==r){ int X=f_q(*f,a),ll=f_lb(*f,X-1),rr=f_lb(*f,X+1);A(ll+1,a-1,-i);A(a+1,rr-1,-i);A(ll+1,rr-1,i); } else if(l==a-1) { int X=f_q(*f,a),ll=f_lb(*f,X-1); A(ll+1,a-1,-i);A(ll+1,a,i); } else if(a+1==r) { int X=f_q(*f,a),rr=f_lb(*f,X+1); A(a+1,rr-1,-i),A(a,rr-1,i); } else A(a,a,i); } f_u(f[s[a]&1],a,-1);s[a]^=1;f_u(f[s[a]&1],a,1); } } for(int i=0;0&&i<pn;++i)printf(" : %d %d %d\n",p[i][0],p[i][1],p[i][2]); //return 0; for(int i=0;i<qn;++i) { int cp=0,cn=0,z=0,aq=q[i][0],bq=q[i][1],tq=q[i][2]; for(int j=0;j<pn;++j) { int a=p[j][0],b=p[j][1],t=p[j][2]; if(a<=aq&&bq<=b&&abs(t)<=tq){ z+=t; if(t<0) { ++cn; } else { ++cp; } } } if(cn<cp)z-=tq; printf("%d\n",-z); } }

Compilation message (stderr)

street_lamps.cpp: In function 'int main()':
street_lamps.cpp:11:17: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | int main(){scanf("%d%d%s",&n,&Q,s+1);
      |            ~~~~~^~~~~~~~~~~~~~~~~~~~
street_lamps.cpp:14:32: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 | for(int i=1,a,b;i<=Q;++i){scanf("%s%d",op,&a);
      |                           ~~~~~^~~~~~~~~~~~~~
street_lamps.cpp:15:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |     if(*op=='q'){scanf("%d",&b);q[qn][0]=a,q[qn][1]=--b,q[qn][2]=i;++qn;}
      |                  ~~~~~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...