제출 #654167

#제출 시각아이디문제언어결과실행 시간메모리
654167ParsaSFinancial Report (JOI21_financial)C++14
60 / 100
37 ms5084 KiB
// In the name of God #include<bits/stdc++.h> using namespace std; #define pb push_back #define fi first #define se second typedef long long ll; #define int ll const int N = 3e5 + 5; int n, a[N], d; const ll inf = 1e18; ll arr[2][N]; void upd(int t, int l, int r, int val) { for (int i = l; i <= r; i++) arr[t][i] = val; } int bs(int t, int val) { for (int i = 1; i < N; i++) { if (arr[t][i] >= val) return i; } } int get(int t, int i) { return arr[t][i]; } void solve() { cin >> n >> d; for (int i = 0; i < n; i++) cin >> a[i]; if (n > 7000) return; fill(arr[1], arr[1] + N, inf); fill(arr[0], arr[0] + N, inf); // inx, l, r, val for (int i = 0; i < n; i++) { if (i >= d) { int j = bs(0, i - d); //cout << "bs " << j << endl; upd(0, 1, j - 1, get(0, j)); upd(1, 1, j - 1, get(1, j)); } int j = bs(1, a[i]); upd(0, j, n, i); upd(1, j, j, a[i]); continue; for (int j = 1; j < n; j++) cout << arr[1][j] << ' '; cout << endl; } int ans = 0; for (int i = 1; i <= n; i++) { if (get(1, i) < inf) { ans = i; } } cout << ans << endl; } void solve2() { if (n <= 7000) return; int ans = 0; stack<int> st; for (int i = n - 1; i >= 0; i--) { while (!st.empty() && a[st.top()] <= a[i]) { st.pop(); } st.push(i); ans = max(ans, (int)st.size()); } cout << ans << endl; } int32_t main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); solve(); solve2(); return 0; }

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

Main.cpp: In function 'll bs(ll, ll)':
Main.cpp:23:1: warning: control reaches end of non-void function [-Wreturn-type]
   23 | }
      | ^
#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...