# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1040873 |
2024-08-01T11:16:06 Z |
Zero_OP |
Fish 3 (JOI24_fish3) |
C++14 |
|
259 ms |
61524 KB |
#include<bits/stdc++.h>
using namespace std;
const int MAX = 3e5 + 5;
#define mod __mod
#define div __div
int n, q, bad[MAX];
long long D, a[MAX], mod[MAX], div[MAX], handle[MAX], pref[MAX];
vector<pair<int, int>> queries[MAX];
long long st[MAX << 2], lazy[MAX << 2], answer[MAX];
bool applied[MAX << 2];
void apply(int id, int l, int r, long long val){
st[id] = val * (r - l + 1);
lazy[id] = val;
applied[id] = true;
}
void pushDown(int id, int l, int r, int mid){
if(applied[id]){
apply(id << 1, l, mid, lazy[id]);
apply(id << 1 | 1, mid + 1, r, lazy[id]);
applied[id] = false;
lazy[id] = 0;
}
}
void update(int id, int l, int r, int u, int v, long long val){
if(u <= l && r <= v){
apply(id, l, r, val);
}
else{
int mid = l + r >> 1;
pushDown(id, l, r, mid);
if(u <= mid) update(id << 1, l, mid, u, v, val);
if(mid < v) update(id << 1 | 1, mid + 1, r, u, v, val);
st[id] = st[id << 1] + st[id << 1 | 1];
}
}
long long query(int id, int l, int r, int u, int v){
if(v < l || u > r) return 0;
if(u <= l && r <= v) return st[id];
int mid = l + r >> 1;
pushDown(id, l, r, mid);
return query(id << 1, l, mid, u, v) + query(id << 1 | 1, mid + 1, r, u, v);
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n >> D;
for(int i = 1; i <= n; ++i) {
cin >> a[i];
mod[i] = a[i] % D;
div[i] = a[i] / D;
if(mod[i - 1] > mod[i]) bad[i] = 1;
bad[i] = bad[i - 1] + bad[i]; //mod[i - 1] > mod[i]
handle[i] = div[i] - bad[i];
pref[i] = pref[i - 1] + handle[i];
}
cin >> q;
for(int i = 0; i < q; ++i){
int l, r;
cin >> l >> r;
queries[r].push_back({l, i});
}
stack<int> s;
for(int i = 1; i <= n; ++i){
while(!s.empty() && handle[s.top()] >= handle[i]){
s.pop();
}
update(1, 1, n, (s.empty() ? 1 : s.top() + 1), i, handle[i]);
s.push(i);
for(auto [j, id] : queries[i]){
long long minHandle = query(1, 1, n, j, j);
if(bad[j] + minHandle < 0) answer[id] = -1;
else answer[id] = pref[i] - pref[j - 1] - query(1, 1, n, j, i);
}
}
for(int i = 0; i < q; ++i){
cout << answer[i] << '\n';
}
return 0;
}
Compilation message
Main.cpp: In function 'void update(int, int, int, int, int, long long int)':
Main.cpp:37:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
37 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In function 'long long int query(int, int, int, int, int)':
Main.cpp:48:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
48 | int mid = l + r >> 1;
| ~~^~~
Main.cpp: In function 'int main()':
Main.cpp:83:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
83 | for(auto [j, id] : queries[i]){
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
26972 KB |
Output is correct |
2 |
Correct |
3 ms |
26972 KB |
Output is correct |
3 |
Correct |
3 ms |
26972 KB |
Output is correct |
4 |
Correct |
4 ms |
27228 KB |
Output is correct |
5 |
Correct |
4 ms |
27228 KB |
Output is correct |
6 |
Correct |
4 ms |
27076 KB |
Output is correct |
7 |
Correct |
3 ms |
27228 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
4 ms |
27244 KB |
Output is correct |
10 |
Correct |
5 ms |
27228 KB |
Output is correct |
11 |
Correct |
4 ms |
27228 KB |
Output is correct |
12 |
Correct |
5 ms |
27192 KB |
Output is correct |
13 |
Correct |
4 ms |
27196 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
239 ms |
54716 KB |
Output is correct |
2 |
Correct |
242 ms |
53964 KB |
Output is correct |
3 |
Correct |
64 ms |
34732 KB |
Output is correct |
4 |
Correct |
180 ms |
53964 KB |
Output is correct |
5 |
Correct |
159 ms |
53696 KB |
Output is correct |
6 |
Correct |
213 ms |
53840 KB |
Output is correct |
7 |
Correct |
212 ms |
53524 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
98 ms |
38484 KB |
Output is correct |
2 |
Correct |
234 ms |
61524 KB |
Output is correct |
3 |
Correct |
238 ms |
61524 KB |
Output is correct |
4 |
Correct |
248 ms |
61520 KB |
Output is correct |
5 |
Correct |
236 ms |
61520 KB |
Output is correct |
6 |
Correct |
227 ms |
55316 KB |
Output is correct |
7 |
Correct |
238 ms |
55124 KB |
Output is correct |
8 |
Correct |
241 ms |
58244 KB |
Output is correct |
9 |
Correct |
258 ms |
58224 KB |
Output is correct |
10 |
Correct |
223 ms |
57788 KB |
Output is correct |
11 |
Correct |
225 ms |
57680 KB |
Output is correct |
12 |
Correct |
242 ms |
60236 KB |
Output is correct |
13 |
Correct |
233 ms |
60228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
212 ms |
47956 KB |
Output is correct |
2 |
Correct |
223 ms |
54864 KB |
Output is correct |
3 |
Correct |
160 ms |
42072 KB |
Output is correct |
4 |
Correct |
255 ms |
57932 KB |
Output is correct |
5 |
Correct |
233 ms |
60464 KB |
Output is correct |
6 |
Correct |
233 ms |
61268 KB |
Output is correct |
7 |
Correct |
235 ms |
53760 KB |
Output is correct |
8 |
Correct |
239 ms |
61264 KB |
Output is correct |
9 |
Correct |
187 ms |
54100 KB |
Output is correct |
10 |
Correct |
181 ms |
54092 KB |
Output is correct |
11 |
Correct |
243 ms |
57936 KB |
Output is correct |
12 |
Correct |
198 ms |
57172 KB |
Output is correct |
13 |
Correct |
245 ms |
61168 KB |
Output is correct |
14 |
Correct |
172 ms |
56932 KB |
Output is correct |
15 |
Correct |
249 ms |
61012 KB |
Output is correct |
16 |
Correct |
178 ms |
56916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
26972 KB |
Output is correct |
2 |
Correct |
3 ms |
26972 KB |
Output is correct |
3 |
Correct |
3 ms |
26972 KB |
Output is correct |
4 |
Correct |
4 ms |
27228 KB |
Output is correct |
5 |
Correct |
4 ms |
27228 KB |
Output is correct |
6 |
Correct |
4 ms |
27076 KB |
Output is correct |
7 |
Correct |
3 ms |
27228 KB |
Output is correct |
8 |
Correct |
5 ms |
27228 KB |
Output is correct |
9 |
Correct |
4 ms |
27244 KB |
Output is correct |
10 |
Correct |
5 ms |
27228 KB |
Output is correct |
11 |
Correct |
4 ms |
27228 KB |
Output is correct |
12 |
Correct |
5 ms |
27192 KB |
Output is correct |
13 |
Correct |
4 ms |
27196 KB |
Output is correct |
14 |
Correct |
239 ms |
54716 KB |
Output is correct |
15 |
Correct |
242 ms |
53964 KB |
Output is correct |
16 |
Correct |
64 ms |
34732 KB |
Output is correct |
17 |
Correct |
180 ms |
53964 KB |
Output is correct |
18 |
Correct |
159 ms |
53696 KB |
Output is correct |
19 |
Correct |
213 ms |
53840 KB |
Output is correct |
20 |
Correct |
212 ms |
53524 KB |
Output is correct |
21 |
Correct |
98 ms |
38484 KB |
Output is correct |
22 |
Correct |
234 ms |
61524 KB |
Output is correct |
23 |
Correct |
238 ms |
61524 KB |
Output is correct |
24 |
Correct |
248 ms |
61520 KB |
Output is correct |
25 |
Correct |
236 ms |
61520 KB |
Output is correct |
26 |
Correct |
227 ms |
55316 KB |
Output is correct |
27 |
Correct |
238 ms |
55124 KB |
Output is correct |
28 |
Correct |
241 ms |
58244 KB |
Output is correct |
29 |
Correct |
258 ms |
58224 KB |
Output is correct |
30 |
Correct |
223 ms |
57788 KB |
Output is correct |
31 |
Correct |
225 ms |
57680 KB |
Output is correct |
32 |
Correct |
242 ms |
60236 KB |
Output is correct |
33 |
Correct |
233 ms |
60228 KB |
Output is correct |
34 |
Correct |
212 ms |
47956 KB |
Output is correct |
35 |
Correct |
223 ms |
54864 KB |
Output is correct |
36 |
Correct |
160 ms |
42072 KB |
Output is correct |
37 |
Correct |
255 ms |
57932 KB |
Output is correct |
38 |
Correct |
233 ms |
60464 KB |
Output is correct |
39 |
Correct |
233 ms |
61268 KB |
Output is correct |
40 |
Correct |
235 ms |
53760 KB |
Output is correct |
41 |
Correct |
239 ms |
61264 KB |
Output is correct |
42 |
Correct |
187 ms |
54100 KB |
Output is correct |
43 |
Correct |
181 ms |
54092 KB |
Output is correct |
44 |
Correct |
243 ms |
57936 KB |
Output is correct |
45 |
Correct |
198 ms |
57172 KB |
Output is correct |
46 |
Correct |
245 ms |
61168 KB |
Output is correct |
47 |
Correct |
172 ms |
56932 KB |
Output is correct |
48 |
Correct |
249 ms |
61012 KB |
Output is correct |
49 |
Correct |
178 ms |
56916 KB |
Output is correct |
50 |
Correct |
259 ms |
61524 KB |
Output is correct |
51 |
Correct |
243 ms |
55120 KB |
Output is correct |
52 |
Correct |
239 ms |
58192 KB |
Output is correct |
53 |
Correct |
220 ms |
57684 KB |
Output is correct |
54 |
Correct |
235 ms |
60204 KB |
Output is correct |
55 |
Correct |
226 ms |
61340 KB |
Output is correct |
56 |
Correct |
185 ms |
57056 KB |
Output is correct |
57 |
Correct |
163 ms |
53840 KB |
Output is correct |
58 |
Correct |
163 ms |
53900 KB |
Output is correct |
59 |
Correct |
251 ms |
59184 KB |
Output is correct |
60 |
Correct |
180 ms |
56912 KB |
Output is correct |
61 |
Correct |
218 ms |
57664 KB |
Output is correct |
62 |
Correct |
230 ms |
56656 KB |
Output is correct |
63 |
Correct |
230 ms |
59992 KB |
Output is correct |
64 |
Correct |
176 ms |
56916 KB |
Output is correct |