Submission #911347

# Submission time Handle Problem Language Result Execution time Memory
911347 2024-01-18T19:15:29 Z vjudge1 Snowball (JOI21_ho_t2) C++17
100 / 100
831 ms 16064 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
signed main() {
	ll n, q;
	cin>>n>>q;
	vector<ll>pos(n);
	for(ll i=0;i<n;i++){
		cin>>pos[i];
	}
	vector<pair<ll,ll>>rangos;
	rangos.push_back({0,0});
	ll ml=0,rr=0;
	ll suma=0;
	for(ll i=0;i<q;i++){
		ll w;
		cin>>w;
		suma+=w;
		rr=max(suma,rr);
		ml=min(suma,ml);
		rangos.push_back({ml,rr});
	}
	vector<ll>amplitud(n,0LL);
	amplitud[0]=-rangos[rangos.size()-1].first;
	amplitud[n-1]+=rangos[rangos.size()-1].second;
	for(ll i=0LL;i<n-1;i++){
		ll l=0,r=rangos.size();
		while(l<r){
			ll mid=(l+r)/2;
			if(pos[i]+rangos[mid].second>pos[i+1]+rangos[mid].first){
				r=mid;
			}
			else{
				l=mid+1;
			}
		}
		cerr << "bs = " << l << endl;
		ll dir=0;
		if(l==rangos.size()){
			amplitud[i]+=rangos[l-1].second;
			amplitud[i+1]+=-rangos[l-1].first;
			continue;
		}
		if(rangos[l].first<rangos[l-1].first)dir=-1;
		else dir=1;
		ll e=0;
		if(dir==1){
			amplitud[i+1]+=abs(min(0LL,rangos[l].first));
			ll diff=pos[i+1]-abs(min(0LL,rangos[l].first));
			diff=max(0LL,diff-pos[i]);
			amplitud[i]+=diff;
		}
		else{
			amplitud[i]+=abs(max(0LL,rangos[l].second));
			ll diff=pos[i]+abs(max(0LL,rangos[l].second));
			diff=max(0LL,pos[i+1]-diff);
			amplitud[i+1]+=diff;
		}
	}
	for(ll i=0;i<n;i++){
		cout<<amplitud[i]<<"\n";
	}
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:39:7: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   if(l==rangos.size()){
      |      ~^~~~~~~~~~~~~~~
Main.cpp:46:6: warning: unused variable 'e' [-Wunused-variable]
   46 |   ll e=0;
      |      ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 8 ms 344 KB Output is correct
5 Correct 8 ms 348 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 8 ms 344 KB Output is correct
8 Correct 8 ms 348 KB Output is correct
9 Correct 8 ms 348 KB Output is correct
10 Correct 8 ms 348 KB Output is correct
11 Correct 9 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 9 ms 348 KB Output is correct
17 Correct 8 ms 488 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 8 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 452 KB Output is correct
4 Correct 8 ms 344 KB Output is correct
5 Correct 8 ms 348 KB Output is correct
6 Correct 8 ms 348 KB Output is correct
7 Correct 8 ms 344 KB Output is correct
8 Correct 8 ms 348 KB Output is correct
9 Correct 8 ms 348 KB Output is correct
10 Correct 8 ms 348 KB Output is correct
11 Correct 9 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 1 ms 344 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 9 ms 348 KB Output is correct
17 Correct 8 ms 488 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 8 ms 348 KB Output is correct
20 Correct 68 ms 7872 KB Output is correct
21 Correct 58 ms 7288 KB Output is correct
22 Correct 56 ms 6336 KB Output is correct
23 Correct 59 ms 6536 KB Output is correct
24 Correct 122 ms 7212 KB Output is correct
25 Correct 803 ms 14596 KB Output is correct
26 Correct 799 ms 14232 KB Output is correct
27 Correct 799 ms 14508 KB Output is correct
28 Correct 831 ms 14172 KB Output is correct
29 Correct 783 ms 14180 KB Output is correct
30 Correct 792 ms 12828 KB Output is correct
31 Correct 761 ms 12416 KB Output is correct
32 Correct 751 ms 12548 KB Output is correct
33 Correct 89 ms 2104 KB Output is correct
34 Correct 803 ms 14444 KB Output is correct
35 Correct 790 ms 14008 KB Output is correct
36 Correct 808 ms 14424 KB Output is correct
37 Correct 801 ms 14012 KB Output is correct
38 Correct 794 ms 13720 KB Output is correct
39 Correct 808 ms 14232 KB Output is correct
40 Correct 765 ms 14012 KB Output is correct
41 Correct 76 ms 7420 KB Output is correct
42 Correct 753 ms 12752 KB Output is correct
43 Correct 793 ms 15516 KB Output is correct
44 Correct 74 ms 7104 KB Output is correct
45 Correct 775 ms 14020 KB Output is correct
46 Correct 808 ms 16044 KB Output is correct
47 Correct 807 ms 16036 KB Output is correct
48 Correct 801 ms 16064 KB Output is correct