Submission #1286156

#TimeUsernameProblemLanguageResultExecution timeMemory
1286156herominhsteveFoehn Phenomena (JOI17_foehn_phenomena)C++20
100 / 100
110 ms8164 KiB
#include <bits/stdc++.h>
#define el '\n'
#define FNAME "Foehn"
#define allof(x) x.begin(),x.end()
#define allof1(x) x.begin()+1,x.end()
#define mset(x,n) memset(x,(n),sizeof(x))
using namespace std;
const long long MOD = (long long) 1e9 + 7;
template<class X,class Y> bool minimize(X &a,Y b){ if (a>b) {a=b; return true;} return false;}
template<class X,class Y> bool maximize(X &a,Y b){ if (a<b) {a=b; return true;} return false;}

void setup(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
	if (fopen(FNAME".inp","r")){
		freopen(FNAME".inp"	,"r",stdin);
		freopen(FNAME".out","w",stdout);
	}
}

template<typename T>
struct FenwickTree{
	int n;
	vector<T> bit;
	FenwickTree(int N=0){
		n=N;
		if (n>0){
			bit.resize(n+1,0);
		}
	}
	void update(int node,T val){
		while (node<=n){
			bit[node]+=val;
			node += (node & -node);
		}
	}
	inline void range(int l,int r,T val){
		update(l,val);
		if (r+1<=n) update(r+1,-val);
	}
	T getVal(int node){
		T res=0;
		while (node>0){
			res+=bit[node];
			node -= (node & -node);
		}
		return res;
	}

};

int n,q,S,T;
vector<int> a;

FenwickTree<long long> curAt, total;

void init(){
	cin>>n>>q>>S>>T;
	curAt = FenwickTree<long long>(n);
	total = FenwickTree<long long>(n);
	a.assign(n+1,0);
	cin>>a[1];
	for (int i=1;i<=n;i++){
		cin>>a[i];
		curAt.range(i,i,+a[i]);
	}
}

/*
 * a[i] < a[i+1] => - abs * S
 * a[i] >= a[i+1] >= + abs * T
 * a[i-1] < a[i] => - abs * S
 * a[i-1] >= a[i] => + abs * T
*/

inline void update(int pos,int delta){
	long long prev = curAt.getVal(pos-1);
	long long cur = curAt.getVal(pos);
	if (prev < cur)
		total.update(pos, - (cur - prev) * 1ll * delta * S);
	else
		total.update(pos, + (prev - cur) * 1ll * delta * T);
}

void sol(){
	for (int i=1;i<=n;i++) update(i,1);
	while (q--){
		int l,r,x;
		cin>>l>>r>>x;
		update(l,-1);
		if (r+1<=n) update(r+1,-1);
		curAt.range(l,r,x);
		update(l,+1);
		if (r+1<=n) update(r+1,+1);
		cout<<total.getVal(n)<<el;
	}	
}

int main(){
    setup();
    init();
    sol();
}

Compilation message (stderr)

foehn_phenomena.cpp: In function 'void setup()':
foehn_phenomena.cpp:16:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |                 freopen(FNAME".inp"     ,"r",stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:17:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |                 freopen(FNAME".out","w",stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...