Submission #404540

#TimeUsernameProblemLanguageResultExecution timeMemory
404540maomao90조개 줍기 (KOI17_shell)C++14
100 / 100
680 ms33156 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...