#include<bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define pb push_back
#define sz(x) (int)(x.size())
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define vi vector<int>
#define vp vector<pii>
#define vvi vector<vi>
#define ykh mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count())
#define __lg(x) 63-__builtin_clzll(x)
#define pow2(x) (1LL<<x)
void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void setio(){}
#define debug(x...)
#endif
void setIO(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
signed main(){
setio();
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
int n,Q;
cin>>n>>Q;
vector<int>x(n+1),q(Q+1);
vector<pii>temp;
for(int i=1;i<=n;i++){
cin>>x[i];
}
for(int i=1;i<=Q;i++){
cin>>q[i];
}
for(int i=0;i<=n;i++){
if(i==n){
temp.pb({1e18,i});
}
else if(i==0){
temp.pb({1e18,i});
}
else{
temp.pb({x[i+1]-x[i],i});
}
}
sort(all(temp));
debug(temp);
int cur=0,mx=0,mn=0;
int prev=0;
int l=0;
vector<int>ans(n+2);
for(int i=1;i<=Q;i++){
cur+=q[i];
if(-cur>mn){
mn=-cur;
}
if(cur>mx){
mx=cur;
}
while(l<n and temp[l].F<=mx+mn){
if(q[i]<0){
ans[temp[l].S]+=mx;
ans[temp[l].S+1]+=temp[l].F-mx;
}
else{
ans[temp[l].S+1]+=mn;
ans[temp[l].S]+=temp[l].F-mn;
}
l++;
}
}
debug(mx,mn,l);
while(l<sz(temp)){
//debug(temp[l]);
ans[temp[l].S]+=mx;
ans[temp[l].S+1]+=mn;
debug(ans);
l++;
}
for(int i=1;i<=n;i++){
cout<<ans[i]<<'\n';
}
}
/*
input:
l r
x
r=min(r,x-l)
*/
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:73:9: warning: unused variable 'prev' [-Wunused-variable]
73 | int prev=0;
| ^~~~
Main.cpp: In function 'void setIO(std::string)':
Main.cpp:42:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:43:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
43 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
520 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
456 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 |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
524 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 |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
520 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
1 ms |
344 KB |
Output is correct |
9 |
Correct |
1 ms |
344 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 |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
456 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 |
468 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
524 KB |
Output is correct |
20 |
Correct |
24 ms |
3932 KB |
Output is correct |
21 |
Correct |
18 ms |
3932 KB |
Output is correct |
22 |
Correct |
17 ms |
3676 KB |
Output is correct |
23 |
Correct |
17 ms |
3668 KB |
Output is correct |
24 |
Correct |
19 ms |
4316 KB |
Output is correct |
25 |
Correct |
62 ms |
13516 KB |
Output is correct |
26 |
Correct |
63 ms |
14288 KB |
Output is correct |
27 |
Correct |
64 ms |
13260 KB |
Output is correct |
28 |
Correct |
70 ms |
13428 KB |
Output is correct |
29 |
Correct |
63 ms |
13260 KB |
Output is correct |
30 |
Correct |
65 ms |
12120 KB |
Output is correct |
31 |
Correct |
58 ms |
11604 KB |
Output is correct |
32 |
Correct |
46 ms |
11976 KB |
Output is correct |
33 |
Correct |
7 ms |
1760 KB |
Output is correct |
34 |
Correct |
63 ms |
14792 KB |
Output is correct |
35 |
Correct |
65 ms |
14272 KB |
Output is correct |
36 |
Correct |
67 ms |
14276 KB |
Output is correct |
37 |
Correct |
67 ms |
14024 KB |
Output is correct |
38 |
Correct |
63 ms |
13508 KB |
Output is correct |
39 |
Correct |
67 ms |
14052 KB |
Output is correct |
40 |
Correct |
62 ms |
13248 KB |
Output is correct |
41 |
Correct |
22 ms |
4688 KB |
Output is correct |
42 |
Correct |
55 ms |
12568 KB |
Output is correct |
43 |
Correct |
70 ms |
15600 KB |
Output is correct |
44 |
Correct |
19 ms |
4436 KB |
Output is correct |
45 |
Correct |
60 ms |
13324 KB |
Output is correct |
46 |
Correct |
57 ms |
15044 KB |
Output is correct |
47 |
Correct |
60 ms |
16276 KB |
Output is correct |
48 |
Correct |
62 ms |
15456 KB |
Output is correct |