제출 #421709

#제출 시각아이디문제언어결과실행 시간메모리
421709KerimSnowball (JOI21_ho_t2)C++17
33 / 100
48 ms3912 KiB
#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x)  cerr<< #x <<" = "<< x<<endl;
using namespace std;
 
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
ll arr[MAXN],w[MAXN];
pair<ll,ll>rng[3];
const ll B=1e16;
void print(pair<ll,ll>a){
	cout<<a.ff<<" "<<a.ss<<endl;
}
int main(){
    //freopen("file.in", "r", stdin);
    int n,q;
    scanf("%d%d",&n,&q);
    for(int i=1;i<=n;i++)
		scanf("%lld",arr+i);
	arr[0]=-B;
	arr[n+1]=B;
	for(int i=1;i<=q;i++)
		scanf("%lld",w+i);
	for(int i=1;i<=n;i++){
		ll x=arr[i-1],y=arr[i],z=arr[i+1],A,B;
		rng[0]=mp(x,x);
		rng[1]=mp(y,y);
		rng[2]=mp(z,z);
		bool a=0,b=0;
		for(int j=1;j<=q;j++){
			if(!w[j])continue;
			x+=w[j];
			y+=w[j];
			z+=w[j];
			umin(rng[0].ff,x);umax(rng[0].ss,x);
			umin(rng[1].ff,y);umax(rng[1].ss,y);
			umin(rng[2].ff,z);umax(rng[2].ss,z);
			if(rng[0].ss>=rng[1].ff and !a){
				a=1;
				if(w[j]<0)A=rng[0].ss;
				else A=rng[1].ff;
			}
			if(rng[1].ss>=rng[2].ff and !b){
				b=1;
				if(w[j]<0)B=rng[1].ss;
				else B=rng[2].ff;
			}
		}
		if(!a)A=rng[1].ff;
		if(!b)B=rng[1].ss;
		printf("%lld\n",B-A);
	}
	return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'int main()':
Main.cpp:29:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   29 |     scanf("%d%d",&n,&q);
      |     ~~~~~^~~~~~~~~~~~~~
Main.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   31 |   scanf("%lld",arr+i);
      |   ~~~~~^~~~~~~~~~~~~~
Main.cpp:35:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |   scanf("%lld",w+i);
      |   ~~~~~^~~~~~~~~~~~
Main.cpp:63:9: warning: 'B' may be used uninitialized in this function [-Wmaybe-uninitialized]
   63 |   printf("%lld\n",B-A);
      |   ~~~~~~^~~~~~~~~~~~~~
Main.cpp:63:9: warning: 'A' may be used uninitialized in this function [-Wmaybe-uninitialized]
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...