| Task: | Forest density |
| Sender: | aalto26dm_021 |
| Submission time: | 2026-09-21 16:59:16 +0300 |
| Language: | C++ (C++20) |
| Status: | READY |
| Result: | ACCEPTED |
| test | verdict | time | |
|---|---|---|---|
| #1 | ACCEPTED | 0.00 s | details |
| #2 | ACCEPTED | 0.11 s | details |
| #3 | ACCEPTED | 0.09 s | details |
Code
#include <bits/stdc++.h>
using namespace std;
// debug
template<class T> ostream& operator<<(ostream&, const vector<T>&);
template<class T> ostream& operator<<(ostream&, const set<T>&);
template<class T> ostream& operator<<(ostream&, const multiset<T>&);
template<class K, class V> ostream& operator<<(ostream&, const map<K, V>&);
template<class T, size_t N> ostream& operator<<(ostream&, const array<T, N>&);
template<class A, class B> ostream& operator<<(ostream& os, const pair<A, B>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
template<class T>
void print_collection(ostream& os, const T& v) {
os << "{";
bool first = true;
for (const auto& x : v) {
if (!first) os << ", ";
first = false;
os << x;
}
os << "}";
}
template<class T> ostream& operator<<(ostream& os, const vector<T>& v) { print_collection(os, v); return os; }
template<class T> ostream& operator<<(ostream& os, const set<T>& v) { print_collection(os, v); return os; }
template<class T> ostream& operator<<(ostream& os, const multiset<T>& v) { print_collection(os, v); return os; }
template<class K, class V> ostream& operator<<(ostream& os, const map<K, V>& v) { print_collection(os, v); return os; }
template<class T, size_t N> ostream& operator<<(ostream& os, const array<T, N>& v) { print_collection(os, v); return os; }
#define dbg(x) cerr << #x << " = " << (x) << '\n'
using ll = long long;
constexpr int INF = 1'000'000'000; // 1e9
constexpr ll LINF = 1'000'000'000'000'000'000LL; // 1e18
constexpr int MOD = 1'000'000'007; // 1e9 + 7
inline ll add(ll a, ll b) { return (a + b) % MOD; }
inline ll sub(ll a, ll b) { return ((a - b) % MOD + MOD) % MOD; }
inline ll mul(ll a, ll b) { return (a * b) % MOD; }
void solve() {
int n, q;
cin >> n >> q;
vector<vector<int>> x(n+1, vector<int>(n+1));
string s;
int sum;
for(int i=1;i<=n;++i) {
cin >> s;
sum = 0;
for(int j=1;j<=n;j++) {
if(s[j-1]=='*') {
sum++;
}
x[i][j] = x[i-1][j] + sum;
}
}
// cout << x;
int x1,x2,y1,y2;
for(int i=0; i<q;++i) {
cin >> y1 >>x1>>y2>>x2;
cout << x[y2][x2] - x[y2][x1-1] - x[y1-1][x2] + x[y1-1][x1-1] << "\n";
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}Test details
Test 1
Verdict: ACCEPTED
| input |
|---|
| 10 100 **.*.*.**. *.**.*..*. .*****.**. **....***. ... |
| correct output |
|---|
| 10 14 5 7 8 ... |
| user output |
|---|
| 10 14 5 7 8 ... |
Test 2
Verdict: ACCEPTED
| input |
|---|
| 1000 200000 **.**.****..**.***..**.***.**.... |
| correct output |
|---|
| 41079 2824 15631 1548 8483 ... |
| user output |
|---|
| 41079 2824 15631 1548 8483 ... |
Test 3
Verdict: ACCEPTED
| input |
|---|
| 1000 200000 ******************************... |
| correct output |
|---|
| 1000000 1000000 1000000 1000000 1000000 ... |
| user output |
|---|
| 1000000 1000000 1000000 1000000 1000000 ... |
