Submission #849190

#TimeUsernameProblemLanguageResultExecution timeMemory
849190quanlt206Global Warming (CEOI18_glo)C++14
0 / 100
49 ms6716 KiB
#include<bits/stdc++.h> #define X first #define Y second #define all(x) begin(x), end(x) #define FOR(i, a, b) for(int i = (a); i <= (b); i++) #define FORD(i, b, a) for(int i = (b); i >= (a); i--) #define REP(i, a, b) for (int i = (a); i < (b); i++) #define mxx max_element #define mnn min_element #define SQR(x) (1LL * (x) * (x)) #define MASK(i) (1LL << (i)) #define Point Vector #define left Left #define right Right #define div Div using namespace std; typedef long long ll; typedef unsigned long long ull; typedef double db; typedef long double ld; typedef pair<db, db> pdb; typedef pair<ld, ld> pld; typedef pair<int, int> pii; typedef pair<int, pii> piii; typedef pair<ll, ll> pll; typedef pair<ll, pll> plll; typedef pair<ll, int> pli; typedef pair<ll, pii> plii; template<class A, class B> bool maximize(A& x, B y) { if (x < y) return x = y, true; else return false; } template<class A, class B> bool minimize(A& x, B y) { if (x > y) return x = y, true; else return false; } /* END OF TEMPLATE */ const int N = 2e5 + 7; int n, d, a[N], b[N], f[N], f2[N], g[N], m, ed[N]; int chat(int x, int a[]) { int d = 1, c = m, res, g; while (d <= c) { g = (d + c) >> 1; if (a[ed[g]] < x) res = ed[g], d = g + 1; else c = g - 1; } return res; } void buildLISarray(int a[], int f[], int f2[], bool changeF2) { m = 1; ed[1] = 0; f[0] = 1; a[0] = -2e9; FOR(i, 1, n) { int j = chat(a[i], a), k = f[j] + 1; if (changeF2) f2[i] = f[chat(a[i] + d, a)] + 1; if (m < k) { m = k; ed[m] = i; } else if (a[ed[k]] > a[i]) ed[k] = i; f[i] = k; } FOR(i, 1, n) f[i]--; if (changeF2) { FOR(i, 1, n) f2[i]--; } } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin>>n>>d; FOR(i, 1, n) cin>>a[i]; buildLISarray(a, f, f2, true); FOR(i, 1, n) b[i] = a[i] + d; reverse(b + 1, b + 1 + n); buildLISarray(b, g, f2, false); reverse(g + 1, g + 1 + n); reverse(b + 1, b + 1 + n); int res = 1; FOR(i, 1, n) maximize(res, f2[i] + g[i] - 1); cout<<res; return 0; }

Compilation message (stderr)

glo.cpp: In function 'int chat(int, int*)':
glo.cpp:52:12: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   52 |     return res;
      |            ^~~
glo.cpp: In function 'void buildLISarray(int*, int*, int*, bool)':
glo.cpp:61:38: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   61 |         int j = chat(a[i], a), k = f[j] + 1;
      |                                      ^
glo.cpp:62:37: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   62 |         if (changeF2) f2[i] = f[chat(a[i] + d, a)] + 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...