#include "bits/stdc++.h"
#define MAXN 200009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
ll arr[MAXN],w[MAXN],par[MAXN],mx[MAXN],mn[MAXN];
PII rng[3];
const ll I=1e18;
bool intersect(PII a, PII b){
if(a.ff>b.ff)swap(a,b);
return (b.ff<=a.ss and a.ss<=b.ss);
}
PII get(int pos,int ind){
return {arr[pos]+mn[ind],arr[pos]+mx[ind]};
}
int main(){
//freopen("file.in", "r", stdin);
int n,q;
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++)
scanf("%lld",arr+i);
arr[0]=-I;
arr[n+1]=I;
for(int i=1;i<=q;i++){
scanf("%lld",w+i);
par[i]=par[i-1]+w[i];
mn[i]=min(mn[i-1],par[i]);
mx[i]=max(mx[i-1],par[i]);
}
for(int i=1;i<=n;i++){
ll A=get(i,q).ff,B=get(i,q).ss;
if(intersect(get(i-1,q), get(i,q))){
int st=1,en=q;
while(st+1<en){
int mid=(st+en)>>1;
if(intersect(get(i-1,mid), get(i,mid)))en=mid;
else st=mid;
}
if(intersect(get(i-1,st), get(i,st)))en=st;
if(w[en]<0)A=get(i-1,en).ss;
else A=get(i,en).ff;
}
if(intersect(get(i+1,q),get(i,q))){
int st=1,en=q;
while(st+1<en){
int mid=(st+en)>>1;
if(intersect(get(i+1,mid),get(i,mid)))en=mid;
else st=mid;
}
if(intersect(get(i+1,st),get(i,st)))en=st;
if(w[en]<0)B=get(i,en).ss;
else B=get(i+1,en).ff;
}
printf("%lld\n",B-A);
}
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:33:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | scanf("%d%d",&n,&q);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | scanf("%lld",arr+i);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp:39:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
39 | scanf("%lld",w+i);
| ~~~~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
584 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
536 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
444 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
584 KB |
Output is correct |
7 |
Correct |
1 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
536 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
444 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
604 KB |
Output is correct |
16 |
Correct |
1 ms |
604 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
488 KB |
Output is correct |
20 |
Correct |
20 ms |
8796 KB |
Output is correct |
21 |
Correct |
19 ms |
8416 KB |
Output is correct |
22 |
Correct |
20 ms |
8304 KB |
Output is correct |
23 |
Correct |
18 ms |
8280 KB |
Output is correct |
24 |
Correct |
27 ms |
8528 KB |
Output is correct |
25 |
Correct |
118 ms |
13396 KB |
Output is correct |
26 |
Correct |
114 ms |
13392 KB |
Output is correct |
27 |
Correct |
112 ms |
13136 KB |
Output is correct |
28 |
Correct |
109 ms |
13136 KB |
Output is correct |
29 |
Correct |
105 ms |
12628 KB |
Output is correct |
30 |
Correct |
103 ms |
12080 KB |
Output is correct |
31 |
Correct |
61 ms |
11604 KB |
Output is correct |
32 |
Correct |
52 ms |
11680 KB |
Output is correct |
33 |
Correct |
10 ms |
1624 KB |
Output is correct |
34 |
Correct |
115 ms |
13908 KB |
Output is correct |
35 |
Correct |
108 ms |
13292 KB |
Output is correct |
36 |
Correct |
109 ms |
13484 KB |
Output is correct |
37 |
Correct |
113 ms |
13212 KB |
Output is correct |
38 |
Correct |
124 ms |
13116 KB |
Output is correct |
39 |
Correct |
94 ms |
13116 KB |
Output is correct |
40 |
Correct |
69 ms |
13268 KB |
Output is correct |
41 |
Correct |
21 ms |
9300 KB |
Output is correct |
42 |
Correct |
41 ms |
11652 KB |
Output is correct |
43 |
Correct |
64 ms |
15040 KB |
Output is correct |
44 |
Correct |
21 ms |
9164 KB |
Output is correct |
45 |
Correct |
44 ms |
13168 KB |
Output is correct |
46 |
Correct |
64 ms |
15132 KB |
Output is correct |
47 |
Correct |
63 ms |
15296 KB |
Output is correct |
48 |
Correct |
80 ms |
15496 KB |
Output is correct |