답안 #548346

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
548346 2022-04-13T05:07:08 Z Pherokung Snowball (JOI21_ho_t2) C++14
0 / 100
3 ms 3544 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define F first
#define S second
typedef pair<int,int> 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] = -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 Incorrect 3 ms 3544 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 3544 KB Output isn't correct
2 Halted 0 ms 0 KB -