제출 #157471

#제출 시각아이디문제언어결과실행 시간메모리
157471GioChkhaidzeFoehn Phenomena (JOI17_foehn_phenomena)C++14
0 / 100
419 ms8184 KiB
#include <bits/stdc++.h>
#define Tree int h,int l,int r
#define left 2*h,l,(l+r)/2
#define right 2*h+1,(l+r)/2+1,r
using namespace std;
const int N=2e5+5;
long long n,q,s,t,L,R,X,ANS,idx,x,y,V=0;
long long a[N],v[6*N];
void Get(Tree,int idx) {
	if (idx<l || r<idx) return ; V+=v[h];
	if (l==idx && r==idx) return ;
	Get(left,idx),Get(right,idx);
}
void Upd(Tree) {
	if (R<l || r<L) return ;
	if (L<=l && r<=R) { v[h]+=X; return ; }
	Upd(left),Upd(right);
}
void RectL(long long x,long long y,long long X)  {
	if (x<y) {
		ANS+=(y-x)*s;
		y+=X;
		if (x<y) ANS-=(y-x)*s;	
			else ANS+=(x-y)*t;				
	}
		else {
		ANS-=(x-y)*t;
		y+=X;
		if (x<y) ANS-=(y-x)*s;	
			else ANS+=(x-y)*t;				
	}
}
void RectR(long long x,long long y,long long X)  {
	if (x<y) {
		ANS+=(y-x)*s;
		x+=X;
		if (x<y) ANS-=(y-x)*s;	
			else ANS+=(x-y)*t;	
	}
		else {
		ANS-=(x-y)*t;	
		x+=X;
		if (x<y) ANS-=(y-x)*s;	
			else ANS+=(x-y)*t;	
	}
}
main () { 
	ios::sync_with_stdio(false);
	cin>>n>>q>>s>>t;
	for (int i=0; i<=n; i++) {
		cin>>a[i];
		if (i)  {
			if (a[i-1]<a[i]) ANS-=(a[i]-a[i-1])*s;	
						else ANS+=(a[i-1]-a[i])*t;
						
 			L=i,R=i,X=a[i];
			Upd(1,1,n);
		}
	}
	
	while (q--) {
		cin>>L>>R>>X;

		if (R==n) {
			V=0,Get(1,1,n,L-1),x=V;
			V=0,Get(1,1,n,L),y=V;
			RectL(x,y,X);
		}
			else { 
			V=0,Get(1,1,n,L-1),x=V;
			V=0,Get(1,1,n,L),y=V;
			RectL(x,y,X);
			V=0,Get(1,1,n,R),x=V;
			V=0,Get(1,1,n,R+1),y=V;
			RectR(x,y,X);
		}
		
		Upd(1,1,n);
		printf("%d\n",ANS);
	}
}

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

foehn_phenomena.cpp: In function 'void Get(int, int, int, int)':
foehn_phenomena.cpp:10:2: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
  if (idx<l || r<idx) return ; V+=v[h];
  ^~
foehn_phenomena.cpp:10:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
  if (idx<l || r<idx) return ; V+=v[h];
                               ^
foehn_phenomena.cpp: At global scope:
foehn_phenomena.cpp:47:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () { 
       ^
foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:79:20: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   printf("%d\n",ANS);
                    ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...