# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
102581 | nickyrio | UFO (IZhO14_ufo) | C++17 | 1501 ms | 153848 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
//
// main.cpp
// UFO
//
// Created by Nguyen E Ro on 3/26/19.
// Copyright © 2019 Nguyen E Ro. All rights reserved.
//
#include <iostream>
#include <vector>
using namespace std;
const int N = 1e6 + 10;
int n, m, r, k, p;
vector< vector<int> > a;
vector<int> temp;
int remain;
struct SegmentTreeMax {
vector<int> Max;
int n;
SegmentTreeMax(int n):n(n), Max(n * 4 + 10) {}
SegmentTreeMax() {}
void Reset(int n) {
this -> n = n;
Max.resize(n * 4 + 10);
}
void Update(int u, int val) { Update(1, 1, n, u, val); }
void FindFirst(int k) {
FindFirst(1, 1, n, k);
}
void FindLast(int k) {
FindLast(1, 1, n, k);
}
private:
void Update(int k, int l, int r, int u, int val) {
if (l == r) {
Max[k] = val;
return;
}
int m = (l + r) >> 1;
if (u <= m) Update(k << 1, l, m, u, val);
else Update(k << 1 | 1, m + 1, r, u, val);
Max[k] = max(Max[k << 1], Max[k << 1 | 1]);
}
void FindFirst(int k, int l, int r, int x) {
if (remain == 0 || Max[k] < x) return;
if (l == r) {
--remain;
temp.push_back(l);
return;
}
int m = (l + r) >> 1;
FindFirst(k << 1, l, m, x);
FindFirst(k << 1 | 1, m + 1, r, x);
}
void FindLast(int k, int l, int r, int x) {
if (remain == 0 || Max[k] < x) return;
if (l == r) {
--remain;
temp.push_back(l);
return;
}
int m = (l + r) >> 1;
FindLast(k << 1 | 1, m + 1, r, x);
FindLast(k << 1, l, m, x);
}
};
SegmentTreeMax Row[N], Col[N];
int main() {
cin >> m >> n >> r >> k >> p;
a.resize(m + 1);
for (int i = 1; i <= n; ++i) {
Col[i].Reset(m);
}
a[0].resize(n + 1);
for (int i = 1; i <= m; ++i) {
Row[i].Reset(n);
a[i].resize(n + 1);
for (int j = 1; j <= n; ++j) {
cin >> a[i][j];
Row[i].Update(j, a[i][j]);
Col[j].Update(i, a[i][j]);
}
}
for (int i = 0; i < k; ++i) {
char type;
int id, h;
cin >> type >> id >> h;
temp.clear();
remain = r;
if (type == 'W') {
Row[id].FindFirst(h);
for (int x : temp) {
--a[id][x];
Row[id].Update(x, a[id][x]);
Col[x].Update(id, a[id][x]);
}
}
if (type == 'E') {
Row[id].FindLast(h);
for (int x : temp) {
--a[id][x];
Row[id].Update(x, a[id][x]);
Col[x].Update(id, a[id][x]);
}
}
if (type == 'N') {
Col[id].FindFirst(h);
for (int x : temp) {
--a[x][id];
Row[x].Update(id, a[x][id]);
Col[id].Update(x, a[x][id]);
}
}
if (type == 'S') {
Col[id].FindLast(h);
for (int x : temp) {
--a[x][id];
Row[x].Update(id, a[x][id]);
Col[id].Update(x, a[x][id]);
}
}
}
for (int i = 1; i <= m; ++i) {
for (int j = 1; j <= n; ++j) {
a[i][j] += a[i][j - 1] + a[i - 1][j] - a[i - 1][j - 1];
}
}
int ans = 0;
for (int i = 1; i <= m - p + 1; ++i) {
for (int j = 1; j <= n - p + 1; ++j) {
int sum = a[i + p - 1][j + p - 1] - a[i + p - 1][j - 1] - a[i - 1][j + p - 1] + a[i - 1][j - 1];
ans = max(ans, sum);
}
}
cout << ans;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |