답안 #543302

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
543302 2022-03-30T06:04:16 Z Aktan Snowball (JOI21_ho_t2) C++14
100 / 100
129 ms 10408 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template<class T>
using ordered_set = tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define ft first
#define sc second
const int mod=1e9+7,INF=1e17,N=2e5+10;

int mn[N],mx[N],ans[N];
main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	int n,q;
	cin >> n >> q;
	vector<int> a(n+1),b(q+1);
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	int cnt=0;
	for(int i=1;i<=q;i++){
		cin >> b[i];
		cnt+=b[i];
		mn[i]=min(mn[i-1],cnt);
		mx[i]=max(mx[i-1],cnt);
	}
	ans[1]+=abs(mn[q]);
    ans[n]+=mx[q];
	for(int i=1;i<n;i++){
		if(a[i]+mx[q]<=a[i+1]+mn[q]){
            ans[i]+=mx[q];
            ans[i+1]+=abs(mn[q]);
        }
		else{
		int l=1,r=q;
		while(l<r){
			int m=(l+r)/2;
			if(a[i]+mx[m]>a[i+1]+mn[m]){
				r=m;
			}
			else{
				l=m+1;
			}
		}
		if(b[l]>0){
                ans[i]+=max(0ll,a[i+1]+mn[l-1]-a[i]);
                ans[i+1]+=max(0ll,a[i+1]-(a[i+1]+mn[l-1]));
        }
		else{
                ans[i]+=max(0ll,a[i]+mx[l-1]-a[i]);
                ans[i+1]+=max(0ll,a[i+1]-a[i]-mx[l-1]);
        }
   	}
	}
	for(int i=1;i<=n;i++){
		cout << ans[i] << "\n";
	}
	
}

Compilation message

Main.cpp:14:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   14 | main(){
      | ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 392 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 404 KB Output is correct
17 Correct 1 ms 396 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 468 KB Output is correct
8 Correct 2 ms 392 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 404 KB Output is correct
17 Correct 1 ms 396 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 28 ms 5560 KB Output is correct
21 Correct 29 ms 5608 KB Output is correct
22 Correct 26 ms 5588 KB Output is correct
23 Correct 23 ms 5600 KB Output is correct
24 Correct 41 ms 6000 KB Output is correct
25 Correct 108 ms 10388 KB Output is correct
26 Correct 102 ms 10312 KB Output is correct
27 Correct 126 ms 10024 KB Output is correct
28 Correct 100 ms 10052 KB Output is correct
29 Correct 100 ms 9900 KB Output is correct
30 Correct 91 ms 9440 KB Output is correct
31 Correct 71 ms 9128 KB Output is correct
32 Correct 51 ms 9004 KB Output is correct
33 Correct 9 ms 1668 KB Output is correct
34 Correct 101 ms 10296 KB Output is correct
35 Correct 102 ms 10056 KB Output is correct
36 Correct 104 ms 10256 KB Output is correct
37 Correct 129 ms 10060 KB Output is correct
38 Correct 120 ms 10052 KB Output is correct
39 Correct 94 ms 10124 KB Output is correct
40 Correct 86 ms 10072 KB Output is correct
41 Correct 33 ms 5572 KB Output is correct
42 Correct 63 ms 9040 KB Output is correct
43 Correct 89 ms 10316 KB Output is correct
44 Correct 50 ms 5596 KB Output is correct
45 Correct 65 ms 10060 KB Output is correct
46 Correct 97 ms 10328 KB Output is correct
47 Correct 84 ms 10408 KB Output is correct
48 Correct 115 ms 10316 KB Output is correct