Submission
Status:
PPPPPP-PPP
Subtask/Task Score:
90/100
Score: 90
User: Nuttykub
Problemset: สำรวจอาเรย์ 2
Language: cpp
Time: 0.006 second
Submitted On: 2026-10-02 10:32:39
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int m, n;
cin >> m >> n;
vector<vector<int>> matrix(m, vector<int>(n));
for (auto &row : matrix)
for (auto &x : row) cin >> x;
int q;
cin >> q;
long long last = 0; // value used if the very first query is invalid
array<int, 4> ans = {0, 0, 0, 0};
while (q--) {
int a, b;
cin >> a >> b;
if (a >= 1 && a <= m && b >= 1 && b <= n)
last = matrix[a - 1][b - 1];
// else: reuse previous 'last'
if (last > 0) ans[0]++;
else if (last < 0) ans[1]++;
if (last % 2 == 0) ans[2]++; // works for negatives and 0
else ans[3]++;
}
for (int x : ans) cout << x << " ";
cout << "\n";
}