Question Portal
This question looks dizzy at the beginning...\ (Qwq \). First, we need to clarify the altitude & Temperature in the question. The temperature is affected by the altitude. Each time we change the altitude, we need the temperature.
When we start reading data, we can process the start point.\ (N \)The temperature of the location and the elevation difference of each location. Each read operation affects a certain interval, and the relative altitude in the interval remains unchanged, so the temperature does not change. Only the boundary of the interval may be affected. Therefore, we only need to process the boundary:This is the idea of difference..
For example\ ([L, R] \)The interval must be processed.\ (L \)The original answer of the location minus\ (L \)Change the altitude of the location, and add a new answer. Then\ (R + 1 \)The other parts are not affected.
\ (Code \)
# Include <cstdio> # include <algorithm> using namespace STD; typedef long ll; int N, Q, las; ll S, T, ANS, a [2, 200090]; ll CAL (ll x) {return x> 0? -X * s:-x * t;} int main () {scanf ("% d % LLD", & N, & Q, & S, & T); scanf ("% d", & las); For (INT I = 1; I <= N; I ++) {int x = 0; scanf ("% d", & X); A [I] = x-las; Las = x; ans + = CAL (A [I]);} while (Q --) {int x = 0, y = 0, Z = 0; scanf ("% d", & X, & Y, & Z ); ans-= CAL (A [x]); A [x] + = z; ans + = CAL (A [x]); If (y = N) {printf ("% LLD \ n", ANS); continue;} ANS-= CAL (A [Y + 1]); A [Y + 1]-= z; ans + = CAL (A [Y + 1]); printf ("% LLD \ n", ANS);} return 0 ;}
Libre OJ p2332 "joi 2017 final" tornado [differential Thinking] By cellur925