이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
int N, A[1500][1500];
long long ft[1500][1501];
void update (int n, int x, long long v) {
x++;
while (x <= N) ft[n][x] += v, x += x & -x;
}
void update (int n, int a, int b, long long v) {
update(n,a,v); update(n,b+1,-v);
}
long long query (int n, int x) {
x++;
long long ans = 0;
while (x) ans += ft[n][x], x -= x & -x;
return ans;
}
long long f(int x, int y) {
long long ans = 0;
if (x != 0) ans = max(ans,query(x-1,y));
if (y != 0) ans = max(ans,query(x,y-1));
return ans + A[x][y];
}
int main() {
scanf("%d", &N);
memset(ft,0,sizeof(ft));
long long ans = 0;
for (int i = 0; i < N; ++i) for (int j = 0; j < N; ++j) {
scanf("%d", &A[i][j]);
long long val = f(i,j);
update(i,j,j,val);
ans += val;
}
printf("%lld\n", ans);
for (int a = 0; a < N; ++a) {
char c; int x,y; scanf(" %c %d %d", &c, &x, &y); x--, y--;
int v = c == 'U' ? 1 : -1, s = y, e = y+1;
A[x][y] += v, ans += v;
update(x,s,s,v);
while (e < N && f(x,e) != query(x,e)) update(x,e,e,v), e++, ans += v;
for (int i = x+1; i < N; ++i) {
while (s < e && f(i,s) == query(i,s)) s++;
update(i,s,e-1,v), ans += (e-s) * v;
while (e < N && f(i,e) != query(i,e)) update(i,e,e,v), e++, ans += v;
}
printf("%lld\n", ans);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
shell.cpp: In function 'int main()':
shell.cpp:31:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | scanf("%d", &N);
| ~~~~~^~~~~~~~~~
shell.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | scanf("%d", &A[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~
shell.cpp:42:31: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
42 | char c; int x,y; scanf(" %c %d %d", &c, &x, &y); x--, y--;
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |