# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
534334 |
2022-03-08T05:07:47 Z |
Biaz |
Snowball (JOI21_ho_t2) |
C++17 |
|
341 ms |
18452 KB |
#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define fi first
#define se second
#define X first
#define Y second
#define ist insert
#define pii pair<int,int>
typedef long long ll;
//typedef pair<int,int> pii;
using namespace std;
int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}
const int INF=1700000000000000000;//2147483647;
const int MOD=998244353;//1000000007;
const int N=200005;
struct BIT{
int n;
vector<int> bit;
void init(int _n){
n=_n;
bit.resize(n+5,0);
}
void add(int i,int v){
while (i<=n){
bit[i]+=v;
i+=(i&-i);
}
}
int que(int i){
int res=0;
while (i>0){
res+=bit[i];
i-=(i&-i);
}
return res;
}
};
int n,Q;
int a[N],w[N],res[N];
pii d[N];
int mxL,mxR;
int search(int val){
int l=1,r=n+1,res=0;
while (r>=l){
int mid=(l+r)/2;
if (d[mid].fi>=val){
res=mid;
l=mid+1;
}
else r=mid-1;
}
return res;
}
void sol(){
cin >>n>>Q;
for (int i=1;i<=n;i++)
cin >>a[i];
a[0]=-INF;a[n+1]=INF;
for (int i=1;i<=Q;i++)
cin >>w[i];
BIT tr[2];tr[0].init(n+5);tr[1].init(n+5);
for (int i=1;i<=n+1;i++)
d[i].fi=a[i]-a[i-1],d[i].se=i;
sort(d+1,d+n+2,greater<pii>());
/*for (int i=1;i<=n+1;i++)
cout <<d[i].se<<' ';
cout <<"\n";*/
int cur=0,r=n+1;
mxL=mxR=0;
for (int xx=1;xx<=Q;xx++){
cur+=w[xx];
if (mxL<=cur&&cur<=mxR) continue;
if (cur>0){
int loc=search(cur-mxL);
//cout <<loc<<'\n';
tr[1].add(1,cur-mxR);
tr[1].add(loc+1,mxR-cur);
while (d[r].fi<cur-mxL){
tr[1].add(r,d[r].fi-(mxR-mxL));
tr[1].add(r+1,-(d[r].fi-(mxR-mxL)));
r--;
}
}
if (cur<0){
int loc=search(mxR-cur);
//cout <<loc<<'\n';
tr[0].add(1,mxL-cur);
tr[0].add(loc+1,cur-mxL);
while (d[r].fi<mxR-cur){
tr[0].add(r,d[r].fi-(mxR-mxL));
tr[0].add(r+1,-(d[r].fi-(mxR-mxL)));
r--;
}
}
mxL=min(mxL,cur);
mxR=max(mxR,cur);
/*for (int i=0;i<=n+2;i++)
cout <<tr[1].que(i)<<' ';
cout <<"\n";
for (int i=0;i<=n+2;i++)
cout <<tr[0].que(i)<<' ';
cout <<"\n";*/
}
for (int i=1;i<=n+1;i++)
res[d[i].se]+=tr[0].que(i);
for (int i=1;i<=n+1;i++)
res[d[i].se-1]+=tr[1].que(i);
for (int i=1;i<=n;i++)
cout <<res[i]<<'\n';
}
/*
4 3
-2 3 5 8
2
-4
7
*/
signed main()
{
int _=1;
//cin >>_;
while (_--) sol();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
3 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
332 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
3 ms |
332 KB |
Output is correct |
17 |
Correct |
3 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
2 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
2 ms |
332 KB |
Output is correct |
5 |
Correct |
3 ms |
332 KB |
Output is correct |
6 |
Correct |
3 ms |
332 KB |
Output is correct |
7 |
Correct |
4 ms |
332 KB |
Output is correct |
8 |
Correct |
4 ms |
332 KB |
Output is correct |
9 |
Correct |
3 ms |
332 KB |
Output is correct |
10 |
Correct |
2 ms |
332 KB |
Output is correct |
11 |
Correct |
2 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
204 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
3 ms |
332 KB |
Output is correct |
16 |
Correct |
3 ms |
332 KB |
Output is correct |
17 |
Correct |
3 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
204 KB |
Output is correct |
19 |
Correct |
2 ms |
332 KB |
Output is correct |
20 |
Correct |
91 ms |
1860 KB |
Output is correct |
21 |
Correct |
94 ms |
1780 KB |
Output is correct |
22 |
Correct |
80 ms |
1784 KB |
Output is correct |
23 |
Correct |
82 ms |
1944 KB |
Output is correct |
24 |
Correct |
87 ms |
2884 KB |
Output is correct |
25 |
Correct |
299 ms |
12740 KB |
Output is correct |
26 |
Correct |
228 ms |
12760 KB |
Output is correct |
27 |
Correct |
219 ms |
12544 KB |
Output is correct |
28 |
Correct |
240 ms |
12624 KB |
Output is correct |
29 |
Correct |
232 ms |
12380 KB |
Output is correct |
30 |
Correct |
237 ms |
12012 KB |
Output is correct |
31 |
Correct |
187 ms |
11628 KB |
Output is correct |
32 |
Correct |
182 ms |
11536 KB |
Output is correct |
33 |
Correct |
25 ms |
1484 KB |
Output is correct |
34 |
Correct |
214 ms |
12784 KB |
Output is correct |
35 |
Correct |
255 ms |
12596 KB |
Output is correct |
36 |
Correct |
228 ms |
12772 KB |
Output is correct |
37 |
Correct |
261 ms |
12632 KB |
Output is correct |
38 |
Correct |
221 ms |
12568 KB |
Output is correct |
39 |
Correct |
225 ms |
12516 KB |
Output is correct |
40 |
Correct |
233 ms |
12628 KB |
Output is correct |
41 |
Correct |
107 ms |
1732 KB |
Output is correct |
42 |
Correct |
172 ms |
14740 KB |
Output is correct |
43 |
Correct |
283 ms |
17972 KB |
Output is correct |
44 |
Correct |
109 ms |
4420 KB |
Output is correct |
45 |
Correct |
226 ms |
16224 KB |
Output is correct |
46 |
Correct |
288 ms |
18136 KB |
Output is correct |
47 |
Correct |
311 ms |
18372 KB |
Output is correct |
48 |
Correct |
341 ms |
18452 KB |
Output is correct |