-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path24hsg9hnoi4.cpp
More file actions
53 lines (45 loc) · 1.08 KB
/
Copy path24hsg9hnoi4.cpp
File metadata and controls
53 lines (45 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int findLIS(vector<pair<int, int>> &cells) {
vector<int> dp;
for (auto &[row, col] : cells) {
auto it = upper_bound(dp.begin(), dp.end(), col);
if (it == dp.end()) {
dp.push_back(col);
} else {
*it = col;
}
}
return dp.size();
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N, M, Q, K;
cin >> N >> M >> Q >> K;
vector<vector<int>> grid(N, vector<int>(M));
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
cin >> grid[i][j];
}
}
vector<vector<pair<int, int>>> mgroup(K);
for (int i = 0; i < N; ++i) {
for (int j = 0; j < M; ++j) {
int val = grid[i][j] % K;
mgroup[val].emplace_back(i, j);
}
}
vector<int> results(K);
for (int i = 0; i < K; ++i) {
results[i] = findLIS(mgroup[i]);
}
while(Q--) {
int x;
cin >> x;
cout << results[x] << '\n';
}
return 0;
}