제출 #533800

#제출 시각아이디문제언어결과실행 시간메모리
533800alextodoranGlobal Warming (CEOI18_glo)C++17
100 / 100
377 ms27224 KiB
/** ____ ____ ____ ____ ____ ||a |||t |||o |||d |||o || ||__|||__|||__|||__|||__|| |/__\|/__\|/__\|/__\|/__\| **/ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int N_MAX = 200000; const int T_MAX = (int) 2e9; int n, x; int t[N_MAX + 2]; int u[N_MAX + 2]; int before[N_MAX + 2], after[N_MAX + 2]; int beforeFen[N_MAX * 2 + 2], afterFen[N_MAX * 2 + 2]; void update (int Fen[], int pos, int val) { for (int i = pos; i <= n * 2; i += i & -i) { Fen[i] = max(Fen[i], val); } } int query (int Fen[], int pos) { int ret = 0; for (int i = pos; i >= 1; i -= i & -i) { ret = max(ret, Fen[i]); } return ret; } int main () { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cin >> n >> x; for (int i = 1; i <= n; i++) { cin >> t[i]; u[i] = t[i] + x; } map <int, int> mp; for (int i = 1; i <= n; i++) { mp[t[i]]; mp[u[i]]; } int curr = 0; for (pair <int, int> _ : mp) { mp[_.first] = ++curr; } for (int i = 1; i <= n; i++) { t[i] = mp[t[i]]; u[i] = mp[u[i]]; } for (int i = 1; i <= n; i++) { before[i] = query(beforeFen, t[i] - 1) + 1; after[i] = max(query(afterFen, t[i] - 1), query(beforeFen, u[i] - 1)) + 1; update(beforeFen, t[i], before[i]); update(afterFen, t[i], after[i]); } cout << query(afterFen, n * 2) << "\n"; return 0; }
#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...