Submission #653800

#TimeUsernameProblemLanguageResultExecution timeMemory
653800JuanGlobal Warming (CEOI18_glo)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #define int long long 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'; }

Compilation message (stderr)

cc1plus: error: '::main' must return 'int'