제출 #1260472

#제출 시각아이디문제언어결과실행 시간메모리
1260472vlomaczkCat Exercise (JOI23_ho_t4)C++20
21 / 100
11 ms2632 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> typedef long long ll; using namespace __gnu_pbds; using namespace std; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; int base = 1<<17; vector<int> t(2*base), poz(2*base); void update(int x, int val) { x+=base; t[x] = val; x/=2; while(x > 0) { t[x] = max(t[x+x], t[x+x+1]); x/=2; } } int query(int a, int b) { a += base-1; b += base+1; int ans = 0; while(a/2 != b/2) { if(a%2==0) ans = max(ans, t[a+1]); if(b%2==1) ans = max(ans, t[b-1]); a/=2; b/=2; } return ans; } int ans(int a, int b) { int val = query(a, b); int mid = poz[val]; int odp = 0; if(mid!=a) { odp = max(odp, mid-poz[query(a, mid-1)] + ans(a, mid-1)); } if(mid!=b) { odp = max(odp, poz[query(mid+1, b)]-mid + ans(mid+1, b)); } return odp; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n; cin >> n; for(int i=0; i<n; ++i) { int x; cin >> x; poz[x] = i; update(i, x); } cout << ans(0, n-1) << "\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...