제출 #653799

#제출 시각아이디문제언어결과실행 시간메모리
653799JuanGlobal Warming (CEOI18_glo)C++14
27 / 100
197 ms5900 KiB
#include<bits/stdc++.h> using namespace std; const int maxn = 2e5 + 5; int v[maxn], bit[2*maxn]; vector<int> ids; int n; void upd(int x, int val){ for(; x < 2*maxn; x+=x&-x) {bit[x] = max(bit[x], val);} } int mx(int x){ int rt = 0; for(; x>0; x-=x&-x) rt = max(rt, bit[x]); return rt; } int bbin(int x){ int l = 0, r = ids.size()-1, rt; while(l<=r){ int mid = (l+r)>>1; if(ids[mid] > x) r = mid-1; else if(ids[mid] < x) l = mid+1; else {rt = mid; break;} } return rt+1; } int main(){ int x; cin >> n >> x; x = -abs(x); for(int i = 0; i < n; i++){ cin >> v[i]; ids.push_back(v[i]); ids.push_back(v[i]+x); } sort(ids.begin(), ids.end()); ids.erase(unique(ids.begin(), ids.end()), ids.end()); // todas as coordenadas que importam estão comprimidas. Para acessar // a coordenada comprimida use "bbin(val)" e ela retornará o id relativo (comprimido) // 0-indexado + 1 int ans = 1; for(int i = 0; i < n; i++){ int id1 = bbin(v[i]); int id2 = bbin(v[i]+x); int sz_lis1 = mx(id1-1)+1; int sz_lis2 = mx(id2-1)+1; ans = max({ans, sz_lis1, sz_lis2}); upd(id1, sz_lis1); upd(id2, sz_lis2); } cout << ans << '\n'; }

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

glo.cpp: In function 'int bbin(int)':
glo.cpp:26:12: warning: 'rt' may be used uninitialized in this function [-Wmaybe-uninitialized]
   26 |  return rt+1;
      |            ^
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...