# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
990854 |
2024-05-31T14:06:12 Z |
Pacybwoah |
Fish 3 (JOI24_fish3) |
C++17 |
|
368 ms |
59320 KB |
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
using namespace std;
typedef long long ll;
struct node{
ll val=0,tag=0;
};
vector<ll> vec;
vector<node> seg;
void build(int l,int r,int ind){
if(l==r){
seg[ind].val=vec[l];
return;
}
int mid=(l+r)>>1;
build(l,mid,ind*2);
build(mid+1,r,ind*2+1);
seg[ind].val=seg[ind*2].val+seg[ind*2+1].val;
}
void push(int l,int r,int ind){
if(l==r) return;
int mid=(l+r)>>1;
seg[ind*2].val+=seg[ind].tag*(mid-l+1);
seg[ind*2+1].val+=seg[ind].tag*(r-mid);
seg[ind*2].tag+=seg[ind].tag;
seg[ind*2+1].tag+=seg[ind].tag;
seg[ind].tag=0;
}
void modify(int l,int r,int start,int end,ll num,int ind){
if(r<start||end<l) return;
if(start<=l&&r<=end){
seg[ind].val+=num*(r-l+1);
seg[ind].tag+=num;
return;
}
push(l,r,ind);
int mid=(l+r)>>1;
modify(l,mid,start,end,num,ind*2);
modify(mid+1,r,start,end,num,ind*2+1);
seg[ind].val=seg[ind*2].val+seg[ind*2+1].val;
}
ll query(int l,int r,int start,int end,int ind){
if(r<start||end<l) return 0;
if(start<=l&&r<=end) return seg[ind].val;
push(l,r,ind);
int mid=(l+r)>>1;
return query(l,mid,start,end,ind*2)+query(mid+1,r,start,end,ind*2+1);
}
struct rng{
int l,r;
ll lnum,rnum;
rng(int _l,int _r,ll _lnum,ll _rnum){
l=_l,r=_r,lnum=_lnum,rnum=_rnum;
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
ll d;
cin>>n>>d;
seg.resize(4*n+4);
vec.resize(n+1);
vector<ll> pre(n+1);
for(int i=1;i<=n;i++) cin>>vec[i],pre[i]=pre[i-1]+vec[i];
build(1,n,1);
vector<vector<pair<int,int>>> events(n+1);
int q;
cin>>q;
vector<ll> ans(q);
int a,b;
for(int i=0;i<q;i++){
cin>>a>>b;
events[b].push_back(make_pair(a,i));
}
vector<rng> st;
for(int i=1;i<=n;i++){
int nowl=i,nowr=i;
ll nowlnum=vec[i],nowrnum=vec[i];
while(!st.empty()){
auto [l,r,lnum,rnum]=st.back();
//cout<<l<<" "<<r<<" "<<lnum<<" "<<rnum<<"\n";
if(rnum+d<=nowlnum) break;
st.pop_back();
ll res=(rnum-nowlnum-1)/d+1;
if(rnum<=nowlnum) res=0;
modify(1,n,l,r,-d*res,1);
nowl=l;
nowlnum=lnum-d*res;
}
st.emplace_back(nowl,nowr,nowlnum,nowrnum);
for(auto &[l,id]:events[i]){
if(query(1,n,l,l,1)<0) ans[id]=-1;
else ans[id]=((pre[i]-pre[l-1])-query(1,n,l,i,1))/d;
}
}
for(auto x:ans) cout<<x<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
860 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
732 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
3 ms |
860 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
13 |
Correct |
3 ms |
808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
359 ms |
44116 KB |
Output is correct |
2 |
Correct |
337 ms |
44140 KB |
Output is correct |
3 |
Correct |
76 ms |
10248 KB |
Output is correct |
4 |
Correct |
241 ms |
43856 KB |
Output is correct |
5 |
Correct |
234 ms |
43856 KB |
Output is correct |
6 |
Correct |
276 ms |
43708 KB |
Output is correct |
7 |
Correct |
290 ms |
43604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
126 ms |
11604 KB |
Output is correct |
2 |
Correct |
320 ms |
47192 KB |
Output is correct |
3 |
Correct |
363 ms |
50516 KB |
Output is correct |
4 |
Correct |
367 ms |
50668 KB |
Output is correct |
5 |
Correct |
363 ms |
50516 KB |
Output is correct |
6 |
Correct |
314 ms |
45160 KB |
Output is correct |
7 |
Correct |
313 ms |
45140 KB |
Output is correct |
8 |
Correct |
317 ms |
47440 KB |
Output is correct |
9 |
Correct |
338 ms |
47440 KB |
Output is correct |
10 |
Correct |
270 ms |
58304 KB |
Output is correct |
11 |
Correct |
264 ms |
59316 KB |
Output is correct |
12 |
Correct |
306 ms |
51900 KB |
Output is correct |
13 |
Correct |
332 ms |
51900 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
292 ms |
38276 KB |
Output is correct |
2 |
Correct |
336 ms |
44952 KB |
Output is correct |
3 |
Correct |
222 ms |
19028 KB |
Output is correct |
4 |
Correct |
353 ms |
47212 KB |
Output is correct |
5 |
Correct |
304 ms |
46160 KB |
Output is correct |
6 |
Correct |
361 ms |
50544 KB |
Output is correct |
7 |
Correct |
289 ms |
42744 KB |
Output is correct |
8 |
Correct |
317 ms |
50512 KB |
Output is correct |
9 |
Correct |
242 ms |
44112 KB |
Output is correct |
10 |
Correct |
214 ms |
43756 KB |
Output is correct |
11 |
Correct |
346 ms |
47196 KB |
Output is correct |
12 |
Correct |
273 ms |
46420 KB |
Output is correct |
13 |
Correct |
327 ms |
50256 KB |
Output is correct |
14 |
Correct |
237 ms |
46416 KB |
Output is correct |
15 |
Correct |
327 ms |
50268 KB |
Output is correct |
16 |
Correct |
245 ms |
46164 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
3 ms |
860 KB |
Output is correct |
5 |
Correct |
2 ms |
860 KB |
Output is correct |
6 |
Correct |
2 ms |
732 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
860 KB |
Output is correct |
9 |
Correct |
2 ms |
860 KB |
Output is correct |
10 |
Correct |
3 ms |
860 KB |
Output is correct |
11 |
Correct |
2 ms |
860 KB |
Output is correct |
12 |
Correct |
2 ms |
860 KB |
Output is correct |
13 |
Correct |
3 ms |
808 KB |
Output is correct |
14 |
Correct |
359 ms |
44116 KB |
Output is correct |
15 |
Correct |
337 ms |
44140 KB |
Output is correct |
16 |
Correct |
76 ms |
10248 KB |
Output is correct |
17 |
Correct |
241 ms |
43856 KB |
Output is correct |
18 |
Correct |
234 ms |
43856 KB |
Output is correct |
19 |
Correct |
276 ms |
43708 KB |
Output is correct |
20 |
Correct |
290 ms |
43604 KB |
Output is correct |
21 |
Correct |
126 ms |
11604 KB |
Output is correct |
22 |
Correct |
320 ms |
47192 KB |
Output is correct |
23 |
Correct |
363 ms |
50516 KB |
Output is correct |
24 |
Correct |
367 ms |
50668 KB |
Output is correct |
25 |
Correct |
363 ms |
50516 KB |
Output is correct |
26 |
Correct |
314 ms |
45160 KB |
Output is correct |
27 |
Correct |
313 ms |
45140 KB |
Output is correct |
28 |
Correct |
317 ms |
47440 KB |
Output is correct |
29 |
Correct |
338 ms |
47440 KB |
Output is correct |
30 |
Correct |
270 ms |
58304 KB |
Output is correct |
31 |
Correct |
264 ms |
59316 KB |
Output is correct |
32 |
Correct |
306 ms |
51900 KB |
Output is correct |
33 |
Correct |
332 ms |
51900 KB |
Output is correct |
34 |
Correct |
292 ms |
38276 KB |
Output is correct |
35 |
Correct |
336 ms |
44952 KB |
Output is correct |
36 |
Correct |
222 ms |
19028 KB |
Output is correct |
37 |
Correct |
353 ms |
47212 KB |
Output is correct |
38 |
Correct |
304 ms |
46160 KB |
Output is correct |
39 |
Correct |
361 ms |
50544 KB |
Output is correct |
40 |
Correct |
289 ms |
42744 KB |
Output is correct |
41 |
Correct |
317 ms |
50512 KB |
Output is correct |
42 |
Correct |
242 ms |
44112 KB |
Output is correct |
43 |
Correct |
214 ms |
43756 KB |
Output is correct |
44 |
Correct |
346 ms |
47196 KB |
Output is correct |
45 |
Correct |
273 ms |
46420 KB |
Output is correct |
46 |
Correct |
327 ms |
50256 KB |
Output is correct |
47 |
Correct |
237 ms |
46416 KB |
Output is correct |
48 |
Correct |
327 ms |
50268 KB |
Output is correct |
49 |
Correct |
245 ms |
46164 KB |
Output is correct |
50 |
Correct |
353 ms |
50516 KB |
Output is correct |
51 |
Correct |
321 ms |
45140 KB |
Output is correct |
52 |
Correct |
368 ms |
47440 KB |
Output is correct |
53 |
Correct |
285 ms |
58048 KB |
Output is correct |
54 |
Correct |
361 ms |
51904 KB |
Output is correct |
55 |
Correct |
346 ms |
50512 KB |
Output is correct |
56 |
Correct |
249 ms |
46420 KB |
Output is correct |
57 |
Correct |
210 ms |
43852 KB |
Output is correct |
58 |
Correct |
217 ms |
43856 KB |
Output is correct |
59 |
Correct |
319 ms |
48300 KB |
Output is correct |
60 |
Correct |
221 ms |
46312 KB |
Output is correct |
61 |
Correct |
271 ms |
59320 KB |
Output is correct |
62 |
Correct |
311 ms |
45908 KB |
Output is correct |
63 |
Correct |
313 ms |
51908 KB |
Output is correct |
64 |
Correct |
235 ms |
46164 KB |
Output is correct |