今天又是自闭的一天,看一下自闭之后能获得哪些新知识呢
vector<vector<int> > a;
int ans[maxn * maxn];
int main()
{
int n, m, d, q;
cin >> n >> m >> d >> q;
a = vector<vector<int> > (n + 1, vector<int> (m + 1));
return 0;
}
链接:https://ac.nowcoder.com/acm/contest/863/H
来源:牛客网
题目描述
经过挖土种植栽培,花开始长大了。现有n×m的花田,每朵花都有自己的漂亮值。现给你n,m和一个标准漂亮值d(大于等于d的是漂亮的花,小于d的是丑花),小明想要知道某个矩形内漂亮的花的个数是多少。
输入描述:
第一行分别为n,m,d,q,分别代表花田的长和宽,漂亮值和询问的次数。(1≤n×m≤1000000,1≤q≤100000)(1≤n×m≤1000000,1≤q≤100000)。 接下来n行,每行m个元素xi,jxi,j,表示为花田(0≤xi,j≤109)(0≤xi,j≤109)。 接下来q行,每行四个整数x1,y1,x2,y2x1,y1,x2,y2,分别表示一个矩形的左上角坐标(x1,y1)(x1,y1)和右下角坐标(x2,y2)(x2,y2)。(1≤x1≤x2≤n,1≤y1≤y2≤m)(1≤x1≤x2≤n,1≤y1≤y2≤m)
输出描述:
q行,每行一个数表示被询问的矩阵内漂亮的花的个数。
示例1
输入
3 3 3 2 1 2 3 2 1 5 4 3 2 1 2 2 3 2 1 3 3
输出
2 3
#include<algorithm>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <string>
#include <vector>
#include <cstdio>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define SZ(x) ((int)x.size())
#define rep(i,a,n) for (int i = a; i < n; ++i)
#define per(i,a,n) for (int i = n-1; i >= a; --i)
#define devil_may_cry ios::sync_with_stdio(false);
using namespace std;
//head
#define maxn 1010
//int a[maxn][maxn], b[maxn][maxn];
vector<vector<int> > a;
int ans[maxn * maxn];
int main()
{
int n, m, d, q;
cin >> n >> m >> d >> q;
a = vector<vector<int> > (n + 1, vector<int> (m + 1));
rep(i, 1, n + 1) rep(j, 1, m + 1)
{
cin >> a[i][j];
if(a[i][j] >= d) a[i][j] = 1;
else
a[i][j] = 0;
a[i][j] = a[i][j] + a[i - 1][j] + a[i][j - 1] - a[i - 1][j - 1];
}
rep(i, 0, q)
{
int x1, x2, y1, y2;
cin >> x1 >> y1 >> x2 >> y2;
ans[i] = a[x2][y2] - a[x1 - 1][y2] - a[x2][y1 - 1] + a[x1 - 1][y1 - 1];
}
rep(i, 0, q)
cout << ans[i] << endl;
return 0;
}