#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define F first
#define S second
#define FOR(i,a,b) for (auto i = (a); i <= (b); ++i)
#define NFOR(i,a,b) for(auto i = (a); i >= (b); --i)
#define all(x) (x).begin(), (x).end()
#define sz(x) lli(x.size())
#define mp(i,a) make_pair(i,a)
#define pb(a) push_back(a)
#define bit(x,b) (x&(1LL<<b))
typedef long long int lli;
typedef pair <lli,lli> ii;
typedef pair <ii,lli> iii;
typedef vector <lli> vi;
typedef tree<lli,null_type,less<lli>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
lli n,q;
lli a[200100],pos[200100];
vi sum(200100),po1(200100),ne1(200100);
vi v;
lli ans[200100];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>q;
for(lli i=0;i<n;++i)
cin>>pos[i];
for(lli i=0;i<q;++i)
{
cin>>a[i];
if(i!=0)
a[i]=a[i]+a[i-1];
}
lli po=0,ne=0;
for(lli i=0;i<q;++i)
{
if(a[i]>=0&&a[i]>=po)
{
v.pb(a[i]-po);
po=a[i];
}
else if(a[i]<0&&a[i]<=ne)
{
v.pb(a[i]-ne);
ne=a[i];
}
}
lli n1=v.size();
for(lli i=0;i<n1;++i)
{
sum[i+1]=abs(v[i]);
if(v[i]>0)
po1[i+1]=v[i];
else
ne1[i+1]=v[i];
if(i>0)
{
sum[i+1]+=sum[i];
po1[i+1]+=po1[i];
ne1[i+1]+=ne1[i];
}
}
for(lli i=1;i<n;++i)
{
lli l=pos[i]-pos[i-1];
lli it=lower_bound(sum.begin()+1,sum.begin()+v.size()+1,l)-sum.begin();
if(it==v.size()+1)
it--;
if(it-1<0)
exit(1);
ans[i-1]+=po1[it];
ans[i]+=-ne1[it];
if(v[it-1]>0)
ans[i-1]-=max(0*1LL,(v[it-1]-(l-sum[it-1])));
else
ans[i]-=max(0*1LL,(-v[it-1]-(l-sum[it-1])));
}
ans[0]+=-ne1[n1];
ans[n-1]+=po1[n1];
for(lli i=0;i<n;++i)
cout<<ans[i]<<endl;
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:70:10: warning: comparison of integer expressions of different signedness: 'lli' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
70 | if(it==v.size()+1)
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
9 ms |
5100 KB |
Output is correct |
5 |
Correct |
9 ms |
5100 KB |
Output is correct |
6 |
Correct |
8 ms |
5100 KB |
Output is correct |
7 |
Correct |
9 ms |
5100 KB |
Output is correct |
8 |
Correct |
9 ms |
5228 KB |
Output is correct |
9 |
Correct |
9 ms |
5100 KB |
Output is correct |
10 |
Correct |
9 ms |
5100 KB |
Output is correct |
11 |
Correct |
9 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
10 ms |
5100 KB |
Output is correct |
16 |
Correct |
9 ms |
5100 KB |
Output is correct |
17 |
Correct |
9 ms |
5100 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
19 |
Correct |
8 ms |
5100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
5100 KB |
Output is correct |
2 |
Correct |
4 ms |
5100 KB |
Output is correct |
3 |
Correct |
4 ms |
5100 KB |
Output is correct |
4 |
Correct |
9 ms |
5100 KB |
Output is correct |
5 |
Correct |
9 ms |
5100 KB |
Output is correct |
6 |
Correct |
8 ms |
5100 KB |
Output is correct |
7 |
Correct |
9 ms |
5100 KB |
Output is correct |
8 |
Correct |
9 ms |
5228 KB |
Output is correct |
9 |
Correct |
9 ms |
5100 KB |
Output is correct |
10 |
Correct |
9 ms |
5100 KB |
Output is correct |
11 |
Correct |
9 ms |
5100 KB |
Output is correct |
12 |
Correct |
4 ms |
5100 KB |
Output is correct |
13 |
Correct |
4 ms |
5100 KB |
Output is correct |
14 |
Correct |
4 ms |
5100 KB |
Output is correct |
15 |
Correct |
10 ms |
5100 KB |
Output is correct |
16 |
Correct |
9 ms |
5100 KB |
Output is correct |
17 |
Correct |
9 ms |
5100 KB |
Output is correct |
18 |
Correct |
4 ms |
5100 KB |
Output is correct |
19 |
Correct |
8 ms |
5100 KB |
Output is correct |
20 |
Correct |
46 ms |
11004 KB |
Output is correct |
21 |
Correct |
37 ms |
10728 KB |
Output is correct |
22 |
Correct |
37 ms |
10600 KB |
Output is correct |
23 |
Correct |
40 ms |
10472 KB |
Output is correct |
24 |
Correct |
84 ms |
10560 KB |
Output is correct |
25 |
Correct |
543 ms |
16868 KB |
Output is correct |
26 |
Correct |
542 ms |
16748 KB |
Output is correct |
27 |
Correct |
534 ms |
16484 KB |
Output is correct |
28 |
Correct |
531 ms |
16612 KB |
Output is correct |
29 |
Correct |
537 ms |
16228 KB |
Output is correct |
30 |
Correct |
525 ms |
15588 KB |
Output is correct |
31 |
Correct |
486 ms |
14820 KB |
Output is correct |
32 |
Correct |
486 ms |
14692 KB |
Output is correct |
33 |
Correct |
56 ms |
6380 KB |
Output is correct |
34 |
Correct |
520 ms |
15596 KB |
Output is correct |
35 |
Correct |
512 ms |
15216 KB |
Output is correct |
36 |
Correct |
544 ms |
16612 KB |
Output is correct |
37 |
Correct |
534 ms |
16100 KB |
Output is correct |
38 |
Correct |
541 ms |
16740 KB |
Output is correct |
39 |
Correct |
527 ms |
16612 KB |
Output is correct |
40 |
Correct |
500 ms |
16612 KB |
Output is correct |
41 |
Correct |
39 ms |
11496 KB |
Output is correct |
42 |
Correct |
483 ms |
15076 KB |
Output is correct |
43 |
Correct |
517 ms |
18276 KB |
Output is correct |
44 |
Correct |
41 ms |
11496 KB |
Output is correct |
45 |
Correct |
493 ms |
16612 KB |
Output is correct |
46 |
Correct |
511 ms |
18404 KB |
Output is correct |
47 |
Correct |
516 ms |
18148 KB |
Output is correct |
48 |
Correct |
517 ms |
18660 KB |
Output is correct |