QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#258791 | #6563. Four Square | tien_noob | WA | 1ms | 5796kb | C++20 | 1.9kb | 2023-11-20 10:25:11 | 2023-11-20 10:25:11 |
Judging History
answer
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 2e5;
int n, m, k;
long long a[N + 1];
stack<int> st;
struct FenwickTree
{
long long tree[N + 1];
void add(int pos, int val)
{
for (; pos <= n; pos |= pos + 1)
{
tree[pos] += val;
}
}
long long sum(int pos)
{
long long ret = 0;
for (; pos >= 0; pos = (pos & (pos + 1)) - 1)
{
ret += tree[pos];
}
return ret;
}
long long sum(int l, int r)
{
l = max(l, 0);
r = min(r, n);
return sum(r) - sum(l - 1);
}
} tree;
void read()
{
cin >> n >> m >> k;
for (int i = 1; i <= n; ++ i)
{
cin >> a[i];
}
}
void solve()
{
long long res = 0;
for (int i = 1; i <= n + m - 1; ++ i)
{
if (i <= n)
{
st.push(i);
}
while(!st.empty() && st.top() + m - 1 >= i)
{
long long s = tree.sum(i - m + 1, i);
if (s >= k)
{
break;
}
int j = st.top();
long long t = min(a[j], k - s);
a[j] -= t;
tree.add(j, t);
res += t;
if (a[j] == 0)
{
st.pop();
}
}
}
cout << res;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
if (fopen(TASK".INP", "r"))
{
freopen(TASK".INP", "r", stdin);
//freopen(TASK".OUT", "w", stdout);
}
int t = 1;
bool typetest = false;
if (typetest)
{
cin >> t;
}
for (int __ = 1; __ <= t; ++ __)
{
//cout << "Case " << __ << ": ";
read();
solve();
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5792kb
input:
1 1 1 1 1 1 1 1
output:
1
result:
ok single line: '1'
Test #2:
score: -100
Wrong Answer
time: 1ms
memory: 5796kb
input:
3 1 3 3 2 2 3 3
output:
7
result:
wrong answer 1st lines differ - expected: '0', found: '7'