This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int H, W, D, K;
vector<pair<pair<int, int>, pair<int, int>>> v;
int bit[2000001];
int N;
int query(int i) {
int ii = i;
int res = 0;
while (i > 0) {
res += bit[i];
i -= (i & -i);
}
//cout << "query: " << ii << ": " << res << endl;
return res;
}
void update(int i, int x) {
while (i <= N) {
bit[i] += x;
i += (i & -i);
}
}
void update(int l, int r, int x) {
//cout << "update: " << l << " " << r << " " << x << endl;
update(l, x);
update(r + 1, -x);
}
int main() {
cin >> H >> W >> D >> K;
N = W + 2 * D;
string temp;
for (int i = 0; i < H; i++) {
cin >> temp;
for (int j = 0; j < W; j++) {
if (temp[j] == 'M') {
v.push_back({{i, 2}, {j + D + 1, j + D + 1}});
}
if (temp[j] == 'S') {
v.push_back({{i - D, 1}, {j + 1, j + 2 * D + 1}});
v.push_back({{i + D, 3}, {j + 1, j + 2 * D + 1}});
}
}
}
sort(v.begin(), v.end());
int ans = 0;
for (int i = 0; i < v.size(); i++) {
if (v[i].first.second == 2) {
int temp = query(v[i].second.first);
//cout << temp << endl;
if (temp >= K) {
ans++;
}
} else {
update(v[i].second.first, v[i].second.second, v[i].first.second == 3 ? -1 : 1);
}
}
cout << ans << endl;
return 0;
}
Compilation message (stderr)
mushrooms.cpp: In function 'int query(int)':
mushrooms.cpp:15:6: warning: unused variable 'ii' [-Wunused-variable]
15 | int ii = i;
| ^~
mushrooms.cpp: In function 'int main()':
mushrooms.cpp:58:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
58 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |