제출 #1116347

#제출 시각아이디문제언어결과실행 시간메모리
1116347staszic_ojuzFoehn Phenomena (JOI17_foehn_phenomena)C++17
0 / 100
1078 ms6820 KiB
#include <bits/stdc++.h> using namespace std; void upd(vector<int>& tree, int w, int in, int v) { in += w; tree[in] += v; for (in /= 2; in > 0; in /= 2) { tree[in] = tree[2 * in] + tree[2 * in + 1]; } } int sum(const vector<int>& tree, int w, int left, int right) { int result = 0; left += w; right += w; while (left < right) { if (left % 2 == 1) result += tree[left++]; if (right % 2 == 1) result += tree[--right]; left /= 2; right /= 2; } return result; } int li(vector <int> domy, vector<int> v, int i) { return sum(domy, v.size(), 0, i + 1) + v[i]; } int main() { int n, q, s, t, w, l, p, va, p1, p2, l1, l2; cin >> n >> q >> s >> t; n += 1; vector<int> domy(2 * n); vector<int> v(n); for (int i = 0; i < n; i++) { cin >> v[i]; if (i > 0 && v[i - 1] < v[i]) { w -= s * (v[i] - v[i - 1]); } else if(i > 0 && v[i - 1] > v[i]) { w += t * (v[i - 1] - v[i]); } } for (int i = 0; i < n; i++) { cout << v[i] << " "; } cout << endl; for (int i = 0; i < q; i++) { cin >> l >> p >> va; l1 = li(domy, v, l - 1); l2 = li(domy, v, l); if (l1 < l2) { w += s * (l2 - l1); } else { w -= t * (l1 - l2); } if (p < n - 1) { p1 = li(domy, v, p); p2 = li(domy, v, p + 1); if (p1 < p2) { w += s * (p2 - p1); } else { w -= t * (p1 - p2); } } upd(domy, n, l, va); if (p < n - 1) { upd(domy, n, p + 1, -va); } l1 = li(domy, v, l - 1); l2 = li(domy, v, l); if (l1 < l2) { w -= s * (l2 - l1); } else { w += t * (l1 - l2); } if (p < n - 1) { p1 = li(domy, v, p); p2 = li(domy, v, p + 1); if (p1 < p2) { w -= s * (p2 - p1); } else { w += t * (p1 - p2); } } cout << w << endl; } }

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

foehn_phenomena.cpp: In function 'int main()':
foehn_phenomena.cpp:54:15: warning: 'w' may be used uninitialized in this function [-Wmaybe-uninitialized]
   54 |             w -= t * (l1 - l2);
      |             ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...