# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
404540 |
2021-05-14T14:55:54 Z |
maomao90 |
None (KOI17_shell) |
C++14 |
|
680 ms |
33156 KB |
#include <bits/stdc++.h>
using namespace std;
#define mnto(x, y) x = min(x, (__typeof__(x)) y)
#define mxto(x, y) x = max(x, (__typeof__(x)) y)
#define REP(i, s, e) for (int i = s; i < e; i++)
#define RREP(i, s, e) for (int i = s; i >= e; i--)
typedef long long ll;
typedef long double ld;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(_a) _a.begin(), _a.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ii> vii;
#define INF 1000000005
#define LINF 1000000000000000005
#define MOD 1000000007
#define MAXN 1505
int n;
int a[MAXN][MAXN];
ll ans;
ll fw[MAXN][MAXN];
ll query(int i, int j) {
if (i == 0 || j == 0) return 0;
ll res = 0;
for (; j > 0; j -= (j & -j)) res += fw[i][j];
return res;
}
void incre(int i, int j, int v) {
for (; j <= n; j += (j & -j)) fw[i][j] += v;
}
void incre(int i, int j, int k, int v) {
incre(i, j, v); incre(i, k + 1, -v);
}
bool change(int i, int j) {
if (max(query(i - 1, j), query(i, j - 1)) + a[i][j] != query(i, j)) {
return 1;
} else {
return 0;
}
}
void walk(int i, int l, int r, int mult) {
if (i > n) return;
while (l < r && !change(i, l)) {
l++;
}
incre(i, l, r - 1, mult);
ans += (r - l) * mult;
while (r <= n && change(i, r)) {
incre(i, r, r, mult);
ans += mult;
r++;
}
if (l == r) return;
walk(i + 1, l, r, mult);
}
int main() {
scanf("%d", &n);
REP (i, 1, n + 1) {
REP (j, 1, n + 1) {
scanf("%d", &a[i][j]);
}
}
REP (i, 1, n + 1) {
REP (j, 1, n + 1) {
ll v = max(query(i - 1, j), query(i, j - 1)) + a[i][j];
incre(i, j, j, v);
ans += v;
}
}
printf("%lld\n", ans);
REP (i, 0, n) {
char o; int r, c; scanf(" %c%d%d", &o, &r, &c);
int mult = o == 'D' ? -1 : 1;
a[r][c] += mult;
walk(r, c, c + 1, mult);
printf("%lld\n", ans);
}
return 0;
}
/*
3
3 2 7
4 2 6
5 3 8
U 1 2
D 3 2
U 1 2
*/
Compilation message
shell.cpp: In function 'int main()':
shell.cpp:70:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
70 | scanf("%d", &n);
| ~~~~~^~~~~~~~~~
shell.cpp:73:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | scanf("%d", &a[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~
shell.cpp:85:26: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
85 | char o; int r, c; scanf(" %c%d%d", &o, &r, &c);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1228 KB |
Output is correct |
2 |
Correct |
2 ms |
1228 KB |
Output is correct |
3 |
Correct |
3 ms |
1228 KB |
Output is correct |
4 |
Correct |
3 ms |
1208 KB |
Output is correct |
5 |
Correct |
3 ms |
1228 KB |
Output is correct |
6 |
Correct |
3 ms |
1228 KB |
Output is correct |
7 |
Correct |
3 ms |
1228 KB |
Output is correct |
8 |
Correct |
2 ms |
1228 KB |
Output is correct |
9 |
Correct |
3 ms |
1228 KB |
Output is correct |
10 |
Correct |
2 ms |
1228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
270 ms |
31212 KB |
Output is correct |
2 |
Correct |
271 ms |
31196 KB |
Output is correct |
3 |
Correct |
274 ms |
31140 KB |
Output is correct |
4 |
Correct |
263 ms |
31216 KB |
Output is correct |
5 |
Correct |
280 ms |
31172 KB |
Output is correct |
6 |
Correct |
269 ms |
31196 KB |
Output is correct |
7 |
Correct |
273 ms |
31300 KB |
Output is correct |
8 |
Correct |
272 ms |
31176 KB |
Output is correct |
9 |
Correct |
266 ms |
31164 KB |
Output is correct |
10 |
Correct |
269 ms |
31208 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1228 KB |
Output is correct |
2 |
Correct |
2 ms |
1228 KB |
Output is correct |
3 |
Correct |
3 ms |
1228 KB |
Output is correct |
4 |
Correct |
3 ms |
1208 KB |
Output is correct |
5 |
Correct |
3 ms |
1228 KB |
Output is correct |
6 |
Correct |
3 ms |
1228 KB |
Output is correct |
7 |
Correct |
3 ms |
1228 KB |
Output is correct |
8 |
Correct |
2 ms |
1228 KB |
Output is correct |
9 |
Correct |
3 ms |
1228 KB |
Output is correct |
10 |
Correct |
270 ms |
31212 KB |
Output is correct |
11 |
Correct |
271 ms |
31196 KB |
Output is correct |
12 |
Correct |
274 ms |
31140 KB |
Output is correct |
13 |
Correct |
263 ms |
31216 KB |
Output is correct |
14 |
Correct |
280 ms |
31172 KB |
Output is correct |
15 |
Correct |
269 ms |
31196 KB |
Output is correct |
16 |
Correct |
273 ms |
31300 KB |
Output is correct |
17 |
Correct |
272 ms |
31176 KB |
Output is correct |
18 |
Correct |
266 ms |
31164 KB |
Output is correct |
19 |
Correct |
269 ms |
31208 KB |
Output is correct |
20 |
Correct |
2 ms |
1228 KB |
Output is correct |
21 |
Correct |
325 ms |
31412 KB |
Output is correct |
22 |
Correct |
300 ms |
31508 KB |
Output is correct |
23 |
Correct |
321 ms |
31296 KB |
Output is correct |
24 |
Correct |
622 ms |
31508 KB |
Output is correct |
25 |
Correct |
579 ms |
32404 KB |
Output is correct |
26 |
Correct |
587 ms |
32388 KB |
Output is correct |
27 |
Correct |
271 ms |
31116 KB |
Output is correct |
28 |
Correct |
300 ms |
31216 KB |
Output is correct |
29 |
Correct |
299 ms |
32952 KB |
Output is correct |
30 |
Correct |
295 ms |
33048 KB |
Output is correct |
31 |
Correct |
588 ms |
33088 KB |
Output is correct |
32 |
Correct |
680 ms |
33156 KB |
Output is correct |
33 |
Correct |
282 ms |
31140 KB |
Output is correct |
34 |
Correct |
270 ms |
31160 KB |
Output is correct |