Submission #868946

#TimeUsernameProblemLanguageResultExecution timeMemory
868946quandlmGlobal Warming (CEOI18_glo)C++14
27 / 100
228 ms18420 KiB
#include <bits/stdc++.h> #define file(name) if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); } #define ll long long #define FOR(i, a, b) for (int i = (a); i <= (b); ++i) #define REP(i, a, b) for (int i = (a); i >= (b); --i) #define pi pair<int,int> #define ple tuple<int,int,int> #define fi first #define se second #define ii make_pair #define isz(a) ((int)a.size()) #define ALL(a) a.begin(), a.end() using namespace std; const int N = 1e6 + 10; int n, x, pref[N], suf[N]; int cnt = 0, a[N], b[N]; vector<int> values; int node[N * 4]; void reset() { FOR(i,1,4*cnt) { node[i]=0; } } void update (int id, int l, int r, int u, int val) { if (l == r) { node[id] = max(node[id], val); return; } int mid = l + r >> 1; if (u <= mid) update(id*2, l, mid, u, val); else update(id*2+1, mid+1, r, u, val); node[id] = max(node[id*2], node[id*2+1]); } int get (int id, int l, int r, int u, int v) { if (l > v || r < u || l > r || u > v) return 0; if (l >= u && r <= v) return node[id]; int mid = l + r >> 1; return max(get(id*2,l,mid,u,v),get(id*2+1,mid+1,r,u,v)); } void update (int u, int val) { update(1,1,cnt,u,val); } int get (int l, int r) { return get(1,1,cnt,l,r); } int main () { file("dynamic"); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> x; FOR(i,1,n) cin >> a[i]; FOR(i,1,n) { values.push_back(a[i]); values.push_back(a[i]+x); } sort(ALL(values)); values.resize(unique(ALL(values))-values.begin()); cnt = isz(values); FOR(i,1,n) { a[i]=lower_bound(ALL(values),a[i])-values.begin()+1; b[i]=a[i]+x; b[i]=lower_bound(ALL(values),b[i])-values.begin()+1; } REP(i,n,1) { suf[i] = get(a[i]+1, cnt) + 1; update(a[i], suf[i]); } reset(); int res = 0; FOR(i,1,n) { pref[i] = get(1, a[i] - 1) + 1; update(a[i], pref[i]); res = max(res, pref[i]); res = max(res, get(1,b[i]-1) + suf[i]); } cout << res << '\n'; }

Compilation message (stderr)

glo.cpp: In function 'void update(int, int, int, int, int)':
glo.cpp:34:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   34 |     int mid = l + r >> 1;
      |               ~~^~~
glo.cpp: In function 'int get(int, int, int, int, int)':
glo.cpp:42:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   42 |     int mid = l + r >> 1;
      |               ~~^~~
glo.cpp: In function 'int main()':
glo.cpp:2:60: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                    ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:55:5: note: in expansion of macro 'file'
   55 |     file("dynamic");
      |     ^~~~
glo.cpp:2:94: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
    2 | #define file(name)  if (fopen (name".inp", "r")) { freopen (name".inp", "r", stdin); freopen (name".out", "w", stdout); }
      |                                                                                      ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
glo.cpp:55:5: note: in expansion of macro 'file'
   55 |     file("dynamic");
      |     ^~~~
#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...