Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // 변화하는 중간값
- #include <iostream>
- #include <cstring>
- #include <unordered_map>
- #include <fstream>
- #include <cstdio>
- #include <cmath>
- #include <ctime>
- #include <vector>
- #include <stack>
- #include <queue>
- #include <functional>
- #include <list>
- #include <deque>
- #include <numeric>
- #include <set>
- #include <climits>
- #include <utility>
- #include <map>
- #include <algorithm>
- #define INF 987654321
- #define MOD 1000000007
- using namespace std;
- typedef long long ll;
- typedef unsigned long long ull;
- inline int max( int x, int y ){ return x > y ? x : y ; }
- inline int min( int x, int y ){ return x < y ? x : y ; }
- inline ll max( ll x, ll y ){ return x > y ? x : y ; }
- inline ll min( ll x, ll y ){ return x < y ? x : y ; }
- inline ull max( ull x, ull y ){ return x > y ? x : y ; }
- inline ull min( ull x, ull y ){ return x < y ? x : y ; }
- int gcd( int a, int b ) { return b ? gcd( b , a%b ) : a; }
- struct RNG {
- int seed, a, b;
- RNG(int _a, int _b ) : a(_a), b(_b), seed(1983) {}
- int next() {
- int ret = seed;
- seed = ((seed*(long long)a)+b)%20090711;
- return ret;
- }
- };
- int main() {
- int TC, N, A, B, a, b, ans=0;
- scanf("%d", &TC);
- while( TC-- ){
- scanf("%d %d %d", &N, &A, &B);
- RNG rng(A,B);
- ans = 0;
- priority_queue<int, vector<int>, greater<int> >MinHeap;
- priority_queue<int, vector<int>, less<int> >MaxHeap;
- for( int i=0; i<N; ++i ){
- if( MaxHeap.size() == MinHeap.size() ){
- MaxHeap.push(rng.next());
- }else{
- MinHeap.push(rng.next());
- }
- if( !MinHeap.empty() && !MaxHeap.empty() && MaxHeap.top() > MinHeap.top() ){
- a = MaxHeap.top();
- b = MinHeap.top();
- MinHeap.pop(); MaxHeap.pop();
- MinHeap.push( a ); MaxHeap.push( b );
- }
- ans = ( ans + MaxHeap.top() )%20090711;
- }
- printf("%d\n", ans);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement