题意:

给定n,m
求满足:

  1.a[i][j]互不相同,且有$1<=a[i][j]<=n*m$

  2.对于$a[i1][j1],a[i2][j2]$,如果有 $i1 \oplus j1 > i2 \oplus j2$,则有$a[i1][j1] > a[i2][j2]$

的矩形个数,答案取余$10^9+7$

数据组数T<=1000,且n,m <= 1000

解法:

首先注意到我们只要根据$i \oplus j$分类,计算出$cnt(x)$表示$i \oplus j = x$的$i,j$对数。

这样有答案为$\sum_{i=0}^{1024}{cnt(x)!}$

1.(雾)对于每组数据循环i,j然后cnt[i^j]++;,因为 i^j 操作很快所以AC

2.每个询问是关于(n,m)的一个二元组,考虑对n莫队分块,这样复杂度$O(T*n* \sqrt{n} + 1024*T)$

3.考虑fwt,注意到cnt = id(n)*id(m),应用fwt卷积可以$O(T*nlogn)$

 \#include <iostream>
#include <cstdio>
#include <cstring>
#include <bitset>
#include <algorithm> #define N 1010
#define LL long long
#define P 1000000007LL using namespace std; struct node
{
int n,m,id;
}a[N]; LL fac[N*N];
LL ansv[N];
int cnt[],SIZE; bool cmp(node a,node b)
{
if((a.n-)/SIZE==(b.n-)/SIZE) return a.m<b.m;
return a.n<b.n;
} LL calc(int n,int m)
{
LL ans=;
for(int i=;i<=;i++)
ans=ans*fac[cnt[i]]%P;
return ans;
} int main()
{
int T;
scanf("%d",&T);
for(int i=;i<=T;i++)
{
scanf("%d%d",&a[i].n,&a[i].m);
a[i].id=i;
}
SIZE = ;
sort(a+,a+T+,cmp);
fac[]=1LL;
for(int i=;i<N*N;i++) fac[i]=fac[i-]*(LL)i%P;
int n=,m=;
for(int i=;i<=T;i++)
{
while(n<a[i].n)
{
n++;
for(int j=;j<=m;j++)
cnt[n^j]++;
}
while(n>a[i].n)
{
for(int j=;j<=m;j++)
cnt[n^j]--;
n--;
}
while(m<a[i].m)
{
m++;
for(int j=;j<=n;j++)
cnt[j^m]++;
}
while(m>a[i].m)
{
for(int j=;j<=n;j++)
cnt[j^m]--;
m--;
}
ansv[a[i].id] = calc(n,m);
}
for(int i=;i<=T;i++) cout << ansv[i] << endl;
return ;
}

wannafly test D的更多相关文章

  1. NowCoder Wannafly 27E 黄魔法师 构造

    原文链接https://www.cnblogs.com/zhouzhendong/p/NowCoder-Wannafly27E.html 题目传送门 - NowCoder Wannafly 27E 题 ...

  2. 牛客 Wannafly 挑战赛26D 禁书目录 排列组合 概率期望

    原文链接https://www.cnblogs.com/zhouzhendong/p/9781060.html 题目传送门 - NowCoder Wannafly 26D 题意 放一放这一题原先的题面 ...

  3. Wannafly挑战赛25游记

    Wannafly挑战赛25游记 A - 因子 题目大意: 令\(x=n!(n\le10^{12})\),给定一大于\(1\)的正整数\(p(p\le10000)\)求一个\(k\)使得\(p^k|x\ ...

  4. 2019 wannafly winter camp day 3

    2019 wannafly winter camp day 3 J 操作S等价于将S串取反,然后依次遍历取反后的串,每次加入新字符a,当前的串是T,那么这次操作之后的串就是TaT.这是第一次转化. 涉 ...

  5. 2019 wannafly winter camp

    2019 wannafly winter camp Name Rank Solved A B C D E F G H I J K day1 9 5/11 O O O O O day2 5 3/11 O ...

  6. Wannafly挑战赛27

    Wannafly挑战赛27 我打的第一场$Wannafly$是第25场,$T2$竟然出了一个几何题?而且还把我好不容易升上绿的$Rating$又降回了蓝名...之后再不敢打$Wannafly$了. 由 ...

  7. Wannafly 挑战赛 19 参考题解

    这一次的 Wannafly 挑战赛题目是我出的,除了第一题,剩余的题目好像对大部分算法竞赛者来说好像都不是特别友好,但是个人感觉题目质量还是过得去的,下面是题目链接以及题解. [题目链接] Wanna ...

  8. Wannafly挑战赛21A

    题目链接 Wannafly挑战赛21A 题解 代码 #include <cstdio> #include <cmath> #define MAX 1000005 #define ...

  9. Wannafly挑战赛24游记

    Wannafly挑战赛24游记 A - 石子游戏 题目大意: A和B两人玩游戏,总共有\(n(n\le10^4)\)堆石子,轮流进行一些操作,不能进行下去的人则输掉这局游戏.操作包含以下两种: 把石子 ...

  10. Wannafly挑战赛25C 期望操作数

    Wannafly挑战赛25C 期望操作数 简单题啦 \(f[i]=\frac{\sum_{j<=i}f[j]}{i}+1\) \(f[i]=\frac{f[i]}{i}+\frac{\sum_{ ...

随机推荐

  1. VM(转)

    vmplayer  &&  VMworkstation 很多人想尝试一下多种不同的操作系统,例如学习Linux:又或者希望搞一个专门的系统用来测试各种各样东西而不会搞乱搞坏现有的系统. ...

  2. javascript 高级编程系列 - 基本数据类型

    javascript中的基本数据类型包括: Undefined, Null, Boolean, Number, String 5种数据类型 1. Undefined 类型 (只有一个值 undefin ...

  3. java 回文字符串

    package string.string1_5; public class Palindrome { /** * 从两头向中间移动 * @param str * @return */ public ...

  4. PHP魔术方法之__call与__callStatic方法

    <?php class human{ private function t(){ } //魔术方法__call /* $method 获得方法名 $arg 获得方法的参数集合 */ public ...

  5. Python 008- 游戏2048

    #-*- coding:utf-8 -*- import curses from random import randrange, choice # generate and place new ti ...

  6. mysql中索引的使用

    索引是加速查询的主要手段,特别对于涉及多个表的查询更是如此.本节中,将介绍索引的作用.特点,以及创建和删除索引的语法. 使用索引优化查询 索引是快速定位数据的技术,首先通过一个示例来了解其含义及作用. ...

  7. ickeck插件

    地址:http://www.bootcss.com/p/icheck/#skins 使用 1. 先引入文件 css <link rel="stylesheet" type=& ...

  8. 对ShortCut和TWMKey的研究

    TWMKey = packed record Msg: Cardinal; CharCode: Word; Unused: Word; KeyData: Longint; Result: Longin ...

  9. Post Man 调用CRMAPI

    官方文档 https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/webapi/setup-postman ...

  10. Automating hybrid apps

    Automating hybrid apps One of the core principles of Appium is that you shouldn’t have to change you ...