Submission #31117

# Submission time Handle Problem Language Result Execution time Memory
31117 2017-08-10T03:51:13 Z trath Foehn Phenomena (JOI17_foehn_phenomena) C++
0 / 100
36 ms 39520 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
#define ieps 800040
#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;
}


		int a, b;

struct node{
	ll leftmost, rightmost, sumup , sumdown;
	void clv(){
		leftmost = rightmost = sumup = sumdown = 0;
	}
};

ll lazy[ieps]  , n , q , s , t , v[ieps] , val;

node st[ieps];

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(){
	n = read_int() , q = read_int() , s = read_int() , t = read_int();
	n = n+1;
	for(int i = 0;i<n;i++) v[i] = read_int();
	build();
	for(int i = 0;i<q;i++){
		a =read_int();
		b = read_int();
		val = read_int();
		update(a , b);
		ll p = st[1].sumup;
		p-=st[1].sumdown;
		printf("%I64d\n",p);
		
	}
	return 0;
}

Compilation message

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:128:21: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   printf("%I64d\n",p);
                     ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 39520 KB Output is correct
2 Incorrect 3 ms 39520 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 36 ms 39520 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 3 ms 39520 KB Output is correct
2 Incorrect 3 ms 39520 KB Output isn't correct
3 Halted 0 ms 0 KB -