제출 #731144

#제출 시각아이디문제언어결과실행 시간메모리
731144sleepntsheepFoehn Phenomena (JOI17_foehn_phenomena)C++17
0 / 100
187 ms13016 KiB
#include <bits/stdc++.h>
using namespace std;

template <class T>
struct BIT
{
    int n; T *a;
    BIT(int m) : n(m), a(new T[m]) {}
    ~BIT() { delete []a; }
    void inc(T p, int x) { for (; p < n; p += p&-p) a[p] += x; }
    T qry(int p, T z = 0) { for (;p; p-=p&-p) z+=a[p]; return z;}
    void updmax(int p, T x) { for (;p<n; p+=p&-p) a[p]=std::max(x,a[p]);}
    T qrymax(int p, T z) { for (;p; p-=p&-p) z=std::max(z,a[p]); return z;}
};

#define N 402005
long long n, q, s, t, a[N];
BIT<long long> f(N), g(N);

int main()
{
    scanf("%lld%lld%lld%lld", &n, &q, &s, &t);
    for (int i = 0; i <= n; i++) scanf("%lld", a+i), f.inc(i+1, a[i]), f.inc(i+2, -a[i]);
    for (int i = 1; i <= n; i++)
    {
        auto d = -f.qry(i+1) + f.qry(i);
        if (d < 0) g.inc(i+1, s * d);
        else g.inc(i+1, t * d);
    }

    auto upd = [&](int p, long long x){
        long long old = 0, aft = 0;
        auto d = f.qry(p-1) - f.qry(p);
        old = (d < 0 ? s : t) * d;
        f.inc(p, x);
        d = f.qry(p-1) - f.qry(p);
        aft = (d < 0 ? s : t) * d;
        g.inc(p, aft - old);
    };

    for (long long l, r, x; q--;)
    {
        scanf("%lld%lld%lld", &l, &r, &x);

        upd(l+1, x);
        upd(r+2, -x);

        printf("%lld\n", g.qry(n+1));
    }

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     scanf("%lld%lld%lld%lld", &n, &q, &s, &t);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:23:39: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     for (int i = 0; i <= n; i++) scanf("%lld", a+i), f.inc(i+1, a[i]), f.inc(i+2, -a[i]);
      |                                  ~~~~~^~~~~~~~~~~~~
foehn_phenomena.cpp:43:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |         scanf("%lld%lld%lld", &l, &r, &x);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...