题意:
给出N≤105个地毯,M≤106个人,人的编号是0→M−1
地毯由二元组描述,(a,b),a表示[0,a]是厚的,b为地毯的长度周期,地毯无限长
现在N个地毯摞在,人排一行,求被0→N个地毯厚的部分覆盖的人数
分析:
题目数据范围有误,实测应该是0≤a<b≤16
记录cnt[T][mod]:=周期为T余数为mod的厚部分毛毯个数
然后枚举一遍[0,M)暴力即可
代码:
//
// Created by TaoSama on 2015-12-12
// Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>
#include <cassert>
using namespace std;
#define pr(x) cout << #x << " = " << x << " "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int n, m, ans[N], cnt[20][20];
int main() {
#ifdef LOCAL
freopen("C:\\Users\\TaoSama\\Desktop\\in.txt", "r", stdin);
// freopen("C:\\Users\\TaoSama\\Desktop\\out.txt","w",stdout);
#endif
ios_base::sync_with_stdio(0);
int t; scanf("%d", &t);
while(t--) {
scanf("%d%d", &n, &m);
memset(cnt, 0, sizeof cnt);
memset(ans, 0, sizeof ans);
for(int i = 1; i <= n; ++i) {
int a, b; scanf("%d%d", &a, &b);
for(int j = 0; j < a; ++j) ++cnt[b][j];
}
for(int i = 0; i < m; ++i) {
int cur = 0;
for(int j = 1; j <= 16; ++j)
cur += cnt[j][i % j];
++ans[cur];
}
for(int i = 0; i <= n; ++i) printf("%d\n", ans[i]);
}
return 0;
}