이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int N = 1000100;
int t[N * 4], tadd[4 * N];
int operate(int a, int b) {
return a + b;
}
void push(int v, int vl, int vr) {
if (tadd[v] != 0) {
t[v] += tadd[v] * (vr - vl + 1);
if (vl != vr) {
tadd[2 * v + 1] += tadd[v];
tadd[2 * v + 2] += tadd[v];
}
tadd[v] = 0;
}
}
void update(int l, int r, int val, int v = 0, int vl = 0, int vr = N-1) {
push(v, vl, vr);
if (l > vr || vl > r)
return;
if (l <= vl && vr <= r) {
tadd[v] = val;
push(v, vl, vr);
return;
}
int vm = (vl + vr) >> 1;
update(l, r, val, 2 * v + 1, vl, vm);
update(l, r, val, 2 * v + 2, vm+1, vr);
t[v] = operate(t[2 * v + 1], t[2 * v + 2]);
}
int get(int l, int r, int v = 0, int vl = 0, int vr = N-1) {
push(v, vl, vr);
if (l > vr || r < vl)
return 0;
if (l <= vl && vr <= r)
return t[v];
int vm = (vl + vr) >> 1;
return operate(get(l, r, 2 * v + 1, vl, vm),
get(l, r, 2 * v + 2, vm+1, vr));
}
int main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int n, q;
cin >> n >> q;
int y[n];
for (int i = 0; i < n; i++) {
cin >> y[i];
if (i)
update(min(y[i], y[i-1]), max(y[i], y[i-1]), 1);
}
while (q --) {
int t;
cin >> t;
if (t == 1) {
int pos, val;
cin >> pos >> val;
pos--;
if (pos) update(min(y[pos], y[pos-1]), max(y[pos], y[pos-1]), -1);
if (pos+1<n) update(min(y[pos], y[pos+1]), max(y[pos], y[pos+1]), -1);
y[pos] = val;
if (pos) update(min(y[pos], y[pos-1]), max(y[pos], y[pos-1]), 1);
if (pos+1<n) update(min(y[pos], y[pos+1]), max(y[pos], y[pos+1]), 1);
} else {
int h;
cin >> h;
cout << get(h, h) << '\n';
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
game.cpp: In function 'int main()':
game.cpp:51:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
51 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
game.cpp:52:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
52 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |