Submission #911433

# Submission time Handle Problem Language Result Execution time Memory
911433 2024-01-18T23:13:53 Z vjudge1 Snowball (JOI21_ho_t2) C++11
100 / 100
824 ms 13724 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 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 9 ms 568 KB Output is correct
5 Correct 8 ms 348 KB Output is correct
6 Correct 8 ms 568 KB Output is correct
7 Correct 8 ms 348 KB Output is correct
8 Correct 9 ms 348 KB Output is correct
9 Correct 11 ms 348 KB Output is correct
10 Correct 8 ms 348 KB Output is correct
11 Correct 8 ms 484 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 8 ms 348 KB Output is correct
17 Correct 8 ms 560 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 11 ms 560 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 9 ms 568 KB Output is correct
5 Correct 8 ms 348 KB Output is correct
6 Correct 8 ms 568 KB Output is correct
7 Correct 8 ms 348 KB Output is correct
8 Correct 9 ms 348 KB Output is correct
9 Correct 11 ms 348 KB Output is correct
10 Correct 8 ms 348 KB Output is correct
11 Correct 8 ms 484 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 440 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 8 ms 348 KB Output is correct
17 Correct 8 ms 560 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 11 ms 560 KB Output is correct
20 Correct 65 ms 6312 KB Output is correct
21 Correct 65 ms 7172 KB Output is correct
22 Correct 55 ms 6784 KB Output is correct
23 Correct 57 ms 6588 KB Output is correct
24 Correct 122 ms 6084 KB Output is correct
25 Correct 805 ms 12648 KB Output is correct
26 Correct 821 ms 12732 KB Output is correct
27 Correct 805 ms 12932 KB Output is correct
28 Correct 799 ms 12772 KB Output is correct
29 Correct 793 ms 12020 KB Output is correct
30 Correct 792 ms 11596 KB Output is correct
31 Correct 757 ms 11992 KB Output is correct
32 Correct 763 ms 11304 KB Output is correct
33 Correct 89 ms 1740 KB Output is correct
34 Correct 807 ms 12716 KB Output is correct
35 Correct 824 ms 13004 KB Output is correct
36 Correct 810 ms 13540 KB Output is correct
37 Correct 802 ms 12684 KB Output is correct
38 Correct 795 ms 13016 KB Output is correct
39 Correct 822 ms 12452 KB Output is correct
40 Correct 776 ms 12372 KB Output is correct
41 Correct 75 ms 6336 KB Output is correct
42 Correct 763 ms 11468 KB Output is correct
43 Correct 794 ms 12744 KB Output is correct
44 Correct 72 ms 8128 KB Output is correct
45 Correct 777 ms 12612 KB Output is correct
46 Correct 796 ms 13008 KB Output is correct
47 Correct 805 ms 13724 KB Output is correct
48 Correct 800 ms 13196 KB Output is correct