이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define sz(x) (int)x.size()
#define chmin(x, v) x = min(x, v)
#define chmax(x, v) x = max(x, v)
#define all(x) x.begin(), x.end()
#define pb push_back
#define pii pair<int, int>
#define deb first
#define fin second
#define int long long
using namespace std;
const int N = (1 << 18);
int arbre[N * 2];
int T, S;
int getSum(int noeud){
int sum = 0;
for (; noeud > 0; noeud /= 2)
sum += arbre[noeud];
return sum;
}
void ajouter(int gauche, int droite, int delta){
while (droite >= gauche){
if (gauche%2 == 1)
arbre[gauche++] += delta;
if (droite%2 == 0)
arbre[droite--] += delta;
gauche /= 2;
droite /= 2;
}
}
int ecarts[N * 2];
void calcEcart(int ind){
ecarts[N + ind] = getSum(N + ind + 1) - getSum(N + ind);
if (ecarts[N + ind] < 0)
ecarts[N + ind] *= -T;
else
ecarts[N + ind] *= -S;
for (int noeud = (N + ind)/2; noeud > 0; noeud /= 2)
ecarts[noeud] = ecarts[noeud * 2] + ecarts[noeud * 2 + 1];
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int nMonts, nReqs; cin >> nMonts >> nReqs >> S >> T;
for (int iMont = 0; iMont <= nMonts; ++iMont){
cin >> arbre[iMont + N];
if (iMont > 0)
calcEcart(iMont - 1);
}
for (int iReq = 0; iReq < nReqs; ++iReq){
int gauche, droite, delta;
cin >> gauche >> droite >> delta;
ajouter(N + gauche, N + droite, delta);
calcEcart(gauche - 1);
if (droite != nMonts)
calcEcart(droite);
cout << ecarts[1] << endl;
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |