제출 #104953

#제출 시각아이디문제언어결과실행 시간메모리
104953eriksuenderhaufGlobal Warming (CEOI18_glo)C++11
100 / 100
91 ms4800 KiB
//#pragma GCC optimize("O3") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define enl printf("\n") #define case(t) printf("Case #%d: ", (t)) #define ni(n) scanf("%d", &(n)) #define nl(n) scanf("%I64d", &(n)) #define nai(a, n) for (int i = 0; i < (n); i++) ni(a[i]) #define nal(a, n) for (int i = 0; i < (n); i++) nl(a[i]) #define pri(n) printf("%d\n", (n)) #define prl(n) printf("%I64d\n", (n)) #define pii pair<int, int> #define pll pair<long long, long long> #define vii vector<pii> #define vi vector<int> #define pb push_back #define mp make_pair #define fi first #define se second using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef cc_hash_table<int,int,hash<int>> ht; const int INF = 1e9 + 7; const int MAXN = 2e5 + 5; const double eps = 1e-9; int a[MAXN], dp[MAXN], len[MAXN]; int main() { int n, x; ni(n), ni(x); int ans = 0; for (int i = 1; i <= n; i++) { ni(a[i]); int lo = 0, hi = ans, nx = 0, nx2 = 0; while (lo <= hi) { int m = (lo + hi) / 2; if (a[dp[m]] < a[i]) lo = m + 1, nx = m; else hi = m - 1; } lo = 0, hi = ans; while (lo <= hi) { int m = (lo + hi) / 2; if (a[dp[m]] < a[i] + x) lo = m + 1, nx2 = m; else hi = m - 1; } ans = max(ans, nx + 1); len[i] = nx2; if (dp[nx + 1] == 0) dp[nx + 1] = i; if (a[dp[nx + 1]] > a[i]) dp[nx + 1] = i; } a[n + 1] = INF; fill(dp, dp + MAXN, n + 1); int ret = 0; ans = 0; for (int i = n; i > 0; i--) { int lo = 0, hi = ans, nx = 0; while (lo <= hi) { int m = (lo + hi) / 2; if (a[dp[m]] > a[i]) lo = m + 1, nx = m; else hi = m - 1; } ans = max(ans, nx + 1); if (dp[nx + 1] == n + 1) dp[nx + 1] = i; if (a[dp[nx + 1]] < a[i]) dp[nx + 1] = i; ret = max(ret, nx + 1 + len[i]); } printf("%d\n", ret); return 0; }

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

glo.cpp: In function 'int main()':
glo.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     ni(n), ni(x);
          ^
glo.cpp:32:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
glo.cpp:7:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
 #define ni(n) scanf("%d", &(n))
               ~~~~~^~~~~~~~~~~~
glo.cpp:35:9: note: in expansion of macro 'ni'
         ni(a[i]);
         ^~
#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...