답안 #31118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
31118 2017-08-10T03:57:59 Z trath Foehn Phenomena (JOI17_foehn_phenomena) C++11
0 / 100
0 ms 34052 KB
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define ll long long int
#define ieps 200010
#define eps (int) 1e9
#define pii pair<int,int>

 ll read_int(){
	char r;
	bool start=false,neg=false;
	 ll ret=0;
	while(true){
		r=getchar();
		if((r-'0'<0 || r-'0'>9) && r!='-' && !start){
			continue;
		}
		if((r-'0'<0 || r-'0'>9) && r!='-' && start){
			break;
		}
		if(start)ret*=10;
		start=true;
		if(r=='-')neg=true;
		else ret+=r-'0';
	}
	if(!neg)
		return ret;
	else
		return -ret;
}


		

struct node{
	ll leftmost, rightmost, sumup , sumdown;
	void clv(){
		leftmost = rightmost = sumup = sumdown = 0;
	}
};
int a , b , val;
int n , q ,   v[ieps] ;
ll s , t;
ll lazy[ieps*4];
node st[ieps*4];

void propagate(int curr){
	if(lazy[curr]){
		st[curr].leftmost += lazy[curr];
		st[curr].rightmost += lazy[curr];
		lazy[2*curr] += lazy[curr];
		lazy[2*curr + 1] += lazy[curr];
		lazy[curr] = 0;
	}
}

node mixnode(node left, node right){
	node x;
	x.clv();
	ll toadd = 0 , tosubtract = 0;
	if(left.rightmost >= right.leftmost){
		toadd += t*(left.rightmost - right.leftmost);
	}
	else if(left.rightmost < right.leftmost){
		tosubtract += s*(right.leftmost - left.rightmost);
	}
	x.leftmost = left.leftmost;
	x.rightmost = right.rightmost;
	x.sumup = left.sumup + right.sumup + toadd;
	x.sumdown = left.sumdown + right.sumdown + tosubtract;
	//cout<<x.sumup<<" "<<x.sumdown<<endl;
	return x;
}

void build(int l = 0 , int r = n- 1 , int curr = 1){
	if(l == r){
		st[curr].clv();
		st[curr].rightmost = st[curr].leftmost  = v[l];
		return;
	}
	build(l , (l+r)/2 , 2*curr);
	build((l+r)/2 + 1 , r, 2*curr + 1);
	st[curr] = mixnode(st[2*curr] , st[2*curr + 1]);
	return;
}

void update(int x , int y , int l = 0 , int r = n- 1 , int curr = 1){
	propagate(curr);
	if(l == x && r == y){
		lazy[curr]+=val;
		propagate(curr);
		return;
	}
	ll mid = (l+r)/2;
	if(y <= mid){
		update(x , y, l , mid , 2*curr);
	}
	else if(x > mid){
		update(x ,y, mid + 1 ,r , 2*curr + 1);
	}
	else{
		update(x , mid , l , mid , 2*curr);
		update(mid + 1 , y , mid + 1 , r , 2*curr + 1);
	}
	propagate(2*curr);
	propagate(2*curr + 1);
	st[curr] = mixnode(st[2*curr] , st[2*curr + 1]);
	return;
}




int main(){
	scanf("%lld%lld%lld%lld", &n, &q, &s, &t);
	n = n+1;
	for(int i = 0;i<n;i++) scanf("%lld", &(v[i]));;
	build();
	for(int i = 0;i<q;i++){
		scanf("%d%d%d", &a, &b, &val);
		update(a , b);
		ll p = st[1].sumup;
		p-=st[1].sumdown;
		printf("%lld\n",p);
	}
	return 0;
}

Compilation message

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:118:42: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
  scanf("%lld%lld%lld%lld", &n, &q, &s, &t);
                                          ^
foehn_phenomena.cpp:118:42: warning: format '%lld' expects argument of type 'long long int*', but argument 3 has type 'int*' [-Wformat=]
foehn_phenomena.cpp:120:46: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
  for(int i = 0;i<n;i++) scanf("%lld", &(v[i]));;
                                              ^
foehn_phenomena.cpp:118:43: 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:120:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for(int i = 0;i<n;i++) scanf("%lld", &(v[i]));;
                                               ^
foehn_phenomena.cpp:123:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &a, &b, &val);
                                ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 34052 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 34052 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 34052 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -