QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227659 | #6564. Frequent Flier | Nerovix# | WA | 271ms | 17044kb | C++20 | 2.8kb | 2023-10-27 20:51:20 | 2023-10-27 20:51:21 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 4e5 + 5;
typedef long long ll;
int n, m, k, a[MAXN];
ll len[MAXN];
inline int askLen(int l, int r) {
return len[r] - len[l - 1];
}
#define ls x << 1
#define rs x << 1 | 1
ll sum[MAXN << 2];
int t[MAXN << 2];
inline void pushr(int x, int l, int r) {
sum[x] = askLen(l, r), t[x] = 1;
}
inline void pushdown(int x, int l, int r) {
if(t[x]) {
int mid = l + r >> 1;
pushr(ls, l, mid);
pushr(rs, mid + 1, r);
t[x] = 0;
}
}
void pushup(int x) {
sum[x] = sum[ls] + sum[rs];
}
inline int ask(int x, int l, int r, int ql, int qr) {
if(ql > qr) return 0;
if(ql <= l && r <= qr) { return sum[x];}
pushdown(x, l, r);
int mid = l + r >> 1;
if(qr <= mid) return ask(ls, l, mid, ql, qr);
else if(ql > mid) return ask(rs, mid + 1, r, ql, qr);
else return ask(ls, l, mid, ql, qr) + ask(rs, mid + 1, r, ql, qr);
}
inline void push(int x, int l, int r, int ql, int qr) {
if(ql > qr) return ;
if(ql <= l && r <= qr) return pushr(x, l, r);
pushdown(x, l, r);
int mid = l + r >> 1;
if(qr <= mid) push(ls, l, mid, ql, qr);
else if(ql > mid) push(rs, mid + 1, r, ql, qr);
else push(ls, l, mid, ql, qr), push(rs, mid + 1, r, ql, qr);
pushup(x);
}
inline void add(int x, int l, int r, int p, int v) {
if(l == r) {
sum[x] += v;
return ;
}
pushdown(x, l, r);
int mid = l + r >> 1;
if(p <= mid) add(ls, l, mid, p, v);
else add(rs, mid + 1, r, p, v);
pushup(x);
}
inline void upd(int L, int R) {
// cout << L << ' ' << R << '\n';
int ans = R + 1, l = L, r = R;
while(l <= r) {
int mid = l + r >> 1;
if(askLen(mid, R) + ask(1, 1, n + m - 1, L, mid - 1) <= k) {
ans = mid, r = mid - 1;
} else l = mid + 1;
}
// cout << ans << ' ' << sum[1] << '\n';
push(1, 1, n + m - 1, ans, R);
int t = ask(1, 1, n + m - 1, L, R);
if (ans - 1 >= L) {
int p = k - ask(1, 1, n + m - 1, L, R);
// cout << ans - 1 << ' ' << p << "xxx\n";
if(p > 0) add(1, 1, n + m - 1, ans - 1, p);
}
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> m >> k;
for (int i = 1; i <= n; i++)
cin >> a[i], len[i] = len[i - 1] + a[i];
for(int i = n + 1; i <= n + m - 1; i++)
len[i] = len[i - 1];
for (int i = 1; i <= n + m - 1; i++) {
upd(max(i - m + 1, 1), i);
// for(int j = 1; j <= n; j++) {
// cout << ask(1, 1, n + m - 1, j, j) << ' ';
// }
// cout << '\n';
}
cout << sum[1] << '\n';
return 0;
}
/*
8 3 2
3
1
4
1
5
9
2
6
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5440kb
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: 271ms
memory: 17044kb
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:
89426059451133
result:
wrong answer 1st lines differ - expected: '82994275905', found: '89426059451133'