QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#111089 | #6564. Frequent Flier | KhNURE_KIVI# | AC ✓ | 204ms | 46528kb | C++23 | 4.7kb | 2023-06-05 19:49:57 | 2023-06-05 19:50:00 |
Judging History
answer
//#pragma GCC optimize("Ofast", "unroll-loops")
//#pragma GCC target("sse", "sse2", "sse3", "ssse3", "sse4")
#ifdef __APPLE__
#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstdint>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <random>
#include <deque>
#include <functional>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <complex>
#include <numeric>
#include <cassert>
#include <array>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <thread>
#else
#include <bits/stdc++.h>
#endif
#define all(a) a.begin(),a.end()
#define len(a) (int)(a.size())
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
template<typename T>
bool umin(T &a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool umax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
#if __APPLE__
#define D for (bool _FLAG = true; _FLAG; _FLAG = false)
#define LOG(...) print(#__VA_ARGS__" ::", __VA_ARGS__) << endl
template<class ...Ts>
auto &print(Ts ...ts) { return ((cerr << ts << " "), ...); }
#else
#define D while (false)
#define LOG(...)
#endif
const int max_n = 6e5 + 42, inf = 1000111222;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<typename T>
struct segment_tree {
T f[4 * max_n];
T mn[4 * max_n];
void build(int v, int l, int r) {
f[v] = 0;
if (l == r) {
mn[v] = 0;
return;
}
int mid = (l + r) / 2;
build(2 * v, l, mid);
build(2 * v + 1, mid + 1, r);
mn[v] = min(mn[2 * v], mn[2 * v + 1]);
}
void push(int v, int l, int r, int mid) {
if (f[v]) {
mn[2 * v] += f[v];
mn[2 * v + 1] += f[v];
f[2 * v] += f[v];
f[2 * v + 1] += f[v];
f[v] = 0;
}
}
void update(int v, int tl, int tr, int l, int r, T value) {
if (tl == l && tr == r) {
f[v] += value;
mn[v] += value;
return;
}
int mid = (tl + tr) / 2;
push(v, tl, tr, mid);
if (r <= mid) {
update(2 * v, tl, mid, l, r, value);
} else if (l > mid) {
update(2 * v + 1, mid + 1, tr, l, r, value);
} else {
update(2 * v, tl, mid, l, mid, value);
update(2 * v + 1, mid + 1, tr, mid + 1, r, value);
}
mn[v] = min(mn[2 * v], mn[2 * v + 1]);
}
T get_min(int v, int tl, int tr, int l, int r) {
if (tl == l && tr == r) {
return mn[v];
}
int mid = (tl + tr) / 2;
push(v, tl, tr, mid);
if (r <= mid) {
return get_min(2 * v, tl, mid, l, r);
} else if (l > mid) {
return get_min(2 * v + 1, mid + 1, tr, l, r);
}
return min(get_min(2 * v, tl, mid, l, mid), get_min(2 * v + 1, mid + 1, tr, mid + 1, r));
}
};
void solve() {
ll n, m, k;
cin >> n >> m >> k;
vector<ll> a;
for(int i = 1; i < m; i++) a.pb(0);
for(int i = 0; i < n; i++) {
int x = 1;
cin >> x;
a.pb(x);
}
for(int i = 1; i < m; i++) a.pb(0);
segment_tree<ll> st = {}; st.build(1, 0, max_n - 1);
for(int i = m - 1; i < len(a); i++) st.update(1, 0, max_n - 1, i - m + 1, i, a[i]);
// for(int i = 0; i + m - 1 < len(a); i++) cout << st.get_min(1, 0, max_n - 1, i, i) << ' ';
// cout << '\n';
for(int i = m - 1; i < len(a); i++) {
ll cr = st.get_min(1, 0, max_n - 1, i - m + 1, i);
// cout << cr << ' ';
ll have = a[i];
ll to_del = max(0ll, min(have, cr - k));
// cout << to_del << '\n';
a[i] -= to_del;
st.update(1, 0, max_n - 1, i - m + 1, i, -to_del);
// for(int i = 0; i + m - 1 < len(a); i++) cout << st.get_min(1, 0, max_n - 1, i, i) << ' ';
// cout << '\n';
}
ll ans = 0;
for(auto& x : a) {
ans += x;
// cout << x << ' ';
}
// cout << '\n';
cout << ans << '\n';
}
signed main() {
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int t = 1;
//cin >> t;
while (t--) solve();
}
/*
KIVI
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 9ms
memory: 40920kb
input:
8 3 2 3 1 4 1 5 9 2 6
output:
8
result:
ok single line: '8'
Test #2:
score: 0
Accepted
time: 114ms
memory: 42680kb
input:
200000 2467 999931035 182548858 69876218 33328350 919486767 739850600 948199964 392292320 39077742 366752074 917496841 246661698 37219034 56677740 188278971 965701828 28059790 13200243 825730775 542597589 320715170 939054378 470563899 914247467 990100491 290827128 903662394 611104879 18631185 412134...
output:
82994275905
result:
ok single line: '82994275905'
Test #3:
score: 0
Accepted
time: 130ms
memory: 46528kb
input:
1 200000 999959273 1255319
output:
1255319
result:
ok single line: '1255319'
Test #4:
score: 0
Accepted
time: 204ms
memory: 45760kb
input:
200000 118880 996878327 993340390 999483057 808153702 337349872 863222189 7495963 995920883 12950768 958082368 993215196 967152406 1388062 949959944 836952150 964071667 5291 139115263 958470154 51295691 175385 925242139 995685554 10895812 12563 55482 479983443 42805 996241239 6228013 302633329 10331...
output:
2990634981
result:
ok single line: '2990634981'
Test #5:
score: 0
Accepted
time: 91ms
memory: 42640kb
input:
200000 15 44049967 999927791 29351 999894087 687373343 518282902 19725626 452930 6701 999697321 27032796 5498 259987 999999980 485673990 805879 315651507 166801295 189865616 999910671 6203805 978801777 41916529 942904087 997589912 17146790 922137016 444882952 999884603 999926345 938979650 18597283 9...
output:
598769574112
result:
ok single line: '598769574112'