牛客網暑期ACM多校訓練營(第二場)farm

2021-08-22 12:06:41 字數 1674 閱讀 8212

時間限制:c/c++ 4秒,其他語言8秒

空間限制:c/c++ 262144k,其他語言524288k

64bit io format: %lld

the first line of input contains 3 integers n,m,t(n*m<=1000000,t<=1000000)

for the next n lines, each line contains m integers in range[1,n*m] denoting the type of plant in each grid.

for the next t lines, the i-th line contains 5 integers x1,y1,x2,y2,k(1<=x1<=x2<=n,1<=y1<=y2<=m,1<=k<=n*m)

print an integer, denoting the number of plants which would die.

示例1複製

2 2 2

1 22 3

1 1 2 2 2

2 1 2 1 1

複製

3
題意:白兔有乙個n *m 的藥田,裡面有不同種類的植物,每種植物只有被同種類的化肥施肥才不會死亡,否則就死去;白雲開始對藥田施肥,他一共施了t次肥,每次對左上角為(x1, y1),右下角為(x2+1, y2+1)的矩陣藥田施種類為i的化肥,問經過t次施肥後,有多少植物死去;

思路:看的別人的題解,先隨機雜湊1~1e6的數,之後處理維護二維字首和,就是在每次操作的區間內的格仔加上要施的化肥的種類,(這個用不用二維樹狀陣列感覺都行吧);然後我們遍歷整個藥田,假如說這個格仔內的植物每次施的都是同種類的化肥,那麼處理後的這個格仔內的和一定是這個植物隨機後的雜湊值的整數倍,否則就證明了這個格仔內被施了不同種類的化肥,統計一下就好了;

下面附上我的**:

#include#include#include#include#include#include#include#include#include#include#define ll long long

#define inf 0x3f3f3f3f

#define pi acos(-1.0)

#define lson o<<1

#define rson o<<1|1

using namespace std;

const int maxn = 1e6 + 10;

ll has[maxn];

vectora[maxn], sum[maxn];

int n, m , t;

ll x;

void hsh()

int lowbit(int x)

void add(int x, int y, ll v)

ll s(int x, int y)

int main()

} int x1, x2, y1, y2;

ll w;

for(int i = 0; i < t; i++)

int ans = 0;

for(int i = 1; i <= n; i++)

for(int j = 1; j <= m ;j++)

printf("%d\n", ans);

return 0;

}

牛客網暑期ACM多校訓練營(第二場)

a run 基礎dp,直接做就行了。dp時候求出來到哪個距離有幾種走法,然後求一下字首和。輸出答案的時候減一下就行了。include include include include include include include include using namespace std define ...

牛客網暑期ACM多校訓練營(第九場)

做法 看到下標 xor 這種情況就想 fwt 可是半天沒思路,於是放棄了。其實這個 n 瘋狂暗示啊。設未知數向量為 x 列一下方程組就可以發現有 b k sum a i x j 做法就顯然了吧,把 a 和 b 分別 fwt 對應相除然後反變換即可。表示前天才學的 fwt 就不會使了。include ...

牛客網暑期ACM多校訓練營(第五場)

二分答案,然後就轉化為是否滿足 frac d sum s i c i sum s i d sum s i c i d 0 顯然科目越少gpa越高,於是去掉最小的k個判斷即可。include define rep i,a,b for int i a i b i define per i,a,b for...