제출 #40817

#제출 시각아이디문제언어결과실행 시간메모리
40817IvanCFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
537 ms193084 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 2*1e5 + 10;
ll S,T;
ll magic(ll A,ll B){
	if(A < B){
		return -S*abs(B - A);
	}
	else{
		return abs(B - A)*T;
	}
}
struct node{
	ll temperature;
	ll ini,fim,lazy;
	node() : temperature(0),ini(0),fim(0),lazy(0){}
	node operator*(const node& other)const{
		node novo;
		novo.ini = ini;
		novo.fim = other.fim;
		novo.lazy = 0;
		novo.temperature = temperature + magic(fim,other.ini) + other.temperature;
		return novo;
	}
};
ll N,Q,vetor[MAXN];
node seg[4*MAXN];
void propagate(int pos,int left,int right){
	seg[pos].ini += seg[pos].lazy;
	seg[pos].fim += seg[pos].lazy;
	if(left != right){
		seg[2*pos].lazy += seg[pos].lazy;
		seg[2*pos+1].lazy += seg[pos].lazy;
	}
	seg[pos].lazy = 0;
}
void build(int pos,int left,int right){
	if(left == right){
		seg[pos].ini = seg[pos].fim = vetor[left];
		seg[pos].temperature = seg[pos].lazy = 0;
		return;
	}
	int mid = (left+right)/2;
	build(2*pos,left,mid);
	build(2*pos+1,mid+1,right);
	seg[pos] = seg[2*pos] * seg[2*pos+1];
}
void update(int pos,int left,int right,int i,int j,ll delta){
	propagate(pos,left,right);
	if(left>right||left>j||right<i) return;
	if(left >= i && right <= j){
		seg[pos].lazy += delta;
		propagate(pos,left,right);
		return;
	}
	int mid = (left+right)/2;
	update(2*pos,left,mid,i,j,delta);
	update(2*pos+1,mid+1,right,i,j,delta);
	seg[pos] = seg[2*pos] * seg[2*pos+1];
}
int main(){
	scanf("%lld %lld %lld %lld",&N,&Q,&S,&T);
	for(int i = 0;i<=N;i++){
		scanf("%lld",&vetor[i]);
	}
	build(1,0,N);
	for(ll q = 1;q<=Q;q++){
		ll a,b,delta;
		scanf("%lld %lld %lld",&a,&b,&delta);
		update(1,0,N,a,b,delta);
		printf("%lld\n",seg[1].temperature);
	}
	return 0;
}

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

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:63:42: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%lld %lld %lld %lld",&N,&Q,&S,&T);
                                          ^
foehn_phenomena.cpp:65:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld",&vetor[i]);
                          ^
foehn_phenomena.cpp:70:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld %lld",&a,&b,&delta);
                                       ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...