제출 #654181

#제출 시각아이디문제언어결과실행 시간메모리
654181ParsaSFinancial Report (JOI21_financial)C++14
100 / 100
501 ms43252 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; ll lz[2][N << 2], mx[2][N << 2]; const ll inf = 1e18; void shift(int t, int v, int Tl, int Tr) { if (lz[t][v] == -1) return; mx[t][v] = lz[t][v]; if (Tl < Tr) { lz[t][v << 1] = lz[t][v]; lz[t][v << 1 | 1] = lz[t][v]; } lz[t][v] = -1; } void upd(int t, int l, int r, int val, int v = 1, int Tl = 1, int Tr = n) { shift(t, v, Tl, Tr); if (l > Tr || r < Tl) return; if (Tl >= l && Tr <= r) { lz[t][v] = val; shift(t, v, Tl, Tr); return; } int mid = (Tl + Tr) >> 1; upd(t, l, r, val, v << 1, Tl, mid); upd(t, l, r, val, v << 1 | 1, mid + 1, Tr); mx[t][v] = max(mx[t][v << 1], mx[t][v << 1 | 1]); } int bs(int t, int val, int v = 1, int Tl = 1, int Tr = n) { shift(t, v, Tl, Tr); if (Tl == Tr) { return Tl; } int mid = (Tl + Tr) >> 1; shift(t, v << 1, Tl, mid); shift(t, v << 1 | 1, mid + 1, Tr); if (mx[t][v << 1] >= val) return bs(t, val, v << 1, Tl, mid); return bs(t, val, v << 1 | 1, mid + 1, Tr); } int get(int t, int i, int v = 1, int Tl = 1, int Tr = n) { shift(t, v, Tl, Tr); if (i == Tl && i == Tr) return mx[t][v]; int mid = (Tl + Tr) >> 1; if (i <= mid) return get(t, i, v << 1, Tl, mid); return get(t, i, v << 1 | 1, mid + 1, Tr); } void solve() { cin >> n >> d; for (int i = 0; i < n; i++) cin >> a[i]; fill(mx[1], mx[1] + (N << 2), inf); fill(mx[0], mx[0] + (N << 2), inf); memset(lz, -1, sizeof lz); // inx, l, r, val for (int i = 0; i < n; i++) { if (i >= d) { int j = bs(0, i - d); 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; cout << i << ' ' << j << endl; for (int j = 0; j < n; j++) cout << get(1, j) << ' '; cout << endl; } int ans = 0; for (int i = 1; i <= n; i++) { if (get(1, i) < inf) { ans = i; } } cout << ans << endl; } int32_t main() { ios::sync_with_stdio(0), cin.tie(0), cout.tie(0); solve(); 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...