Libre OJ p2332 "joi 2017 final" tornado [differential Thinking] By cellur925

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.