Submission #950976

#TimeUsernameProblemLanguageResultExecution timeMemory
950976VinhLuuCat Exercise (JOI23_ho_t4)C++17
41 / 100
100 ms29264 KiB
#include <bits/stdc++.h> #define int long long #define pb push_back using namespace std; const int N = 2e5 + 5; int n, a[N]; vector<int> p[N]; namespace sub3{ int st[N << 1]; int get(int l,int r){ r++; int ret = 0; for(l += n - 1, r += n - 1; l < r; l /= 2, r /= 2){ if(l & 1){ if(a[ret] < a[st[l]]) ret = st[l]; l++; } if(r & 1){ --r; if(a[ret] < a[st[r]]) ret = st[r]; } } return ret; } int dq(int l,int r){ if(l > r) return 0; int u = get(l, r); int L = (u == l ? 0 : dq(l, u - 1) + u - get(l, u - 1)); int R = (r == u ? 0 : dq(u + 1, r) + get(u + 1, r) - u); return max(L, R); } void solve(){ for(int i = 1; i <= n; i ++){ st[i + n - 1] = i; } for(int i = n - 1; i >= 1; i --){ if(a[st[i << 1]] > a[st[i << 1|1]]) st[i] = st[i << 1]; else st[i] = st[i << 1|1]; } cout << dq(1, n); } } signed main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define task "ce" if(fopen(task ".inp","r")){ freopen(task ".inp","r",stdin); freopen(task ".out","w",stdout); } cin >> n; for(int i = 1; i <= n; i ++){ cin >> a[i]; } bool ff = true; for(int i = 1; i < n; i ++){ int x, y; cin >> x >> y; if(y != x + 1) ff = false; p[x].pb(y); p[y].pb(x); } if(ff) sub3 :: solve(); }

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:51:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   51 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:52:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |         freopen(task ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#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...