# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1006375 |
2024-06-23T21:55:22 Z |
juliany2 |
Fish 3 (JOI24_fish3) |
C++17 |
|
360 ms |
50268 KB |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define all(x) (x).begin(), (x).end()
struct LZ_ST {
int sz;
vector<ll> t, lz;
void init(int n) {
sz = n;
t.resize(sz * 4 + 7);
lz.resize(sz * 4 + 7);
}
inline void push(int v, int l, int r) {
if (l != r && lz[v]) {
int m = (l + r) / 2;
t[v * 2] += lz[v] * (m - l + 1);
t[v * 2 + 1] += lz[v] * (r - m);
lz[v * 2] += lz[v];
lz[v * 2 + 1] += lz[v];
}
lz[v] = 0;
}
void upd(int ql, int qr, ll x, int v, int l, int r) {
if (r < ql || l > qr)
return;
if (l >= ql && r <= qr)
t[v] += x * (r - l + 1), lz[v] += x;
else {
push(v, l, r);
int m = (l + r) / 2;
upd(ql, qr, x, v * 2, l, m);
upd(ql, qr, x, v * 2 + 1, m + 1, r);
t[v] = t[v * 2] + t[v * 2 + 1];
}
}
void upd(int ql, int qr, ll x) {
upd(ql, qr, x, 1, 1, sz);
}
ll query(int ql, int qr, int v, int l, int r) {
if (r < ql || l > qr)
return 0;
if (l >= ql && r <= qr)
return t[v];
push(v, l, r);
int m = (l + r) / 2;
return query(ql, qr, v * 2, l, m) + query(ql, qr, v * 2 + 1, m + 1, r);
}
ll query(int ql, int qr) {
return query(ql, qr, 1, 1, sz);
}
};
const int N = 3e5 + 7;
int n, q;
vector<array<int, 2>> qry[N];
ll c[N], d;
ll ans[N];
int main() {
cin.tie(0)->sync_with_stdio(false);
cin >> n >> d;
for (int i = 1; i <= n; i++)
cin >> c[i];
cin >> q;
for (int i = 1; i <= q; i++) {
int l, r;
cin >> l >> r;
qry[r].push_back({l, i});
}
LZ_ST st;
st.init(n + 1);
stack<array<ll, 2>> s;
s.push({(ll) 1e18, 1});
for (int i = 1; i <= n; i++) {
if (i > 1) {
if (c[i] >= c[i - 1]) {
ll dif = (c[i] - c[i - 1]) / d;
if (dif)
s.push({dif, i});
}
else {
ll dif = (c[i - 1] - c[i] + d - 1) / d;
while (dif) {
auto &[x, j] = s.top();
ll take = min(x, dif);
x -= take, dif -= take;
st.upd(j, i - 1, take);
if (x == 0)
s.pop();
}
}
}
for (auto &[l, idx] : qry[i]) {
ll x = c[l] - st.query(l, l) * d;
ans[idx] = (x < 0 ? -1 : st.query(l, i));
}
}
for (int i = 1; i <= q; i++)
cout << ans[i] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
9816 KB |
Output is correct |
2 |
Correct |
2 ms |
9816 KB |
Output is correct |
3 |
Correct |
2 ms |
9820 KB |
Output is correct |
4 |
Correct |
4 ms |
10076 KB |
Output is correct |
5 |
Correct |
3 ms |
10076 KB |
Output is correct |
6 |
Correct |
3 ms |
10076 KB |
Output is correct |
7 |
Correct |
3 ms |
10172 KB |
Output is correct |
8 |
Correct |
3 ms |
10076 KB |
Output is correct |
9 |
Correct |
3 ms |
10076 KB |
Output is correct |
10 |
Correct |
4 ms |
10332 KB |
Output is correct |
11 |
Correct |
3 ms |
10076 KB |
Output is correct |
12 |
Correct |
3 ms |
10332 KB |
Output is correct |
13 |
Correct |
3 ms |
10232 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
215 ms |
38684 KB |
Output is correct |
2 |
Correct |
229 ms |
37992 KB |
Output is correct |
3 |
Correct |
69 ms |
17212 KB |
Output is correct |
4 |
Correct |
141 ms |
37712 KB |
Output is correct |
5 |
Correct |
171 ms |
37716 KB |
Output is correct |
6 |
Correct |
160 ms |
37460 KB |
Output is correct |
7 |
Correct |
196 ms |
37584 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
95 ms |
21072 KB |
Output is correct |
2 |
Correct |
303 ms |
49748 KB |
Output is correct |
3 |
Correct |
291 ms |
49880 KB |
Output is correct |
4 |
Correct |
284 ms |
49748 KB |
Output is correct |
5 |
Correct |
281 ms |
49748 KB |
Output is correct |
6 |
Correct |
232 ms |
43348 KB |
Output is correct |
7 |
Correct |
253 ms |
43344 KB |
Output is correct |
8 |
Correct |
277 ms |
46676 KB |
Output is correct |
9 |
Correct |
296 ms |
46624 KB |
Output is correct |
10 |
Correct |
235 ms |
50004 KB |
Output is correct |
11 |
Correct |
194 ms |
50004 KB |
Output is correct |
12 |
Correct |
238 ms |
50260 KB |
Output is correct |
13 |
Correct |
237 ms |
50260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
185 ms |
35156 KB |
Output is correct |
2 |
Correct |
213 ms |
38740 KB |
Output is correct |
3 |
Correct |
145 ms |
22356 KB |
Output is correct |
4 |
Correct |
204 ms |
38736 KB |
Output is correct |
5 |
Correct |
306 ms |
39408 KB |
Output is correct |
6 |
Correct |
286 ms |
42072 KB |
Output is correct |
7 |
Correct |
279 ms |
37460 KB |
Output is correct |
8 |
Correct |
256 ms |
42060 KB |
Output is correct |
9 |
Correct |
191 ms |
37968 KB |
Output is correct |
10 |
Correct |
129 ms |
37716 KB |
Output is correct |
11 |
Correct |
204 ms |
38996 KB |
Output is correct |
12 |
Correct |
191 ms |
37872 KB |
Output is correct |
13 |
Correct |
281 ms |
41812 KB |
Output is correct |
14 |
Correct |
246 ms |
37712 KB |
Output is correct |
15 |
Correct |
281 ms |
41832 KB |
Output is correct |
16 |
Correct |
211 ms |
37716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
9816 KB |
Output is correct |
2 |
Correct |
2 ms |
9816 KB |
Output is correct |
3 |
Correct |
2 ms |
9820 KB |
Output is correct |
4 |
Correct |
4 ms |
10076 KB |
Output is correct |
5 |
Correct |
3 ms |
10076 KB |
Output is correct |
6 |
Correct |
3 ms |
10076 KB |
Output is correct |
7 |
Correct |
3 ms |
10172 KB |
Output is correct |
8 |
Correct |
3 ms |
10076 KB |
Output is correct |
9 |
Correct |
3 ms |
10076 KB |
Output is correct |
10 |
Correct |
4 ms |
10332 KB |
Output is correct |
11 |
Correct |
3 ms |
10076 KB |
Output is correct |
12 |
Correct |
3 ms |
10332 KB |
Output is correct |
13 |
Correct |
3 ms |
10232 KB |
Output is correct |
14 |
Correct |
215 ms |
38684 KB |
Output is correct |
15 |
Correct |
229 ms |
37992 KB |
Output is correct |
16 |
Correct |
69 ms |
17212 KB |
Output is correct |
17 |
Correct |
141 ms |
37712 KB |
Output is correct |
18 |
Correct |
171 ms |
37716 KB |
Output is correct |
19 |
Correct |
160 ms |
37460 KB |
Output is correct |
20 |
Correct |
196 ms |
37584 KB |
Output is correct |
21 |
Correct |
95 ms |
21072 KB |
Output is correct |
22 |
Correct |
303 ms |
49748 KB |
Output is correct |
23 |
Correct |
291 ms |
49880 KB |
Output is correct |
24 |
Correct |
284 ms |
49748 KB |
Output is correct |
25 |
Correct |
281 ms |
49748 KB |
Output is correct |
26 |
Correct |
232 ms |
43348 KB |
Output is correct |
27 |
Correct |
253 ms |
43344 KB |
Output is correct |
28 |
Correct |
277 ms |
46676 KB |
Output is correct |
29 |
Correct |
296 ms |
46624 KB |
Output is correct |
30 |
Correct |
235 ms |
50004 KB |
Output is correct |
31 |
Correct |
194 ms |
50004 KB |
Output is correct |
32 |
Correct |
238 ms |
50260 KB |
Output is correct |
33 |
Correct |
237 ms |
50260 KB |
Output is correct |
34 |
Correct |
185 ms |
35156 KB |
Output is correct |
35 |
Correct |
213 ms |
38740 KB |
Output is correct |
36 |
Correct |
145 ms |
22356 KB |
Output is correct |
37 |
Correct |
204 ms |
38736 KB |
Output is correct |
38 |
Correct |
306 ms |
39408 KB |
Output is correct |
39 |
Correct |
286 ms |
42072 KB |
Output is correct |
40 |
Correct |
279 ms |
37460 KB |
Output is correct |
41 |
Correct |
256 ms |
42060 KB |
Output is correct |
42 |
Correct |
191 ms |
37968 KB |
Output is correct |
43 |
Correct |
129 ms |
37716 KB |
Output is correct |
44 |
Correct |
204 ms |
38996 KB |
Output is correct |
45 |
Correct |
191 ms |
37872 KB |
Output is correct |
46 |
Correct |
281 ms |
41812 KB |
Output is correct |
47 |
Correct |
246 ms |
37712 KB |
Output is correct |
48 |
Correct |
281 ms |
41832 KB |
Output is correct |
49 |
Correct |
211 ms |
37716 KB |
Output is correct |
50 |
Correct |
360 ms |
49764 KB |
Output is correct |
51 |
Correct |
251 ms |
43360 KB |
Output is correct |
52 |
Correct |
256 ms |
46644 KB |
Output is correct |
53 |
Correct |
210 ms |
50004 KB |
Output is correct |
54 |
Correct |
253 ms |
50268 KB |
Output is correct |
55 |
Correct |
314 ms |
49756 KB |
Output is correct |
56 |
Correct |
181 ms |
45396 KB |
Output is correct |
57 |
Correct |
199 ms |
42136 KB |
Output is correct |
58 |
Correct |
207 ms |
42324 KB |
Output is correct |
59 |
Correct |
254 ms |
47700 KB |
Output is correct |
60 |
Correct |
185 ms |
45404 KB |
Output is correct |
61 |
Correct |
221 ms |
50004 KB |
Output is correct |
62 |
Correct |
209 ms |
45140 KB |
Output is correct |
63 |
Correct |
237 ms |
50000 KB |
Output is correct |
64 |
Correct |
181 ms |
45396 KB |
Output is correct |