제출 #1179737

#제출 시각아이디문제언어결과실행 시간메모리
1179737Szymon_PilipczukGrowing Vegetables is Fun 4 (JOI21_ho_t1)C++20
0 / 100
1096 ms328 KiB
#include <bits/stdc++.h> int n; using namespace std; int tr[400000]; void add(int l,int r) { l+=n; r+=n; tr[l]++; if(l!=r)tr[r]++; while(l/2 != r/2) { if(l%2 == 0)tr[l+1]++; if(r%2 == 1)tr[r-1]++; l/=2;r/=2; } } int check(int p) { p+=n; int ans = 0; while(p > 0) { ans+=tr[p]; p/=2; } return ans; } int main() { cin>>n; int a[n]; for(int i =0 ;i<n;i++) { cin>>a[i]; tr[i+n] = a[i]; } int ans = 0; int i = 1; int j = n-2; while(i <=j) { if(check(i-1) < check(i)) { i++; continue; } if(check(j+1) < check(j)) { j--; continue; } add(i,j); ans++; } if(check(i) == check(j)) { ans++; } cout<<ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...