답안 #850174

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
850174 2023-09-16T00:29:39 Z gun_gan Sjeckanje (COCI21_sjeckanje) C++17
0 / 110
1 ms 2392 KB
#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];

      cout << calc() << '\n';

      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

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++) {
      |                      ~~~~~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 2392 KB Output isn't correct
2 Halted 0 ms 0 KB -