이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<long long, long long>
#define plll pair<long long, pll>
#define tiii tuple<int, int, int>
#define tlll tuple<long long, long long, long long>
#define tiiii tuple<int, int, int, int>
#define tllll tuple<long long, long long, long long, long long>
#define ff first
#define ss second
#define ee ss.ff
#define rr ss.ss
//#define DEBUG
using namespace std;
long long seg[808080][2][2];
void mrge(int ind)
{
auto &nd = seg[ind], &x = seg[ind << 1], &y = seg[ind << 1 | 1];
for(int i = 0; i < 2; ++i)
{
for(int j = 0; j < 2; ++j)
{
nd[i][j] = max(x[i][0] + y[1][j], x[i][1] + y[0][j]);
}
}
}
void init(const int *B, int ind, int s, int e)
{
if(s + 1 == e)
{
if(B[s] < 0) seg[ind][0][0] = -B[s];
else seg[ind][1][1] = B[s];
return;
}
int mid = s + e >> 1;
init(B, ind << 1, s, mid);
init(B, ind << 1 | 1, mid, e);
mrge(ind);
}
void upd(int ind, int s, int e, int pos, int x)
{
if(s + 1 == e)
{
for(int i = 0; i < 2; ++i) for(int j = 0; j < 2; ++j) seg[ind][i][j] = 0;
if(x < 0) seg[ind][0][0] = -x;
else seg[ind][1][1] = x;
return;
}
int mid = s + e >> 1;
if(pos < mid) upd(ind << 1, s, mid, pos, x);
else upd(ind << 1 | 1, mid, e, pos, x);
mrge(ind);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, T; cin >> n >> T;
int A[n]; for(auto &i : A) cin >> i;
int B[n - 1]; for(int i = 0; i < n - 1; ++i) B[i] = A[i + 1] - A[i];
init(B, 1, 0, n - 1);
while(T--)
{
int l, r, x; cin >> l >> r >> x; l -= 2; --r;
if(l >= 0) upd(1, 0, n - 1, l, B[l] += x);
if(r < n - 1) upd(1, 0, n - 1, r, B[r] -= x);
#ifdef DEBUG
cout << endl;
cout << "B" << endl;
for(int i = 0; i < n - 1; ++i) cout << B[i] << ' '; cout << endl;
cout << endl;
#endif
#ifdef DEBUG
cout << endl;
cout << "seg" << endl;
for(int i = 0; i < 4 * n; ++i)
{
cout << i << ' ';
for(int j = 0; j < 2; ++j)
for(int k = 0; k < 2; ++k)
cout << seg[i][j][k] << ' ';
cout << endl;
}
cout << endl;
#endif
cout << max({ seg[1][0][0], seg[1][0][1], seg[1][1][0], seg[1][1][1] }) << '\n';
}
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'void init(const int*, int, int, int)':
Main.cpp:45:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
45 | int mid = s + e >> 1;
| ~~^~~
Main.cpp: In function 'void upd(int, int, int, int, int)':
Main.cpp:61:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
61 | int mid = s + e >> 1;
| ~~^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |