#define DEBUG 0
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;
const int INF=0x3f3f3f3f;
const int N=2e5+5;
int n, q;
ll p[N], que[N], sol[N];
vector <pair <ll, int> > v;
void solve() {
for (int i=1; i<n; ++i) v.pb(mp(p[i]-p[i-1], i-1));
sort(v.begin(), v.end());
int j=0;
ll mini=0, maxi=0, curr=0;
for (int i=0; i<q; ++i) {
curr+=que[i];
mini=min(mini, curr); maxi=max(maxi, curr);
#if DEBUG
printf("i: %d, curr: %lld\n", i, curr);
#endif
while (j!=(int)v.size() && v[j].X<=maxi-mini) {
if (que[i]>0) sol[v[j].Y]+=v[j].X+mini, sol[v[j].Y+1]-=mini;
else sol[v[j].Y]+=maxi, sol[v[j].Y+1]+=v[j].X-maxi;
#if DEBUG
printf("index: %d, raz: %lld, mini: %lld, maxi: %lld\n", v[j].Y, v[j].X, mini, maxi);
#endif // DEBUG
j++;
}
}
while (j<(int)v.size()) sol[v[j].Y]+=maxi, sol[v[j++].Y+1]-=mini;
sol[0]-=mini; sol[n-1]+=maxi;
for (int i=0; i<n; ++i) printf("%lld\n", sol[i]);
}
void load() {
scanf("%d %d", &n, &q);
for (int i=0; i<n; ++i) scanf("%lld", p+i);
for (int i=0; i<q; ++i) scanf("%lld", que+i);
}
int main() {
load();
solve();
return 0;
}
Compilation message
Main.cpp: In function 'void load()':
Main.cpp:53:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
53 | scanf("%d %d", &n, &q);
| ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:54:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
54 | for (int i=0; i<n; ++i) scanf("%lld", p+i);
| ~~~~~^~~~~~~~~~~~~
Main.cpp:55:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
55 | for (int i=0; i<q; ++i) scanf("%lld", que+i);
| ~~~~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
452 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
2 ms |
360 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
312 KB |
Output is correct |
4 |
Correct |
2 ms |
460 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
452 KB |
Output is correct |
7 |
Correct |
2 ms |
460 KB |
Output is correct |
8 |
Correct |
2 ms |
460 KB |
Output is correct |
9 |
Correct |
2 ms |
348 KB |
Output is correct |
10 |
Correct |
2 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
464 KB |
Output is correct |
12 |
Correct |
1 ms |
204 KB |
Output is correct |
13 |
Correct |
1 ms |
304 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
2 ms |
360 KB |
Output is correct |
17 |
Correct |
2 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
204 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
38 ms |
3960 KB |
Output is correct |
21 |
Correct |
36 ms |
3692 KB |
Output is correct |
22 |
Correct |
34 ms |
3580 KB |
Output is correct |
23 |
Correct |
32 ms |
3524 KB |
Output is correct |
24 |
Correct |
39 ms |
4320 KB |
Output is correct |
25 |
Correct |
115 ms |
13504 KB |
Output is correct |
26 |
Correct |
114 ms |
13480 KB |
Output is correct |
27 |
Correct |
113 ms |
13124 KB |
Output is correct |
28 |
Correct |
114 ms |
13204 KB |
Output is correct |
29 |
Correct |
117 ms |
12840 KB |
Output is correct |
30 |
Correct |
106 ms |
12164 KB |
Output is correct |
31 |
Correct |
105 ms |
11560 KB |
Output is correct |
32 |
Correct |
89 ms |
11688 KB |
Output is correct |
33 |
Correct |
12 ms |
1752 KB |
Output is correct |
34 |
Correct |
126 ms |
13836 KB |
Output is correct |
35 |
Correct |
115 ms |
13388 KB |
Output is correct |
36 |
Correct |
111 ms |
13560 KB |
Output is correct |
37 |
Correct |
120 ms |
13316 KB |
Output is correct |
38 |
Correct |
116 ms |
13164 KB |
Output is correct |
39 |
Correct |
115 ms |
13352 KB |
Output is correct |
40 |
Correct |
112 ms |
13352 KB |
Output is correct |
41 |
Correct |
40 ms |
4548 KB |
Output is correct |
42 |
Correct |
102 ms |
11792 KB |
Output is correct |
43 |
Correct |
112 ms |
15076 KB |
Output is correct |
44 |
Correct |
42 ms |
4420 KB |
Output is correct |
45 |
Correct |
110 ms |
13276 KB |
Output is correct |
46 |
Correct |
119 ms |
15160 KB |
Output is correct |
47 |
Correct |
116 ms |
15400 KB |
Output is correct |
48 |
Correct |
118 ms |
15468 KB |
Output is correct |