Submission #501445

#TimeUsernameProblemLanguageResultExecution timeMemory
501445nightySjeckanje (COCI21_sjeckanje)C++14
0 / 110
1 ms204 KiB
#include <bits/stdc++.h> using namespace std; bool areSameSgn(long long a, long long b) { return (a > 0 && b > 0) || (a < 0 && b < 0) || (a == b); } long long calc(const vector<long long>& a) { long long res = 0; int i = 0; while (i + 1 < a.size()) { int from = i; if (a[from] == a[from + 1]) { ++i; continue; } while (i + 1 < a.size() && areSameSgn(a[i + 1] - a[i], a[from + 1] - a[from])) { ++i; } res += abs(a[i] - a[from]); ++i; } return res; } int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); int n, q; cin >> n >> q; vector<long long> a(n); for (auto& i : a) { cin >> i; } while (q--) { int l, r, x; cin >> l >> r >> x; --l, --r; for (int i = l; i <= r; ++i) { a[i] += x; } cout << calc(a) << '\n'; } return 0; }

Compilation message (stderr)

Main.cpp: In function 'long long int calc(const std::vector<long long int>&)':
Main.cpp:12:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   12 |     while (i + 1 < a.size()) {
      |            ~~~~~~^~~~~~~~~~
Main.cpp:18:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         while (i + 1 < a.size() && areSameSgn(a[i + 1] - a[i], a[from + 1] - a[from])) {
      |                ~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...