QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#114090 | #6564. Frequent Flier | UFRJ# | WA | 136ms | 15664kb | C++20 | 1.3kb | 2023-06-20 22:16:04 | 2023-06-20 22:16:07 |
Judging History
answer
#include "bits/stdc++.h"
using lint = int64_t;
using namespace std;
template<typename T> struct FT{
vector<T> s;
FT(int n) : s(n) {}
void update(int pos, T dif){
for(; pos < (int) s.size(); pos |= pos + 1) s[pos] += dif;
}
T query(int pos){
T res = 0 ;
for(; pos > 0; pos &= pos - 1) res += s[pos-1];
return res;
}
T query(int a, int b){ //[a, b)
return query(b) - query(a);
}
};
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
set<int> ids;
int n, m, k;
cin>>n>>m>>k;
vector<lint> cost(m-1 + n + m-1);
for(int i = m-1; i < m-1 + n; i++){
ids.insert(i);
cin>>cost[i];
}
FT<lint> ft(cost.size());
for(int i =m; i <= (int) cost.size(); i++){
lint val = ft.query(i - m, i);
while(val < k){
if(ids.empty()) break;
auto it = ids.lower_bound(i);
if(it == ids.begin()) break;
it--;
int j = *it;
lint dif = k - val;
lint cur = min(dif, cost[j]);
cost[j] -= cur;
ft.update(j, cur);
if(cost[j] == 0){
ids.erase(j);
}
val = ft.query(i - m, i);
}
}
cout<<ft.query(0, (int) cost.size())<<"\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 3444kb
input:
8 3 2 3 1 4 1 5 9 2 6
output:
8
result:
ok single line: '8'
Test #2:
score: -100
Wrong Answer
time: 136ms
memory: 15664kb
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:
99815585340157
result:
wrong answer 1st lines differ - expected: '82994275905', found: '99815585340157'