제출 #46635

#제출 시각아이디문제언어결과실행 시간메모리
46635kuzmichev_dimaFoehn Phenomena (JOI17_foehn_phenomena)C++14
100 / 100
915 ms9316 KiB
#include <cstdio> #include <cstring> #include <algorithm> #include <vector> #include <iostream> #include <cassert> #include <cmath> #include <string> #include <queue> #include <set> #include <map> #include <cstdlib> using namespace std; #define INF 1e+9 #define mp make_pair #define pb push_back #define fi first #define fs first #define se second #define i64 long long #define li long long #define lint long long #define pii pair<int, int> #define vi vector<int> #define forn(i, n) for (int i = 0; i < (int)n; i++) #define fore(i, b, e) for (int i = (int)b; i <= (int)e; i++) const int maxn = 2e5+5; i64 tree[maxn * 4]; int start[maxn]; i64 S, T; int n; i64 get(int i, int L, int R, int pos) { if (L + 1 == R) return tree[i]; int M = (L + R) / 2; return (pos < M ? get(i * 2, L, M, pos) : get(i * 2 + 1, M, R, pos)) + tree[i]; } i64 get(int pos) { return get(1, 0, n + 1, pos); } void upd(int i, int L, int R, int A, int B, int diff) { if (L >= B || A >= R) return; if (L >= A && R <= B) { tree[i] += diff; return; } int M = (L + R) / 2; upd(i * 2, L, M, A, B, diff); upd(i * 2 + 1, M, R, A, B, diff); } void build(int i, int L, int R) { if (L + 1 == R) { tree[i] = start[L]; return; } int M = (L + R) / 2; build(i * 2, L, M); build(i * 2 + 1, M, R); } i64 calc(i64 fi, i64 se) { return se > fi ? (se - fi) * -S : (fi - se) * T; } int main() { #ifdef LOCAL freopen("inp", "r", stdin); //freopen("outp", "w", stdout); #else // freopen(TASKNAME ".in", "r", stdin); // freopen(TASKNAME ".out", "w", stdout); #endif int Q; cin >> n >> Q >> S >> T; forn(i, n + 1) { scanf("%d", &start[i]); } build(1, 0, n + 1); i64 ans = 0; forn(i, n) ans += calc(start[i], start[i + 1]); forn(q, Q) { int L, R, diff; scanf("%d%d%d", &L, &R, &diff); ans -= calc(get(L - 1), get(L)); if (R != n) ans -= calc(get(R), get(R + 1)); upd(1, 0, n + 1, L, R + 1, diff); ans += calc(get(L - 1), get(L)); if (R != n) ans += calc(get(R), get(R + 1)); cout << ans << endl; } }

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

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:86:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &start[i]);
         ~~~~~^~~~~~~~~~~~~~~~~
foehn_phenomena.cpp:94:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &L, &R, &diff);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...