이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
const double PI = 4 * atan(1);
#define sz(x) (int)(x).size()
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pii pair <int, int>
#define vi vector<int>
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define vpi vector<pair<int, int>>
#define vpd vector<pair<double, double>>
#define pd pair<double, double>
#define f0r(i,a) for(int i=0;i<a;i++)
#define f1r(i,a,b) for(int i=a;i<b;i++)
#define trav(a, x) for (auto& a : x)
template<typename A, typename B> ostream& operator<<(ostream &cout, pair<A, B> const &p) { return cout << "(" << p.f << ", " << p.s << ")"; }
template<typename A> ostream& operator<<(ostream &cout, vector<A> const &v) {
cout << "["; for(int i = 0; i < v.size(); i++) {if (i) cout << ", "; cout << v[i];} return cout << "]";
}
void fast_io(){
ios_base::sync_with_stdio(0);
cin.tie(NULL);
cout.tie(NULL);
}
void io(string taskname){
string fin = taskname + ".in";
string fout = taskname + ".out";
const char* FIN = fin.c_str();
const char* FOUT = fout.c_str();
freopen(FIN, "r", stdin);
freopen(FOUT, "w", stdout);
fast_io();
}
const int MAX = 2e5 + 5;
ll a[MAX];
template<class T, int SZ> struct LazySeg { // set SZ to a power of 2
T sum[2*SZ], lazy[2*SZ];
LazySeg() {
memset(sum,0,sizeof sum);
memset(lazy,0,sizeof lazy);
}
void push(int ind, int L, int R) { // modify values for current node
sum[ind] += (R-L+1)*lazy[ind];
if (L != R) lazy[2*ind] += lazy[ind], lazy[2*ind+1] += lazy[ind]; // push lazy to children
lazy[ind] = 0;
}
void pull(int ind) { // recalc values for current node
sum[ind] = sum[2*ind]+sum[2*ind+1];
}
void upd(int lo, int hi, ll inc, int ind = 1, int L = 0, int R = SZ-1) {
push(ind,L,R);
if (hi < L || R < lo) return;
if (lo <= L && R <= hi) {
lazy[ind] = inc;
push(ind,L,R); return;
}
int M = (L+R)/2;
upd(lo,hi,inc,2*ind,L,M); upd(lo,hi,inc,2*ind+1,M+1,R);
pull(ind);
}
T qsum(int lo, int hi, int ind = 1, int L = 0, int R = SZ-1) {
push(ind,L,R);
if (lo > R || L > hi) return 0;
if (lo <= L && R <= hi) return sum[ind];
int M = (L+R)/2;
return qsum(lo,hi,2*ind,L,M)+qsum(lo,hi,2*ind+1,M+1,R);
}
};
LazySeg<ll, (1<<18)> seg;
LazySeg<ll, (1<<18)> h;
int main(){
fast_io();
ll n, q, s, t;
cin >> n >> q >> s >> t;
f0r(i, n+1){
cin >> a[i];
h.upd(i, i, a[i]);
}
f0r(i, n){
if(a[i] < a[i+1]){
seg.upd(i+1, i+1,seg.qsum(i, i) -s*(a[i+1] - a[i]));
}
else{
seg.upd(i+1, i+1, seg.qsum(i, i) + t*(a[i] - a[i+1]));
}
}
while(q--){
int l, r, x;
cin >> l >> r >> x;
h.upd(l, r, x);
if(l != 0){
ll aft = h.qsum(l, l);
ll oldTemp = seg.qsum(l, l);
ll temp = seg.qsum(l-1, l-1);
if(h.qsum(l-1, l-1)<aft){
temp -= s*(aft - h.qsum(l-1, l-1));
}
else{
temp += t*(h.qsum(l-1, l-1) - aft);
}
seg.upd(l, n, temp - oldTemp);
}
if(r != n){
ll aft = h.qsum(r, r);
ll temp = seg.qsum(r, r);
ll past = seg.qsum(r+1, r+1);
// cout << "height " << aft << " " << h.qsum(r+1, r+1) << endl;
if(aft<h.qsum(r+1, r+1)){
temp -= s*(h.qsum(r+1, r+1) - aft);
}
else temp += t*(aft - h.qsum(r+1, r+1));
// cout << temp - past << endl;
seg.upd(r+1, n, temp - past);
}
// f0r(i, n+1){
// cout << seg.qsum(i, i) << " ";
//}
//cout << endl;
cout << seg.qsum(n, n) << endl;
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
foehn_phenomena.cpp:1:0: warning: ignoring #pragma comment [-Wunknown-pragmas]
#pragma comment(linker, "/stack:200000000")
foehn_phenomena.cpp: In function 'void io(std::__cxx11::string)':
foehn_phenomena.cpp:52:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FIN, "r", stdin);
~~~~~~~^~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:53:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
freopen(FOUT, "w", stdout);
~~~~~~~^~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |