QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#117731 | #6564. Frequent Flier | cada_dia_mas_insanos# | AC ✓ | 205ms | 57912kb | C++14 | 2.4kb | 2023-07-02 01:22:37 | 2023-07-02 01:22:38 |
Judging History
answer
// I love Manuela
#include<bits/stdc++.h>
#define pb push_back
#define ll long long
using namespace std;
const ll iden = LLONG_MAX;
struct node {
node *left = nullptr, *right = nullptr;
ll val = 1e18, lazy = 0;
node() {}
};
void innit(node *now, int lo, int hi, vector<ll> &vals){
if(lo > hi) return;
if(lo == hi){
now->val = vals[lo];
return;
}
int mid = (lo+hi)>>1;
now-> left = new node();
now->right = new node();
innit(now->left,lo,mid,vals);
innit(now->right,mid+1,hi,vals);
now->val = min(now->left->val,now->right->val);
}
void push(node *v){
if(!v->lazy) return;
v->right->lazy += v->lazy;
v->right->val += v->lazy;
v->left->lazy += v->lazy;
v->left->val += v->lazy;
v->lazy = 0;
}
void update(node *v, ll low, ll high, ll l, ll r, ll value){
if(l > high || r < low || low > high) return;
if(low >= l && high <= r){
v->val += value;
v->lazy += value;
return;
}
ll mid = (low+high)>>1;
push(v);
if(l <= mid)
update(v->left,low,mid,l,r,value);
if(r > mid)
update(v->right,mid+1,high,l,r,value);
v->val = min(v->left->val,v->right->val);
}
ll query_min(node *v, ll low, ll high, ll l, ll r){
if(l > high || r < low || low > high) return iden;
if(low >= l && high <= r) return v->val;
ll mid = (low+high)>>1;
push(v);
ll v1 = query_min(v->left,low,mid,l,r);
ll v2 = query_min(v->right,mid+1,high,l,r);
return min(v1,v2);
}
int main(){
ios_base::sync_with_stdio(0),cin.tie(0);
ll n,m,k; cin >> n >> m >> k;
vector<ll> vals(n);
for(auto &va:vals)
cin >> va;
vector<ll> temp;
for(int i = 0; i < m-1;++i) temp.pb(0);
for(int i = 0; i < n;++i) temp.pb(vals[i]);
for(int i = 0; i < m-1;++i) temp.pb(0);
vals = temp;
n = vals.size();
vector<ll> sums(n);
for(int i = 0; i < n;++i){
sums[i] = vals[i];
if(i) sums[i] += sums[i-1];
}
vector<ll> imp(n);
for(int i = 0; i < n;++i){
if(i + m - 1 < n){
imp[i] = sums[i+m-1];
if(i-1 > -1) imp[i] -= sums[i-1];
} else imp[i] = LLONG_MAX;
}
node *st = new node();
ll low = 0, high = imp.size()-1;
innit(st,low,high,imp);
ll ans = 0;
for(int i = n-1;i > -1;--i){
int l = max(0LL,i-m+1);
ll mi = max(query_min(st,low,high,l,i) - k,0LL);
mi = min(mi,vals[i]);
ans += mi;
update(st,low,high,l,i,-mi);
}
cout << sums.back() - ans << '\n';
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3464kb
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: 93ms
memory: 28680kb
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: 166ms
memory: 53108kb
input:
1 200000 999959273 1255319
output:
1255319
result:
ok single line: '1255319'
Test #4:
score: 0
Accepted
time: 205ms
memory: 57912kb
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: 72ms
memory: 28016kb
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'