답안 #548347

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548347 2022-04-13T05:09:31 Z Pherokung Snowball (JOI21_ho_t2) C++14
100 / 100
108 ms 15420 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
typedef pair<ll,ll> pa;
ll n,q,x[200005],a,mx=0,mi=0,sum=0,ans=0,val[200005][2];
priority_queue<pa,vector<pa>,greater<pa> > pq;
int main(){
	scanf("%lld%lld",&n,&q);
	for(int i=1;i<=n;i++) scanf("%lld",&x[i]);
	for(int i=1;i<=n-1;i++) pq.push({x[i+1]-x[i],i});
	memset(val,-1,sizeof val);
	for(int i=1;i<=q;i++){
		scanf("%lld",&a);
		sum += a;
		if(sum < mi){
			while(!pq.empty()){
				if(abs(sum) + mx >= pq.top().F){
					val[pq.top().S][1] = mx;
					val[pq.top().S+1][0] = pq.top().F - mx;
//					printf("?? %d (%d)= %d, %d (%d)= %d\n",pq.top().S,1,mx,pq.top().S+1,0,pq.top().F-mx);
					pq.pop();
				}
				else break;
			}
			mi = sum;
		}
		if(sum > mx){
			while(!pq.empty()){
				if(abs(sum) + abs(mi) >= pq.top().F){
					val[pq.top().S+1][0] = abs(mi);
					val[pq.top().S][1] = pq.top().F - abs(mi);
					pq.pop();
				}
				else break;
			}
			mx = sum;
		}
	}
	for(int i=1;i<=n;i++){
		if(i != 1 && val[i][0] == -1) val[i][0] = abs(mi);
		if(i != n && val[i][1] == -1) val[i][1] = mx;
	}
	val[1][0] = -mi, val[n][1] = mx;
	for(int i=1;i<=n;i++) printf("%lld\n",val[i][0] + val[i][1]);
}

Compilation message

Main.cpp: In function 'int main()':
Main.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  scanf("%lld%lld",&n,&q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~
Main.cpp:11:29: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |  for(int i=1;i<=n;i++) scanf("%lld",&x[i]);
      |                        ~~~~~^~~~~~~~~~~~~~
Main.cpp:15:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   15 |   scanf("%lld",&a);
      |   ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 3 ms 3524 KB Output is correct
5 Correct 3 ms 3540 KB Output is correct
6 Correct 3 ms 3540 KB Output is correct
7 Correct 3 ms 3540 KB Output is correct
8 Correct 3 ms 3524 KB Output is correct
9 Correct 2 ms 3540 KB Output is correct
10 Correct 2 ms 3520 KB Output is correct
11 Correct 2 ms 3528 KB Output is correct
12 Correct 2 ms 3384 KB Output is correct
13 Correct 2 ms 3412 KB Output is correct
14 Correct 2 ms 3388 KB Output is correct
15 Correct 3 ms 3572 KB Output is correct
16 Correct 3 ms 3540 KB Output is correct
17 Correct 3 ms 3540 KB Output is correct
18 Correct 2 ms 3412 KB Output is correct
19 Correct 2 ms 3540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 3412 KB Output is correct
2 Correct 2 ms 3412 KB Output is correct
3 Correct 2 ms 3412 KB Output is correct
4 Correct 3 ms 3524 KB Output is correct
5 Correct 3 ms 3540 KB Output is correct
6 Correct 3 ms 3540 KB Output is correct
7 Correct 3 ms 3540 KB Output is correct
8 Correct 3 ms 3524 KB Output is correct
9 Correct 2 ms 3540 KB Output is correct
10 Correct 2 ms 3520 KB Output is correct
11 Correct 2 ms 3528 KB Output is correct
12 Correct 2 ms 3384 KB Output is correct
13 Correct 2 ms 3412 KB Output is correct
14 Correct 2 ms 3388 KB Output is correct
15 Correct 3 ms 3572 KB Output is correct
16 Correct 3 ms 3540 KB Output is correct
17 Correct 3 ms 3540 KB Output is correct
18 Correct 2 ms 3412 KB Output is correct
19 Correct 2 ms 3540 KB Output is correct
20 Correct 32 ms 5568 KB Output is correct
21 Correct 31 ms 5328 KB Output is correct
22 Correct 31 ms 5084 KB Output is correct
23 Correct 28 ms 5028 KB Output is correct
24 Correct 34 ms 5804 KB Output is correct
25 Correct 108 ms 13476 KB Output is correct
26 Correct 104 ms 13488 KB Output is correct
27 Correct 104 ms 13104 KB Output is correct
28 Correct 106 ms 13232 KB Output is correct
29 Correct 103 ms 12828 KB Output is correct
30 Correct 98 ms 12152 KB Output is correct
31 Correct 92 ms 11540 KB Output is correct
32 Correct 87 ms 11800 KB Output is correct
33 Correct 12 ms 4576 KB Output is correct
34 Correct 108 ms 13996 KB Output is correct
35 Correct 102 ms 13252 KB Output is correct
36 Correct 108 ms 13524 KB Output is correct
37 Correct 103 ms 13236 KB Output is correct
38 Correct 103 ms 13112 KB Output is correct
39 Correct 100 ms 13348 KB Output is correct
40 Correct 101 ms 13236 KB Output is correct
41 Correct 34 ms 6092 KB Output is correct
42 Correct 65 ms 11696 KB Output is correct
43 Correct 100 ms 15024 KB Output is correct
44 Correct 34 ms 5932 KB Output is correct
45 Correct 74 ms 13320 KB Output is correct
46 Correct 98 ms 15148 KB Output is correct
47 Correct 100 ms 15328 KB Output is correct
48 Correct 104 ms 15420 KB Output is correct