Submission #532300

#TimeUsernameProblemLanguageResultExecution timeMemory
532300AkiYuuGlobal Warming (CEOI18_glo)C++17
100 / 100
250 ms11552 KiB
/* Problems: Author: AkiYuu */ #include <bits/stdc++.h> #define task "GROUP" #define ll long long #define ld long double #define pb push_back #define ffw(i,a,b) for (ll i = a; i <= b; i++) #define fbw(i,b,a) for (ll i = b; i >= a; i--) #define adj(v,adj,u) for (auto v : adj[u]) #define rep(i,a) for (auto i : a) #define reset(a) memset(a, 0, sizeof(a)) #define sz(a) a.size() #define all(a) a.begin(),a.end() using namespace std; void fastio(){ ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); // freopen(task".inp", "r", stdin); // freopen(task".out", "w", stdout); } const int mxn = 2e5 + 5; typedef pair<ll, ll> ii; int f[mxn]; int dp1[mxn], dp2[mxn]; int a[mxn]; int n , x; int seg[4 * mxn]; vector < ii > pos; int segID[mxn]; void upd( int id , int v ,int x, int lx, int rx){ if ( lx == rx && lx == id ) { seg[x] = v; return; } int m = (lx + rx) / 2; if ( id <= m ) upd(id,v,2*x,lx,m); else upd(id,v,2*x+1,m+1,rx); seg[x] = max(seg[2*x], seg[2*x+1]); } int getmax(int l , int r, int x, int lx, int rx){ if ( l > rx || lx > r || lx > rx || l > r) return -1e9; if ( lx >= l && rx <= r ) return seg[x]; int m = (lx + rx) >> 1; return max( getmax(l,r,2*x,lx,m), getmax(l,r,2*x+1,m+1,rx) ); } void solve(){ cin >> n >> x; ffw(i,1,n) cin >> a[i]; ffw(i,1,n) pos.pb(ii(a[i], i)); sort(all(pos)); ffw(i,0,n-1) segID[ pos[i].second ] = i + 1; int lis = 0; ffw(i,0,n+1) f[i] = -1e18; fbw(i,n,1){ int id = lower_bound(f, f + lis, -a[i]) - f; f[id] = -a[i]; dp2[i] = id + 1; upd(segID[i], dp2[i], 1, 1, n); lis = max(lis, id + 1); } lis = 0; ffw(i,0,n+1) f[i] = -1e18; ffw(i,1,n){ int id = lower_bound(f, f + lis, a[i] - x) - f; f[id] = a[i] - x; dp1[i] = id + 1; lis = max(lis, id + 1); } int res = 0; ffw(i,1,n){ upd(segID[i], -1, 1,1,n); int l = upper_bound(all(pos), ii(a[i] - x, 1000000)) - pos.begin() + 1; res = max(res, dp1[i] + getmax(l,n,1,1,n) ); } cout << res; } int main(){ fastio(); int t = 1; // cin >> t; while (t--) solve(); }

Compilation message (stderr)

glo.cpp: In function 'void solve()':
glo.cpp:69:25: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+18' to '-2147483648' [-Woverflow]
   69 |     ffw(i,0,n+1) f[i] = -1e18;
      |                         ^~~~~
glo.cpp:78:25: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+18' to '-2147483648' [-Woverflow]
   78 |     ffw(i,0,n+1) f[i] = -1e18;
      |                         ^~~~~
#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...