제출 #83465

#제출 시각아이디문제언어결과실행 시간메모리
83465ekremFoehn Phenomena (JOI17_foehn_phenomena)C++98
0 / 100
375 ms22476 KiB
#include <bits/stdc++.h>
#define st first
#define nd second
#define mp make_pair
#define pb push_back
#define sol (k+k)
#define sag (k+k+1)
#define orta ((bas+son)/2)
#define N 200005
using namespace std;

int n, q, s, t, l, r, x, ans, a[N], b[N], seg[4*N];

void bu(int k, int bas, int son){
	if(bas == son){
		seg[k] = a[bas];
		return;
	}
	bu(sol, bas, orta);
	bu(sag, orta + 1, son);
}

int qu(int k, int bas, int son, int x){
	if(x == 0)
		return 0;
	if(bas == son)
		return seg[k];
	if(x <= orta)
		return seg[k] + qu(sol, bas, orta, x);
	return seg[k] + qu(sag, orta + 1, son, x);
}

void up(int k, int bas, int son, int x, int y, int z){
	if(bas > y or son < x)
		return;
	if(bas >= x and son <= y){
		seg[k] += z;
		return;
	}
	up(sol, bas, orta, x, y, z);
	up(sag, orta + 1, son, x, y, z);
}

int main() {
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
	scanf("%d %d %d %d",&n ,&q ,&s ,&t);
	for(int i = 0; i <= n; i++)
		scanf("%d",a + i);
	for(int i = 1; i <= n; i++){
		if(a[i] > a[i - 1])
			b[i] = -s * (a[i] - a[i - 1]);
		else
			b[i] = t * (a[i - 1] - a[i]);
		ans += b[i];
	}
	bu(1, 1, n);
	while(q--){
		scanf("%d %d %d",&l ,&r ,&x);
		ans -= b[r + 1] + b[l];
		up(1, 1, n, l, r, x);
		int a1 = qu(1, 1, n, l - 1);
		int a2 = qu(1, 1, n, l);
		int a3 = qu(1, 1, n, r);
		int a4 = qu(1, 1, n, r + 1);
		if(a2 > a1)
			b[l] = -s * (a2 - a1);
		else
			b[l] = t * (a1 - a2);

		if(a4 > a3)
			b[r + 1] = -s * (a4 - a3);
		else
			b[r + 1] = t * (a3 - a4);
		ans += b[r + 1] + b[l];
		printf("%d\n", ans);
	}
	return 0;
}

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

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:47:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d %d",&n ,&q ,&s ,&t);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:49:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d",a + i);
   ~~~~~^~~~~~~~~~~~
foehn_phenomena.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d %d",&l ,&r ,&x);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...