Submission #256711

#TimeUsernameProblemLanguageResultExecution timeMemory
256711daniel920712Street Lamps (APIO19_street_lamps)C++14
Compilation error
0 ms0 KiB
#include <iostream> #include <stdio.h> #include <stdlib.h> #include <set> #include <utility> using namespace std; set < pair < int , int > > how; struct A { int l,r; int nxl,nxr,nxt; int con; }Node[100000005]; int now=1; char temp[15]; char all[300005]; int Find(int x,int y,int here) { if(here<0) 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; //printf("%d %d %d %d %d %d\n",l1,r1,l2,r2,here,Node[here].nxt); if(Node[here].nxt==-2) { if(Node[here].l==l2&&Node[here].r==r2) { Node[here].con+=con; return ; } if(r2<=(Node[here].l+Node[here].r)/2) { if(Node[here].nxl==-1) { Node[here].nxl=now++; build(Node[here].l,(Node[here].l+Node[here].r)/2,-2,Node[here].nxl); } cha(l1,r1,l2,r2,con,Node[here].nxl); } else if(l2>(Node[here].l+Node[here].r)/2) { 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); } cha(l1,r1,l2,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,-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); } 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].l==l1&&Node[here].r==r1) { if(Node[here].nxt==-1) { Node[here].nxt=now++; build(0,300000,-2,Node[here].nxt); } cha(l1,r1,l2,r2,con,Node[here].nxt); return; } if(r1<=(Node[here].l+Node[here].r)/2) { if(Node[here].nxl==-1) { Node[here].nxl=now++; build(Node[here].l,(Node[here].l+Node[here].r)/2,-1,Node[here].nxl); } cha(l1,r1,l2,r2,con,Node[here].nxl); } else if(l1>(Node[here].l+Node[here].r)/2) { 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); } cha(l1,r1,l2,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); } 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,k,where,ok1=0,ok2=0,ok; scanf("%d %d",&N,&M); scanf("%s",all+1); build(0,300000,-1,0); l=1; r=0; for(i=1;i<=N;i++) { if(all[i]=='1') r=i; else { if(r>=l) { how.insert(make_pair(l,r)); cha(l,r+1,l,r+1,M,0); } l=i+1; r=i; } } if(r>=l) { how.insert(make_pair(l,r)); 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') { auto a=how.lower_bound(make_pair(where+1,where)); auto b=prev(a); r1=where; l2=where+1; if(a==how.end()||all[where+1]=='0') r2=where+1; else r2=a->second+1; if(a==how.begin()||all[where-1]=='0') l1=where; else l1=b->first; if(r2!=where+1) how.erase(a); if(l1!=where) how.erase(b); if(r2-1>=l1) how.insert(make_pair(l1,r2-1)); cha(l1,r1,l2,r2,M-i,0); } else { auto a=prev(how.lower_bound(make_pair(where+1,where))); l1=a->first; r1=where; l2=where+1; r2=a->second+1; how.erase(a); if(r1-1>=l1) how.insert(make_pair(l1,r1-1)); if(r2-1>=l2) how.insert(make_pair(l2,r2-1)); cha(l1,r1,l2,r2,i-M,0); } all[where]=(1-(all[where]-'0'))+'0'; } else { scanf("%d %d",&l,&r); ok=1; if(how.lower_bound(make_pair(l+1,r))!=how.begin()&&prev(how.lower_bound(make_pair(l+1,r)))->first<=l&&prev(how.lower_bound(make_pair(l+1,r)))->second>=r-1) ok=1; else ok=0; printf("%d\n",max(Find(l,r,0)-(M-i)*ok,0)); } } return 0; }

Compilation message (stderr)

street_lamps.cpp: In function 'void cha(int, int, int, int, int, int)':
street_lamps.cpp:51:9: warning: unused variable 't' [-Wunused-variable]
     int t;
         ^
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:147:13: warning: unused variable 't' [-Wunused-variable]
     int N,M,t,l,r,l1,r1,l2,r2,i,j,k,where,ok1=0,ok2=0,ok;
             ^
street_lamps.cpp:147:33: warning: unused variable 'j' [-Wunused-variable]
     int N,M,t,l,r,l1,r1,l2,r2,i,j,k,where,ok1=0,ok2=0,ok;
                                 ^
street_lamps.cpp:147:35: warning: unused variable 'k' [-Wunused-variable]
     int N,M,t,l,r,l1,r1,l2,r2,i,j,k,where,ok1=0,ok2=0,ok;
                                   ^
street_lamps.cpp:147:43: warning: unused variable 'ok1' [-Wunused-variable]
     int N,M,t,l,r,l1,r1,l2,r2,i,j,k,where,ok1=0,ok2=0,ok;
                                           ^~~
street_lamps.cpp:147:49: warning: unused variable 'ok2' [-Wunused-variable]
     int N,M,t,l,r,l1,r1,l2,r2,i,j,k,where,ok1=0,ok2=0,ok;
                                                 ^~~
street_lamps.cpp:148: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:149: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:175:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%s",temp);
         ~~~~~^~~~~~~~~~~
street_lamps.cpp:178:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d",&where);
             ~~~~~^~~~~~~~~~~~~
street_lamps.cpp:210:18: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d %d",&l,&r);
             ~~~~~^~~~~~~~~~~~~~~
/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-shim_facets.o): In function `void std::__facet_shims::(anonymous namespace)::__destroy_string<wchar_t>(void*)':
(.text._ZNSt13__facet_shims12_GLOBAL__N_116__destroy_stringIwEEvPv+0x1e): relocation truncated to fit: R_X86_64_32S against symbol `std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_S_empty_rep_storage' defined in .bss._ZNSbIwSt11char_traitsIwESaIwEE4_Rep20_S_empty_rep_storageE[_ZNSbIwSt11char_traitsIwESaIwEE4_Rep20_S_empty_rep_storageE] section in /usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-wstring-inst.o)
/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-shim_facets.o): In function `void std::__facet_shims::(anonymous namespace)::__destroy_string<char>(void*)':
(.text._ZNSt13__facet_shims12_GLOBAL__N_116__destroy_stringIcEEvPv+0x1e): relocation truncated to fit: R_X86_64_32S against symbol `std::string::_Rep::_S_empty_rep_storage' defined in .bss._ZNSs4_Rep20_S_empty_rep_storageE[_ZNSs4_Rep20_S_empty_rep_storageE] section in /usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-string-inst.o)
/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-shim_facets.o): In function `std::__facet_shims::(anonymous namespace)::money_get_shim<wchar_t>::do_get(std::istreambuf_iterator<wchar_t, std::char_traits<wchar_t> >, std::istreambuf_iterator<wchar_t, std::char_traits<wchar_t> >, bool, std::ios_base&, std::_Ios_Iostate&, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&) const':
(.text._ZNKSt13__facet_shims12_GLOBAL__N_114money_get_shimIwE6do_getESt19istreambuf_iteratorIwSt11char_traitsIwEES6_bRSt8ios_baseRSt12_Ios_IostateRSbIwS5_SaIwEE+0xfe): relocation truncated to fit: R_X86_64_32S against symbol `std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_S_empty_rep_storage' defined in .bss._ZNSbIwSt11char_traitsIwESaIwEE4_Rep20_S_empty_rep_storageE[_ZNSbIwSt11char_traitsIwESaIwEE4_Rep20_S_empty_rep_storageE] section in /usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-wstring-inst.o)
/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-shim_facets.o): In function `std::__facet_shims::(anonymous namespace)::money_get_shim<wchar_t>::do_get(std::istreambuf_iterator<wchar_t, std::char_traits<wchar_t> >, std::istreambuf_iterator<wchar_t, std::char_traits<wchar_t> >, bool, std::ios_base&, std::_Ios_Iostate&, std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >&) const':
(.text._ZNKSt13__facet_shims12_GLOBAL__N_114money_get_shimIwE6do_getESt19istreambuf_iteratorIwSt11char_traitsIwEES6_bRSt8ios_baseRSt12_Ios_IostateRSbIwS5_SaIwEE+0x17b): relocation truncated to fit: R_X86_64_32S against symbol `std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_S_empty_rep_storage' defined in .bss._ZNSbIwSt11char_traitsIwESaIwEE4_Rep20_S_empty_rep_storageE[_ZNSbIwSt11char_traitsIwESaIwEE4_Rep20_S_empty_rep_storageE] section in /usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-wstring-inst.o)
/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-shim_facets.o): In function `std::__facet_shims::(anonymous namespace)::money_get_shim<char>::do_get(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> >, bool, std::ios_base&, std::_Ios_Iostate&, std::string&) const':
(.text._ZNKSt13__facet_shims12_GLOBAL__N_114money_get_shimIcE6do_getESt19istreambuf_iteratorIcSt11char_traitsIcEES6_bRSt8ios_baseRSt12_Ios_IostateRSs+0xfe): relocation truncated to fit: R_X86_64_32S against symbol `std::string::_Rep::_S_empty_rep_storage' defined in .bss._ZNSs4_Rep20_S_empty_rep_storageE[_ZNSs4_Rep20_S_empty_rep_storageE] section in /usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-string-inst.o)
/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-shim_facets.o): In function `std::__facet_shims::(anonymous namespace)::money_get_shim<char>::do_get(std::istreambuf_iterator<char, std::char_traits<char> >, std::istreambuf_iterator<char, std::char_traits<char> >, bool, std::ios_base&, std::_Ios_Iostate&, std::string&) const':
(.text._ZNKSt13__facet_shims12_GLOBAL__N_114money_get_shimIcE6do_getESt19istreambuf_iteratorIcSt11char_traitsIcEES6_bRSt8ios_baseRSt12_Ios_IostateRSs+0x17b): relocation truncated to fit: R_X86_64_32S against symbol `std::string::_Rep::_S_empty_rep_storage' defined in .bss._ZNSs4_Rep20_S_empty_rep_storageE[_ZNSs4_Rep20_S_empty_rep_storageE] section in /usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-string-inst.o)
/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-shim_facets.o): In function `void std::__facet_shims::__numpunct_fill_cache<char>(std::integral_constant<bool, false>, std::locale::facet const*, std::__numpunct_cache<char>*)':
(.text._ZNSt13__facet_shims21__numpunct_fill_cacheIcEEvSt17integral_constantIbLb0EEPKNSt6locale5facetEPSt16__numpunct_cacheIT_E[_ZNSt13__facet_shims21__numpunct_fill_cacheIcEEvSt17integral_constantIbLb0EEPKNSt6locale5facetEPSt16__numpunct_cacheIT_E]+0xa1): relocation truncated to fit: R_X86_64_32S against symbol `std::string::_Rep::_S_empty_rep_storage' defined in .bss._ZNSs4_Rep20_S_empty_rep_storageE[_ZNSs4_Rep20_S_empty_rep_storageE] section in /usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-string-inst.o)
/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-shim_facets.o): In function `void std::__facet_shims::__numpunct_fill_cache<char>(std::integral_constant<bool, false>, std::locale::facet const*, std::__numpunct_cache<char>*)':
(.text._ZNSt13__facet_shims21__numpunct_fill_cacheIcEEvSt17integral_constantIbLb0EEPKNSt6locale5facetEPSt16__numpunct_cacheIT_E[_ZNSt13__facet_shims21__numpunct_fill_cacheIcEEvSt17integral_constantIbLb0EEPKNSt6locale5facetEPSt16__numpunct_cacheIT_E]+0x24f): relocation truncated to fit: R_X86_64_32S against symbol `std::string::_Rep::_S_empty_rep_storage' defined in .bss._ZNSs4_Rep20_S_empty_rep_storageE[_ZNSs4_Rep20_S_empty_rep_storageE] section in /usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-string-inst.o)
/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-shim_facets.o): In function `void std::__facet_shims::__numpunct_fill_cache<wchar_t>(std::integral_constant<bool, false>, std::locale::facet const*, std::__numpunct_cache<wchar_t>*)':
(.text._ZNSt13__facet_shims21__numpunct_fill_cacheIwEEvSt17integral_constantIbLb0EEPKNSt6locale5facetEPSt16__numpunct_cacheIT_E[_ZNSt13__facet_shims21__numpunct_fill_cacheIwEEvSt17integral_constantIbLb0EEPKNSt6locale5facetEPSt16__numpunct_cacheIT_E]+0xa9): relocation truncated to fit: R_X86_64_32S against symbol `std::string::_Rep::_S_empty_rep_storage' defined in .bss._ZNSs4_Rep20_S_empty_rep_storageE[_ZNSs4_Rep20_S_empty_rep_storageE] section in /usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-string-inst.o)
/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-shim_facets.o): In function `void std::__facet_shims::__numpunct_fill_cache<wchar_t>(std::integral_constant<bool, false>, std::locale::facet const*, std::__numpunct_cache<wchar_t>*)':
(.text._ZNSt13__facet_shims21__numpunct_fill_cacheIwEEvSt17integral_constantIbLb0EEPKNSt6locale5facetEPSt16__numpunct_cacheIT_E[_ZNSt13__facet_shims21__numpunct_fill_cacheIwEEvSt17integral_constantIbLb0EEPKNSt6locale5facetEPSt16__numpunct_cacheIT_E]+0x114): relocation truncated to fit: R_X86_64_32S against symbol `std::basic_string<wchar_t, std::char_traits<wchar_t>, std::allocator<wchar_t> >::_Rep::_S_empty_rep_storage' defined in .bss._ZNSbIwSt11char_traitsIwESaIwEE4_Rep20_S_empty_rep_storageE[_ZNSbIwSt11char_traitsIwESaIwEE4_Rep20_S_empty_rep_storageE] section in /usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-wstring-inst.o)
/usr/lib/gcc/x86_64-linux-gnu/7/libstdc++.a(cow-shim_facets.o): In function `void std::__facet_shims::__numpunct_fill_cache<wchar_t>(std::integral_constant<bool, false>, std::locale::facet const*, std::__numpunct_cache<wchar_t>*)':
(.text._ZNSt13__facet_shims21__numpunct_fill_cacheIwEEvSt17integral_constantIbLb0EEPKNSt6locale5facetEPSt16__numpunct_cacheIT_E[_ZNSt13__facet_shims21__numpunct_fill_cacheIwEEvSt17integral_constantIbLb0EEPKNSt6locale5facetEPSt16__numpunct_cacheIT_E]+0x294): additional relocation overflows omitted from the output
collect2: error: ld returned 1 exit status