제출 #709805

#제출 시각아이디문제언어결과실행 시간메모리
709805groshiHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
3057 ms189800 KiB
#include<iostream> #include<vector> #include<algorithm> using namespace std; const int T = 1<<20; vector<vector<int> > drzewo; int wynik[2*T]; int pot=1; int dodaj(int x,int y) { if(drzewo[x].size()==0 || drzewo[y].size()==0) return max(wynik[x],wynik[y]); int mam=drzewo[x].back(); int gdzie=lower_bound(drzewo[y].begin(),drzewo[y].end(),mam)-drzewo[y].begin(); int wynikk=max(wynik[x],wynik[y]); if(gdzie>=1) wynikk=max(wynikk,mam+drzewo[y][gdzie-1]); return wynikk; } vector<int> essa; void zapp(int x,int l,int r,int a,int b) { if(l>b || r<a) return; if(a<=l && r<=b) { essa.push_back(x); return; } int mid=(l+r)/2; zapp(x*2,l,mid,a,b); zapp(x*2+1,mid+1,r,a,b); } int zrob(int x,int y) { essa.clear(); zapp(1,pot+1,pot*2+1,x+pot,y+pot); int maxx_id=0; int wynikk=wynik[essa[0]]; for(int i=1;i<essa.size();i++) { wynikk=max(wynikk,dodaj(essa[maxx_id],essa[i])); if(drzewo[essa[i]].back()<drzewo[essa[maxx_id]].back()) maxx_id=i; } return wynikk; } int32_t main() { cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0); int n,zap,x; cin>>n>>zap; while(pot<=n) pot*=2; pot--; drzewo.resize(2*pot+2); for(int i=1;i<=n;i++) { cin>>x; drzewo[i+pot].push_back(x); } for(int i=pot;i>=1;i--) { wynik[i]=max(wynik[i*2],wynik[i*2+1]); if(drzewo[i*2].size()>0) { int jest=drzewo[i*2].back(); int gdzie=lower_bound(drzewo[i*2+1].begin(),drzewo[i*2+1].end(),jest)-drzewo[i*2+1].begin(); if(gdzie>=1) wynik[i]=max(wynik[i],jest+drzewo[i*2+1][gdzie-1]); } int l=0,r=0; while(l<drzewo[i*2].size() && r<drzewo[i*2+1].size()) { if(drzewo[i*2][l]<=drzewo[i*2+1][r]) { drzewo[i].push_back(drzewo[i*2][l]); l++; } else{ drzewo[i].push_back(drzewo[i*2+1][r]); r++; } } while(r<drzewo[i*2+1].size()) { drzewo[i].push_back(drzewo[i*2+1][r]); r++; } while(l<drzewo[i*2].size()) { drzewo[i].push_back(drzewo[i*2][l]); l++; } } while(zap--) { int x,y,z; cin>>x>>y>>z; if(zrob(x,y)>z) cout<<"0\n"; else cout<<"1\n"; } return 0; }

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

sortbooks.cpp: In function 'int zrob(int, int)':
sortbooks.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=1;i<essa.size();i++)
      |                 ~^~~~~~~~~~~~
sortbooks.cpp: In function 'int32_t main()':
sortbooks.cpp:75:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |         while(l<drzewo[i*2].size() && r<drzewo[i*2+1].size())
      |               ~^~~~~~~~~~~~~~~~~~~
sortbooks.cpp:75:40: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   75 |         while(l<drzewo[i*2].size() && r<drzewo[i*2+1].size())
      |                                       ~^~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:87:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |         while(r<drzewo[i*2+1].size())
      |               ~^~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:92:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |         while(l<drzewo[i*2].size())
      |               ~^~~~~~~~~~~~~~~~~~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...