# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
984710 |
2024-05-17T03:14:03 Z |
vjudge2 |
Fish 3 (JOI24_fish3) |
C++17 |
|
123 ms |
17324 KB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
int32_t main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, k, q;
cin >> n >> k;
vector<int> c(n+1), ac(n+1, 0), a(n+1, 0), b(n+1, 0), aff(n+1, 0);
for (int i = 1; i <= n; i++) {
cin >> c[i];
ac[i] = c[i];
}
int prv = n;
for (int i = n - 1; i >= 1; i--) {
if (ac[i] > ac[i + 1]) {
int diff = ac[i] - ac[i + 1];
diff = (diff + k - 1) / k;
a[i] += diff;
ac[i] -= diff * k;
} else {
int t = 0;
for (int j = i + 1; j <= prv; j++) t++, aff[j] = t;
prv = i;
}
}
int t = 0;
for (int j = 1; j <= prv; j++) t++, aff[j] = t;
for (int i = 1; i <= n; i++) a[i] += a[i - 1];
cin >> q;
while (q--) {
int l, r;
cin >> l >> r;
// cout << a[r] - a[l - 1] << '\n';
// cout << ((c[r] - ac[r]) / k) * (r - l + 1) << '\n';
int L = ac[l], R = ac[r];
if (aff[r] >= r - l + 1) L += (c[r] - R);
if (L < 0) cout << "-1\n";
else cout << a[r] - a[l - 1] - ((c[r] - ac[r]) / k) * min(aff[r], r - l + 1) << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
13904 KB |
Output is correct |
2 |
Correct |
94 ms |
13288 KB |
Output is correct |
3 |
Correct |
40 ms |
1308 KB |
Output is correct |
4 |
Correct |
74 ms |
12972 KB |
Output is correct |
5 |
Correct |
68 ms |
12884 KB |
Output is correct |
6 |
Correct |
79 ms |
12884 KB |
Output is correct |
7 |
Correct |
101 ms |
12768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
61 ms |
5148 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
11840 KB |
Output is correct |
2 |
Correct |
103 ms |
14236 KB |
Output is correct |
3 |
Correct |
68 ms |
4692 KB |
Output is correct |
4 |
Correct |
105 ms |
13904 KB |
Output is correct |
5 |
Correct |
109 ms |
15696 KB |
Output is correct |
6 |
Correct |
116 ms |
17236 KB |
Output is correct |
7 |
Correct |
103 ms |
14676 KB |
Output is correct |
8 |
Correct |
123 ms |
17324 KB |
Output is correct |
9 |
Correct |
78 ms |
13244 KB |
Output is correct |
10 |
Correct |
71 ms |
13012 KB |
Output is correct |
11 |
Correct |
99 ms |
13908 KB |
Output is correct |
12 |
Correct |
94 ms |
13220 KB |
Output is correct |
13 |
Correct |
108 ms |
17012 KB |
Output is correct |
14 |
Correct |
82 ms |
12968 KB |
Output is correct |
15 |
Correct |
110 ms |
17068 KB |
Output is correct |
16 |
Correct |
95 ms |
12892 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |