제출 #256628

#제출 시각아이디문제언어결과실행 시간메모리
256628daniel920712가로등 (APIO19_street_lamps)C++14
0 / 100
966 ms524288 KiB
#include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std; struct A { int l,r; int nxl,nxr,nxt; int con; }Node[20000005]; int now=1; char temp[15]; char all[300005]; int Find(int x,int y,int here) { if(here==-1) return 0; int t; if(Node[here].nxt==-2) { t=Node[here].con; if(Node[here].l==y&&Node[here].r==y) return t; else if(y<=(Node[here].l+Node[here].r)/2) t+=Find(x,y,Node[here].nxl); else t+=Find(x,y,Node[here].nxr); } else { t=Node[here].con; t+=Find(x,y,Node[here].nxt); if(Node[here].l==x&&Node[here].r==x) return t; else if(x<=(Node[here].l+Node[here].r)/2) t+=Find(x,y,Node[here].nxl); else t+=Find(x,y,Node[here].nxr); } return t; } void build(int l,int r,int con,int here) { Node[here].l=l; Node[here].r=r; Node[here].nxt=con; Node[here].nxl=-1; Node[here].nxr=-1; Node[here].con=0; } void cha(int l1,int r1,int l2,int r2,int con,int here) { int t; if(Node[here].nxt==-2) { if(Node[here].l==l2&&Node[here].r==r2) { Node[here].con+=con; return ; } if(Node[here].nxl==-1) { Node[here].nxl=now++; build(Node[here].l,(Node[here].l+Node[here].r)/2,-2,Node[here].nxl); } if(Node[here].nxr==-1) { Node[here].nxr=now++; build((Node[here].l+Node[here].r)/2+1,Node[here].r,-2,Node[here].nxr); } if(r2<=(Node[here].l+Node[here].r)/2) cha(l1,r1,l2,r2,con,Node[here].nxl); else if(l2>(Node[here].l+Node[here].r)/2) cha(l1,r1,l2,r2,con,Node[here].nxr); else { cha(l1,r1,l2,(Node[here].l+Node[here].r)/2,con,Node[here].nxl); cha(l1,r1,(Node[here].l+Node[here].r)/2+1,r2,con,Node[here].nxr); } } else { if(Node[here].nxl==-1) { Node[here].nxl=now++; build(Node[here].l,(Node[here].l+Node[here].r)/2,-1,Node[here].nxl); } if(Node[here].nxr==-1) { Node[here].nxr=now++; build((Node[here].l+Node[here].r)/2+1,Node[here].r,-1,Node[here].nxr); } if(Node[here].nxt==-1) { Node[here].nxt=-1; build(0,300000,-2,Node[here].nxt); } if(Node[here].l==l1&&Node[here].r==r2) cha(l1,r1,l2,r2,con,Node[here].nxt); if(r1<=(Node[here].l+Node[here].r)/2) cha(l1,r1,l2,r2,con,Node[here].nxl); else if(l1>(Node[here].l+Node[here].r)/2) cha(l1,r1,l2,r2,con,Node[here].nxr); else { cha(l1,(Node[here].l+Node[here].r)/2,l2,r2,con,Node[here].nxl); cha((Node[here].l+Node[here].r)/2+1,r1,l2,r2,con,Node[here].nxr); } } } int main() { int N,M,t,l,r,l1,r1,l2,r2,i,j,where; scanf("%d %d",&N,&M); scanf("%s",all+1); build(0,300000,-1,0); for(i=0;i<N;i++) { if(all[i]=='1') { r=i; } else { if(r>=l) cha(l,r+1,l,r+1,M,0); l=i+1; r=i; } } if(r>=l) cha(l,r+1,l,r+1,M,0); for(i=1;i<=M;i++) { scanf("%s",temp); if(temp[0]=='t') { scanf("%d",&where); if(all[where]=='0') { r1=where; l1=where; for(i=where-1;i>=1;i--) { if(all[i]=='1') l1=i; else break; } l2=where+1; r2=where+1; for(i=where+1;i<=N;i--) { if(all[i]=='1') r2=i+1; else break; } cha(l1,r1,l2,r2,M-i,0); } else { r1=where; l1=where; for(i=where-1;i>=1;i--) { if(all[i]=='1') l1=i; else break; } l2=where+1; r2=where+1; for(i=where+1;i<=N;i--) { if(all[i]=='1') r2=i+1; else break; } cha(l1,r1,l2,r2,i-M,0); } } else { scanf("%d %d",&l,&r); printf("%d\n",Find(l,r,0)-(M-i)); } } return 0; }

컴파일 시 표준 에러 (stderr) 메시지

street_lamps.cpp: In function 'void cha(int, int, int, int, int, int)':
street_lamps.cpp:48:9: warning: unused variable 't' [-Wunused-variable]
     int t;
         ^
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:105:13: warning: unused variable 't' [-Wunused-variable]
     int N,M,t,l,r,l1,r1,l2,r2,i,j,where;
             ^
street_lamps.cpp:105:33: warning: unused variable 'j' [-Wunused-variable]
     int N,M,t,l,r,l1,r1,l2,r2,i,j,where;
                                 ^
street_lamps.cpp:106:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %d",&N,&M);
     ~~~~~^~~~~~~~~~~~~~~
street_lamps.cpp:107:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%s",all+1);
     ~~~~~^~~~~~~~~~~~
street_lamps.cpp:129:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s",temp);
         ~~~~~^~~~~~~~~~~
street_lamps.cpp:133:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&where);
             ~~~~~^~~~~~~~~~~~~
street_lamps.cpp:180:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d",&l,&r);
             ~~~~~^~~~~~~~~~~~~~~
street_lamps.cpp: In function 'void cha(int, int, int, int, int, int)':
street_lamps.cpp:39:14: warning: array subscript is below array bounds [-Warray-bounds]
     Node[here].l=l;
     ~~~~~~~~~^
street_lamps.cpp:40:14: warning: array subscript is below array bounds [-Warray-bounds]
     Node[here].r=r;
     ~~~~~~~~~^
street_lamps.cpp:41:14: warning: array subscript is below array bounds [-Warray-bounds]
     Node[here].nxt=con;
     ~~~~~~~~~^
street_lamps.cpp:42:14: warning: array subscript is below array bounds [-Warray-bounds]
     Node[here].nxl=-1;
     ~~~~~~~~~^
street_lamps.cpp:43:14: warning: array subscript is below array bounds [-Warray-bounds]
     Node[here].nxr=-1;
     ~~~~~~~~~^
street_lamps.cpp:44:14: warning: array subscript is below array bounds [-Warray-bounds]
     Node[here].con=0;
     ~~~~~~~~~^
#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...