Submission #850175

#TimeUsernameProblemLanguageResultExecution timeMemory
850175gun_ganSjeckanje (COCI21_sjeckanje)C++17
0 / 110
1 ms2392 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int MX = 2e5 + 5; int N, Q; ll A[MX], dp[MX][2]; ll calc() { for(int i = 0; i <= N; i++) dp[i][0] = dp[i][1] = 0; vector<array<ll,3>> v; for(int i = 1; i + 1 <= N; i++) { if(A[i + 1] >= A[i]) { int j = i; ll sum = 0; while(j + 1 <= N && A[j + 1] >= A[j]) { sum += A[j + 1] - A[j]; j++; } v.push_back({A[i + 1] - A[i], A[j] - A[j - 1], sum}); i = j - 1; } else { int j = i; ll sum = 0; while(j + 1 <= N && A[j + 1] < A[j]) { sum += A[j] - A[j + 1]; j++; } v.push_back({A[i] - A[i + 1], A[j - 1] - A[j], sum}); i = j - 1; } } if(v.size() == 1) return v[0][2]; ll res = v.back()[2]; for(int i = 0; i + 1 < v.size(); i++) { res += v[i][2]; res -= min(v[i][1], v[i + 1][0]); } return res; } int main() { cin.tie(0); ios_base::sync_with_stdio(0); cin >> N >> Q; for(int i = 1; i <= N; i++) cin >> A[i]; for(int i = 1; i <= Q; i++) { ll l, r, x; cin >> l >> r >> x; for(int j = l; j <= r; j++) A[j] += x; cout << calc() << '\n'; } }

Compilation message (stderr)

Main.cpp: In function 'll calc()':
Main.cpp:39:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<long long int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |       for(int i = 0; i + 1 < v.size(); i++) {
      |                      ~~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...