[HAOI 2012] 容易題
阿新 • • 發佈:2019-03-16
!= 容易 nbsp space tps div code ble dig
[題目鏈接]
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; typedeflong long ll; typedef long double ld; typedef unsigned long long ull; const int P = 1e9 + 7; 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 voidchkmin(T &x,T y) { x = min(x,y); } template <typename T> inline void read(T &x) { T f = 1; x = 0; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == ‘-‘) f = -f; for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - ‘0‘; x *= f; } inlineint exp_mod(int a , int n) { int b = a , res = 1; while (n > 0) { if (n & 1) res = 1ll * res * b % P; b = 1ll * b * b % P; n >>= 1; } return res; } int main() { read(n); read(m); read(k); for (int i = 1; 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 + 1) >> 1) % 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 0; }
[HAOI 2012] 容易題