Submission #211085

#TimeUsernameProblemLanguageResultExecution timeMemory
211085w4123Foehn Phenomena (JOI17_foehn_phenomena)C++17
100 / 100
849 ms13188 KiB
// foehn phenomena.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//

#include <iostream>
using namespace std;
long long ss[200005];
long long a[200005];
int main()
{
    long long totalpos = 0;
    long long totalneg = 0;
    int n, q, s, t;
    cin >> n >> q >> s >> t;
    cin >> a[0];
    for (int i = 1; i <= n; i++)
    {
         cin >> a[i];
         if (a[i] - a[i - 1] > 0)
         {
             totalpos += a[i] - a[i - 1];
         }
         else
         {
             totalneg += a[i - 1] - a[i];
         }
         ss[i] = a[i] - a[i - 1];
    }
    for (int i = 0; i != q; i++)
    {
        int l, r, x;
        cin >> l >> r >> x;
        long long templ = ss[l] + x;
        if (templ >= 0)
        {
            totalpos += templ;
            if (ss[l] >= 0)
            {
                totalpos -= ss[l];
            }
            else
            {
                totalneg += ss[l];
            }
        }
        else
        {
            totalneg -= templ;
            if (ss[l] >= 0)
            {
                totalpos -= ss[l];
            }
            else
            {
                totalneg += ss[l];
            }
        }
        ss[l] = templ;
        if (r + 1 > n)
        {
            cout << totalneg * (t - s) + (totalneg - totalpos) * s << endl;
            continue;
        }
        x = -x;
        templ = ss[r + 1] + x;
        if (templ >= 0)
        {
            if (ss[r + 1] >= 0)
            {
                totalpos += x;
            }
            else
            {
                totalneg += ss[r + 1];
                totalpos += templ;
            }
        }
        else
        {
            if (ss[r+1] >= 0)
            {
                totalpos -= ss[r + 1];
                totalneg -= templ;
            }
            else
            {
                totalneg -= x;
            }
        }
        ss[r + 1] = templ;
        cout << totalneg * (t-s) + (totalneg - totalpos) * s << endl;
        
    }
}

// 运行程序: Ctrl + F5 或调试 >“开始执行(不调试)”菜单
// 调试程序: F5 或调试 >“开始调试”菜单

// 入门使用技巧: 
//   1. 使用解决方案资源管理器窗口添加/管理文件
//   2. 使用团队资源管理器窗口连接到源代码管理
//   3. 使用输出窗口查看生成输出和其他消息
//   4. 使用错误列表窗口查看错误
//   5. 转到“项目”>“添加新项”以创建新的代码文件,或转到“项目”>“添加现有项”以将现有代码文件添加到项目
//   6. 将来,若要再次打开此项目,请转到“文件”>“打开”>“项目”并选择 .sln 文件
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...