[题目链接]

https://www.lydsy.com/JudgeOnline/problem.php?id=2751

[算法]

考虑k = 0的情况 , 根据乘法原理 :

Ans = (n * (n + 1) / 2) ^ m

那么 , 对于k > 0 , 只需将用一棵平衡树维护每个位置应减小的值即可

详见代码

时间复杂度 : O(NlogN)

[代码]

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int P = 1e9 + ; int n , m , k;
map<int , int> mp;
map< pair<int , int> , bool> existed; template <typename T> inline void chkmax(T &x,T y) { x = max(x,y); }
template <typename T> inline void chkmin(T &x,T y) { x = min(x,y); }
template <typename T> inline void read(T &x)
{
T f = ; x = ;
char c = getchar();
for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
for (; isdigit(c); c = getchar()) x = (x << ) + (x << ) + c - '';
x *= f;
}
inline int exp_mod(int a , int n)
{
int b = a , res = ;
while (n > )
{
if (n & ) res = 1ll * res * b % P;
b = 1ll * b * b % P;
n >>= ;
}
return res;
} int main()
{ read(n); read(m); read(k);
for (int i = ; i <= k; ++i)
{
int x , y;
read(x); read(y);
if (existed[make_pair(x , y)]) continue;
existed[make_pair(x , y)] = true;
mp[x] += y;
}
int cnt = (1ll * n * (n + ) >> ) % P ,
rest = m - (int)mp.size();
int ans = exp_mod(cnt , rest);
for (map<int , int> :: iterator it = mp.begin(); it != mp.end(); it++)
ans = (1ll * ans * ((cnt - it -> second % P) % P + P) % P) % P;
printf("%d\n" , ans); return ; }

[HAOI 2012] 容易题的更多相关文章

  1. 大暴力——[HAOI]2012音量调节

    题目:[HAOI]2012音量调节 描述: 问题描述 一个吉他手准备参加一场演出.他不喜欢在演出时始终使用同一个音量,所以他决定每一首歌之前他都要改变一次音量.在演出开始之前,他已经做好了一个列表,里 ...

  2. [HAOI 2012]音量调节

    Description 一个吉他手准备参加一场演出.他不喜欢在演出时始终使用同一个音量,所以他决定每一首歌之前他都要改变一次音量.在演出开始之前,他已经做好了一个列表,里面写着在每首歌开始之前他想要改 ...

  3. 【HAOI 2012】高速公路

    Problem Description \(Y901\) 高速公路是一条重要的交通纽带,政府部门建设初期的投入以及使用期间的养护费用都不低,因此政府在这条高速公路上设立了许多收费站. \(Y901\) ...

  4. 解题:HAOI 2012 道路

    题面 这题不开O2怎么过=.= 可能这种有关最短路的计数题做多了就有些感觉了...... 以每个点为基准跑出一张最短路图,然后对每个边$(u,v)$统计两个东西.一个$pre[u]$表示到达$u$这个 ...

  5. HAOI 2012 高速公路

    https://www.luogu.org/problem/show?pid=2221 题目描述 Y901高速公路是一条重要的交通纽带,政府部门建设初期的投入以及使用期间的养护费用都不低,因此政府在这 ...

  6. BZOJ 2749 HAOI 2012 外星人 数论 欧拉函数

    题意: 给出一个数,给出的形式是其分解质因数后,对应的质因数pi及其次数qi,问对这个数不停求phi,直至这个数变成1,需要多少次.(多组数据) 范围:pi <= 1e5,qi <= 1e ...

  7. BZOJ 2750 HAOI 2012 Road 高速公路 最短路

    题意: 给出一个有向图,求每条边有多少次作为最短路上的边(任意的起始点). 范围:n <= 1500, m <= 5005 分析: 一个比较容易想到的思路:以每个点作为起点,做一次SPFA ...

  8. [HAOI 2012] Road

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2750 [算法] 考虑计算每个点对每条边的贡献 对于每个点首先运行SPFA或Dijks ...

  9. [HAOI 2012] 外星人

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2749 [算法] 首先 , 每次对一个数x进行操作 , 只会使该数减少一个2的因子 那 ...

随机推荐

  1. 老司机找bug的十年心路历程

    一.码畜:靠编译器帮自己查语法错误 消灭笔误:编写适合程序猿的键盘练习 if (常量==变量或表达式) 使用goto接力超长的if,switch 连续的if还是if elseif 多个条件的组合:精心 ...

  2. Git学习0基础篇(下)

    server上的 Git - 协议 Git能够使用四种基本的协议传输资料:本地协议(Local).HTTP 协议.SSH(Secure Shell) 协议以及 Git 协议.眼下使用最普及的是 SSH ...

  3. 转: linux下的自动对时

    转自: http://www.cnblogs.com/vimmer/archive/2012/05/17/2505785.html 评注:date 命令格式为: date -s 2012-08-02 ...

  4. cucumber 使用资料

    1.cucumber reporting github:https://github.com/damianszczepanik/cucumber-reporting 配置:详细参考上述地址描述 a.添 ...

  5. ItelliJ IDEA开发工具使用—创建一个web项目

    转   http://blog.csdn.net/wangyang1354/article/details/50452806 最近想用IDEA编辑器开发,但是平时都用MyEclipse和eclipse ...

  6. 自己写的通过ADO操作mysql数据库

    #include <iostream> #include <windows.h> #include <atlstr.h> #import "c:\Prog ...

  7. 不错.net图片水印类

    using System; using System.Drawing; using System.Drawing.Imaging; using System.IO; using System.Draw ...

  8. Anyoffice -HTML5大赛 悦心(基于H5开发安卓音乐app)-项目总结

    项目在线演示地址:http://rose111.applinzi.com/ github 地址:欢迎star https://github.com/midoxinxin/YueX-Music 悦心,一 ...

  9. AMD单双桥时序简叙

    芯片组(双桥)时序 VBAT :RTC电路的供电3V(RTC电路有问题会导致没复位或不跑码等故障) RTCCLK :晶振起振给南桥提供32.768KHz频率(RTC电路有问题会导致没复位或不跑码等故障 ...

  10. Linux Kernel Maintainers

    http://en.wikipedia.org/wiki/Ingo_Molnár http://zh.wikipedia.org/wiki/英格·蒙內 Ingo Molnár Ingo Molnár, ...