#include <bits/stdc++.h>
#define lp(i,a,b) for(int i = a ; i < b; i++)
#define ll long long
#define all(x) x.begin(),x.end()
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define sz(x) (int)(x.size())
#define ff first
#define ss second
const int MAXN = 2e5+10 ;
using namespace std ;
int N , Q ;
ll L[MAXN] , R[MAXN] ;
ll X[MAXN] ;
vector< pair<ll,int> > pref , suf ;
int main()
{
scanf("%d %d", &N , &Q ) ;
for(int i = 1 ; i <= N ; i++ ) scanf("%lld", &X[i] ) ;
ll t = 0 ;
pref.pb(mk(0,0)) ;
suf.pb(mk(0,0)) ;
for(int i = 1 ; i <= Q ; i++ )
{
ll k ;
scanf("%lld", &k ) ;
t += k ;
pref.pb(mk(t,i)) ;
suf.pb(mk(t,i)) ;
}
sort(all(pref)) ;
sort(all(suf)) ;
for(int i = sz(suf)-2 ; i >= 0 ; i-- )
suf[i].ss = min(suf[i].ss , suf[i+1].ss) ;
for(int i = 1 ; i < sz(pref); i++ )
pref[i].ss = min(pref[i-1].ss, pref[i].ss ) ;
R[N] = suf.back().ff+X[N] ;
for(int i = 1 ; i < N ; i++ )
{
ll l = X[i] , r = min(X[i+1],X[i]+suf.back().ff) , mid , best = X[i] ;
while(l <= r)
{
if( l == r-1 ) mid = l ;
else mid = (l+r)>>1 ;
int t_mine = lower_bound(all(suf), mk(mid-X[i], -1) )->second ;
auto it = upper_bound(all(pref), mk(mid-X[i+1],-1) ) ;
int t_yours = Q+10 ;
if(it != pref.begin() )
{
it-- ;
t_yours = it->second ;
}
if(t_mine < t_yours) { best= mid ; l = mid+1 ; }
else r = mid-1 ;
}
R[i] = best ;
}
L[1] = min(X[1]+pref[0].ff, X[1] ) ;
for(int i = 2 ; i<= N ; i++ )
{
L[i] = min(X[i] , X[i]+pref[0].ff ) ;
if( R[i-1] >= L[i] )
L[i] = R[i-1] ;
}
lp(i,1,N+1) printf("%lld\n" , R[i]-L[i] ) ;
//lp(i,1,N+1) printf("%lld %lld\n" , L[i] ,R[i]) ;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
24 | scanf("%d %d", &N , &Q ) ;
| ~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:25:38: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
25 | for(int i = 1 ; i <= N ; i++ ) scanf("%lld", &X[i] ) ;
| ~~~~~^~~~~~~~~~~~~~~~
Main.cpp:34:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
34 | scanf("%lld", &k ) ;
| ~~~~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
492 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
7 ms |
492 KB |
Output is correct |
5 |
Correct |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
6 ms |
492 KB |
Output is correct |
7 |
Correct |
5 ms |
492 KB |
Output is correct |
8 |
Correct |
5 ms |
492 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
4 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
7 ms |
492 KB |
Output is correct |
16 |
Correct |
7 ms |
492 KB |
Output is correct |
17 |
Correct |
5 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
492 KB |
Output is correct |
2 |
Correct |
2 ms |
492 KB |
Output is correct |
3 |
Correct |
2 ms |
492 KB |
Output is correct |
4 |
Correct |
7 ms |
492 KB |
Output is correct |
5 |
Correct |
7 ms |
492 KB |
Output is correct |
6 |
Correct |
6 ms |
492 KB |
Output is correct |
7 |
Correct |
5 ms |
492 KB |
Output is correct |
8 |
Correct |
5 ms |
492 KB |
Output is correct |
9 |
Correct |
5 ms |
640 KB |
Output is correct |
10 |
Correct |
4 ms |
492 KB |
Output is correct |
11 |
Correct |
2 ms |
492 KB |
Output is correct |
12 |
Correct |
1 ms |
364 KB |
Output is correct |
13 |
Correct |
1 ms |
364 KB |
Output is correct |
14 |
Correct |
1 ms |
364 KB |
Output is correct |
15 |
Correct |
7 ms |
492 KB |
Output is correct |
16 |
Correct |
7 ms |
492 KB |
Output is correct |
17 |
Correct |
5 ms |
492 KB |
Output is correct |
18 |
Correct |
1 ms |
364 KB |
Output is correct |
19 |
Correct |
2 ms |
492 KB |
Output is correct |
20 |
Correct |
69 ms |
9084 KB |
Output is correct |
21 |
Correct |
67 ms |
8776 KB |
Output is correct |
22 |
Correct |
72 ms |
8520 KB |
Output is correct |
23 |
Correct |
87 ms |
8684 KB |
Output is correct |
24 |
Correct |
216 ms |
9156 KB |
Output is correct |
25 |
Correct |
1049 ms |
17032 KB |
Output is correct |
26 |
Correct |
1104 ms |
16760 KB |
Output is correct |
27 |
Correct |
992 ms |
16452 KB |
Output is correct |
28 |
Correct |
980 ms |
16744 KB |
Output is correct |
29 |
Correct |
925 ms |
16344 KB |
Output is correct |
30 |
Correct |
598 ms |
15408 KB |
Output is correct |
31 |
Correct |
166 ms |
15044 KB |
Output is correct |
32 |
Correct |
135 ms |
15172 KB |
Output is correct |
33 |
Correct |
79 ms |
2272 KB |
Output is correct |
34 |
Correct |
1079 ms |
17220 KB |
Output is correct |
35 |
Correct |
1008 ms |
16704 KB |
Output is correct |
36 |
Correct |
1060 ms |
16788 KB |
Output is correct |
37 |
Correct |
1002 ms |
16580 KB |
Output is correct |
38 |
Correct |
1002 ms |
16708 KB |
Output is correct |
39 |
Correct |
980 ms |
16644 KB |
Output is correct |
40 |
Correct |
591 ms |
16580 KB |
Output is correct |
41 |
Correct |
66 ms |
9544 KB |
Output is correct |
42 |
Correct |
122 ms |
15244 KB |
Output is correct |
43 |
Correct |
354 ms |
18372 KB |
Output is correct |
44 |
Correct |
62 ms |
9460 KB |
Output is correct |
45 |
Correct |
401 ms |
16708 KB |
Output is correct |
46 |
Correct |
342 ms |
18520 KB |
Output is correct |
47 |
Correct |
384 ms |
18756 KB |
Output is correct |
48 |
Correct |
130 ms |
18884 KB |
Output is correct |