Submission #500599

# Submission time Handle Problem Language Result Execution time Memory
500599 2021-12-31T13:55:03 Z keta_tsimakuridze UFO (IZhO14_ufo) C++14
60 / 100
1185 ms 59196 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define pii pair<int,int>
using namespace std;
const int N = 1e6 + 5, mod = 1e9 + 7; // !
int t, root[N][2], tree[N * 8], le[N * 8], ri[N * 8], idx;
void build(int u,int l,int r) {
	if(l == r) {
		return;
	}
	le[u] = ++idx;
	ri[u] = ++idx;
	int mid = (l + r) / 2;
	build(le[u], l, mid);
	build(ri[u], mid + 1, r);
}
void upd(int u,int ind,int l,int r,int val) {
	if(l > ind || r < ind) return;
	if(l == r) {
		tree[u] = val;
		return;
	}
	int mid = (l + r) / 2;
	upd(le[u], ind, l, mid, val); upd(ri[u], ind, mid + 1, r, val);
	tree[u] = max(tree[le[u]], tree[ri[u]]);
}
int getL(int u,int l,int r,int val) {
	if(l == r) {
		if(tree[u] < val) return l + 1;
		return l;
	}
	int mid = (l + r) / 2;
	if(tree[le[u]] >= val) return getL(le[u], l, mid, val);
	return getL(ri[u], mid + 1, r, val);
}
int getR(int u,int l,int r,int val) {
	if(l == r) {
		if(tree[u] < val) return l - 1;
		return l;
	}
	int mid = (l + r) / 2;
	if(tree[ri[u]] < val) return getL(le[u], l, mid, val);
	return getL(ri[u], mid + 1, r, val);
}
main(){
	int n, m, r, k, p;
	cin >> n >> m >> r >> k >> p;
	vector<long long> a[n + 5];
	for(int i = 1; i <= n; i++) {
		root[i][0] = ++idx;
		a[i].resize(m + 1);
		build(root[i][0], 1, m);
		for(int j = 1; j <= m; j++) {
			cin >> a[i][j];
			upd(root[i][0], j,  1, m, a[i][j]);
		}
	}
	for(int j = 1; j <= m; j++) {
		root[j][1] = ++idx;
		build(root[j][1], 1, n);
		for(int i = 1; i <= n; i++) {
			upd(root[j][1], i, 1, n, a[i][j]);
		}
	}
	while(k--) {
		char c;
		int i, h;
		cin >> c >> i >> h;
		if(c == 'W' || c == 'E') {
			int cnt = 0;
			while(true) {
				cnt++;
				if(cnt > r) break;
				int x;
				if(c == 'W') x = getL(root[i][0], 1, m, h);
				else x = getR(root[i][0],  1, m, h);
				if(x == m + 1 || !x) break;
				a[i][x]--;
				upd(root[i][0], x, 1, m, a[i][x]);
				upd(root[x][1], i, 1, n, a[i][x]);
			}
		}
		else {
			int cnt = 0; 
			while(true) {
				cnt++;
				if(cnt > r) break;
				int x;
				if(c == 'N') x = getL(root[i][1], 1, n, h);
				else x = getR(root[i][1], 1, n, h);
				
				if(x == n + 1 || !x) break;
				a[x][i] --;
				upd(root[i][1], x, 1, n, a[x][i]);
				upd(root[x][0], i, 1, m, a[x][i]);
				
			}
		}
	}
	long long ans = 0;
	a[0].resize(m + 1);
	for(int i = 1; i <= n; i++) {
		for(int j = 1; j <= m; j++) {
			a[i][j] += a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
			if(i >= p && j >= p) ans = max(ans, a[i][j] + a[i - p][j - p] - a[i - p][j] - a[i][j - p]);
		}
	}
	cout << ans;

}

Compilation message

ufo.cpp:46:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   46 | main(){
      | ^~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 0 ms 332 KB Output isn't correct
3 Incorrect 2 ms 460 KB Output isn't correct
4 Incorrect 19 ms 972 KB Output isn't correct
5 Incorrect 120 ms 3512 KB Output isn't correct
6 Incorrect 338 ms 27768 KB Output isn't correct
7 Correct 739 ms 55988 KB Output is correct
8 Correct 632 ms 56004 KB Output is correct
9 Correct 845 ms 55796 KB Output is correct
10 Correct 825 ms 55920 KB Output is correct
11 Correct 771 ms 53812 KB Output is correct
12 Correct 833 ms 55944 KB Output is correct
13 Correct 1016 ms 59196 KB Output is correct
14 Correct 713 ms 53828 KB Output is correct
15 Incorrect 813 ms 56156 KB Output isn't correct
16 Correct 735 ms 53840 KB Output is correct
17 Incorrect 1185 ms 58900 KB Output isn't correct
18 Correct 676 ms 51500 KB Output is correct
19 Incorrect 809 ms 55876 KB Output isn't correct
20 Correct 1012 ms 51184 KB Output is correct