Submission #587495

# Submission time Handle Problem Language Result Execution time Memory
587495 2022-07-02T01:51:14 Z NekoRolly I want to be the very best too! (NOI17_pokemonmaster) C++17
51 / 100
91 ms 10316 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e4+4;

struct Bit{
	int n,t[N];

	void up(int i,int val){
		for (; i<=n; i+=i&-i) t[i] += val;
	}

	int que(int i){ int ans = 0;
		for (; i>0; i-=i&-i) ans += t[i];
		return ans;
	}
} d1;

int n,m,q;
vector<vector<int>> level,poke,vis;
bool use[N];
set<int> d2[N];

bool valid(int a,int b,int x){
	return 0 < a && a <= n && 0 < b && b <= m && !vis[a][b] && level[a][b] <= x;
}

void dfs(int a,int b,int x){ use[poke[a][b]] = vis[a][b] = 1;
	if (valid(a-1, b, x)) dfs(a-1, b, x);
	if (valid(a+1, b, x)) dfs(a+1, b, x);
	if (valid(a, b-1, x)) dfs(a, b-1, x);
	if (valid(a, b+1, x)) dfs(a, b+1, x);
}

void up(int x,int val,int f){
	if (d2[x].size()) d1.up(*d2[x].begin(), -1);
	if (f == 1) d2[x].insert(val);
	if (f == -1) d2[x].erase(val);
	if (d2[x].size()) d1.up(*d2[x].begin(), 1);
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin >> n >> m >> q;
	level.resize(n+1, vector<int> (m+1));
	poke.resize(n+1, vector<int> (m+1));
	vis.resize(n+1, vector<int> (m+1));

	for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) cin >> level[i][j];
	for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) cin >> poke[i][j];

	if (q <= 10){
		for (int t,a,b,x,ans; q; q--){ cin >> t >> b >> a >> x;
			if (t == 1) poke[a][b] = x;
			if (t == 2){ ans = 0;
				for (int i=1; i<N; i++) use[i] = 0;
				for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) vis[i][j] = 0;
				if (level[a][b] <= x) dfs(a, b, x);
				for (int i=1; i<N; i++) ans += use[i], use[i] = 0;
				cout << ans << "\n";
			}
		}
	}
	else if (n == 1){ d1.n = m;
		for (int i=1; i<=m; i++) d2[poke[1][i]].insert(i);
		for (int i=1; i<N; i++) if (d2[i].size()) d1.up(*d2[i].begin(), 1);

		for (int t,a,b,x,ans; q; q--){ cin >> t >> b >> a >> x;
			if (t == 1){ up(poke[a][b], b, -1);
				up(poke[a][b] = x, b, 1);
			}
			if (t == 2) cout << (b <= x ? d1.que(min(x, m)) : 0) << "\n";
		}
	}

    return 0;
}

Compilation message

pokemonmaster.cpp: In function 'void dfs(int, int, int)':
pokemonmaster.cpp:28:58: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
   28 | void dfs(int a,int b,int x){ use[poke[a][b]] = vis[a][b] = 1;
pokemonmaster.cpp: In function 'int main()':
pokemonmaster.cpp:69:20: warning: unused variable 'ans' [-Wunused-variable]
   69 |   for (int t,a,b,x,ans; q; q--){ cin >> t >> b >> a >> x;
      |                    ^~~
# Verdict Execution time Memory Grader output
1 Correct 17 ms 6536 KB Output is correct
2 Correct 22 ms 6848 KB Output is correct
3 Correct 19 ms 6856 KB Output is correct
4 Correct 18 ms 6800 KB Output is correct
5 Correct 21 ms 6868 KB Output is correct
6 Correct 19 ms 6936 KB Output is correct
7 Correct 19 ms 6720 KB Output is correct
8 Correct 21 ms 6816 KB Output is correct
9 Correct 18 ms 6708 KB Output is correct
10 Correct 19 ms 6968 KB Output is correct
11 Correct 28 ms 6884 KB Output is correct
12 Correct 20 ms 6948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 7668 KB Output is correct
2 Correct 15 ms 7096 KB Output is correct
3 Correct 13 ms 7220 KB Output is correct
4 Correct 18 ms 9196 KB Output is correct
5 Correct 21 ms 10240 KB Output is correct
6 Correct 24 ms 10316 KB Output is correct
7 Correct 18 ms 6164 KB Output is correct
8 Correct 16 ms 5708 KB Output is correct
9 Correct 16 ms 5716 KB Output is correct
10 Correct 17 ms 5928 KB Output is correct
11 Correct 19 ms 5640 KB Output is correct
12 Correct 16 ms 5500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 64 ms 8420 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 17 ms 6536 KB Output is correct
2 Correct 22 ms 6848 KB Output is correct
3 Correct 19 ms 6856 KB Output is correct
4 Correct 18 ms 6800 KB Output is correct
5 Correct 21 ms 6868 KB Output is correct
6 Correct 19 ms 6936 KB Output is correct
7 Correct 19 ms 6720 KB Output is correct
8 Correct 21 ms 6816 KB Output is correct
9 Correct 18 ms 6708 KB Output is correct
10 Correct 19 ms 6968 KB Output is correct
11 Correct 28 ms 6884 KB Output is correct
12 Correct 20 ms 6948 KB Output is correct
13 Correct 58 ms 8460 KB Output is correct
14 Correct 86 ms 8628 KB Output is correct
15 Correct 86 ms 8456 KB Output is correct
16 Correct 91 ms 8284 KB Output is correct
17 Correct 80 ms 8624 KB Output is correct
18 Correct 55 ms 8836 KB Output is correct
19 Correct 71 ms 8428 KB Output is correct
20 Correct 77 ms 8552 KB Output is correct
21 Correct 66 ms 8428 KB Output is correct
22 Correct 75 ms 8592 KB Output is correct
23 Correct 75 ms 8584 KB Output is correct
24 Correct 69 ms 8632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 6536 KB Output is correct
2 Correct 22 ms 6848 KB Output is correct
3 Correct 19 ms 6856 KB Output is correct
4 Correct 18 ms 6800 KB Output is correct
5 Correct 21 ms 6868 KB Output is correct
6 Correct 19 ms 6936 KB Output is correct
7 Correct 19 ms 6720 KB Output is correct
8 Correct 21 ms 6816 KB Output is correct
9 Correct 18 ms 6708 KB Output is correct
10 Correct 19 ms 6968 KB Output is correct
11 Correct 28 ms 6884 KB Output is correct
12 Correct 20 ms 6948 KB Output is correct
13 Correct 20 ms 7668 KB Output is correct
14 Correct 15 ms 7096 KB Output is correct
15 Correct 13 ms 7220 KB Output is correct
16 Correct 18 ms 9196 KB Output is correct
17 Correct 21 ms 10240 KB Output is correct
18 Correct 24 ms 10316 KB Output is correct
19 Correct 18 ms 6164 KB Output is correct
20 Correct 16 ms 5708 KB Output is correct
21 Correct 16 ms 5716 KB Output is correct
22 Correct 17 ms 5928 KB Output is correct
23 Correct 19 ms 5640 KB Output is correct
24 Correct 16 ms 5500 KB Output is correct
25 Incorrect 64 ms 8420 KB Output isn't correct
26 Halted 0 ms 0 KB -