Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. // 변화하는 중간값
  2.  
  3. #include <iostream>
  4. #include <cstring>
  5. #include <unordered_map>
  6. #include <fstream>
  7. #include <cstdio>
  8. #include <cmath>
  9. #include <ctime>
  10. #include <vector>
  11. #include <stack>
  12. #include <queue>
  13. #include <functional>
  14. #include <list>
  15. #include <deque>
  16. #include <numeric>
  17. #include <set>
  18. #include <climits>
  19. #include <utility>
  20. #include <map>
  21. #include <algorithm>
  22. #define INF 987654321
  23. #define MOD 1000000007
  24. using namespace std;
  25. typedef long long ll;
  26. typedef unsigned long long ull;
  27. inline int max( int x, int y ){ return x > y ? x : y ; }
  28. inline int min( int x, int y ){ return x < y ? x : y ; }
  29. inline ll max( ll x, ll y ){ return x > y ? x : y ; }
  30. inline ll min( ll x, ll y ){ return x < y ? x : y ; }
  31. inline ull max( ull x, ull y ){ return x > y ? x : y ; }
  32. inline ull min( ull x, ull y ){ return x < y ? x : y ; }
  33. int gcd( int a, int b ) { return b ? gcd( b , a%b ) : a; }
  34.  
  35. struct RNG {
  36. int seed, a, b;
  37. RNG(int _a, int _b ) : a(_a), b(_b), seed(1983) {}
  38. int next() {
  39. int ret = seed;
  40. seed = ((seed*(long long)a)+b)%20090711;
  41. return ret;
  42. }
  43. };
  44.  
  45. int main() {
  46.  
  47. int TC, N, A, B, a, b, ans=0;
  48.  
  49. scanf("%d", &TC);
  50. while( TC-- ){
  51. scanf("%d %d %d", &N, &A, &B);
  52. RNG rng(A,B);
  53. ans = 0;
  54. priority_queue<int, vector<int>, greater<int> >MinHeap;
  55. priority_queue<int, vector<int>, less<int> >MaxHeap;
  56. for( int i=0; i<N; ++i ){
  57. if( MaxHeap.size() == MinHeap.size() ){
  58. MaxHeap.push(rng.next());
  59. }else{
  60. MinHeap.push(rng.next());
  61. }
  62. if( !MinHeap.empty() && !MaxHeap.empty() && MaxHeap.top() > MinHeap.top() ){
  63. a = MaxHeap.top();
  64. b = MinHeap.top();
  65. MinHeap.pop(); MaxHeap.pop();
  66. MinHeap.push( a ); MaxHeap.push( b );
  67. }
  68. ans = ( ans + MaxHeap.top() )%20090711;
  69. }
  70. printf("%d\n", ans);
  71. }
  72. return 0;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement