Pagini recente » Cod sursa (job #1027075) | Cod sursa (job #1382044) | Cod sursa (job #2586444) | Cod sursa (job #1384066) | Cod sursa (job #3127718)
#include<bits/stdc++.h>
using namespace std;
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
void ShowQueue(priority_queue<pair<int, pair<int, int>>> pq){
for(; !pq.empty(); pq.pop())
cout << pq.top().first << " " << pq.top().second.first << " " << pq.top().second.second+1 << "\n";
}
int main(){
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
int n, a, b, c;
fin >> n >> a >> b >> c;
unordered_map<int, queue<pair<int, pair<int, int>>>> mp;
if(a > b) swap(a, b);
mp[a-1].push(make_pair(0, make_pair(c, b-1)));
for(int i = 2; i < n; ++i){
a = (a*i)%n, b = (b*i)%n, c = (c*i)%n;
if(a > b) swap(a, b);
mp[a-1].push(make_pair(i-1, make_pair(c, b-1)));
//cout << "pushed " << i-1 << " " << c << " " << b << " on " << a << "\n";
}
// priority, value, end
priority_queue<pair<int, pair<int, int>>> pq;
for(int i = 0; i < n-1; ++i){
while(!pq.empty() && pq.top().second.second < i) pq.pop();
for(; !mp[i].empty(); mp[i].pop()) pq.push(mp[i].front());
//cout << "house " << i+1 << "\n";
//ShowQueue(pq);
//cout << "\n";
if(!pq.empty())
fout << pq.top().second.first << "\n";
else
fout << "0\n";
}
}