Pagini recente » Cod sursa (job #1714172) | Cod sursa (job #3150935) | Cod sursa (job #2469085) | Cod sursa (job #1444260) | Cod sursa (job #2708077)
#include <bits/stdc++.h>
using namespace std;
ifstream f("curcubeu.in");
ofstream g("curcubeu.out");
const int Max = 1e6 + 5;
void nos()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
}
int n,a,b,c;
struct eveniment
{
int timp, color;
};
struct timestamp
{
//bool color_start_here;
vector < eveniment > ev;
//bool color_end_here;
vector < int > time_end;
} drum[Max];
int timp;
void read()
{
f>>n>>a>>b>>c;
}
pair < int, int > ans;
void solve()
{
int i;
timp = 1;
int left = min(a,b);
int right = max(a,b);
//drum[left].color_start_here = true;
drum[left].ev.push_back({timp,c});
// drum[right+1].color_end_here = true;
drum[right+1].time_end.push_back(timp);
for(i=2; i<n; i++)
{
timp = i;
a = (1LL*a * i) % n;
b = (1LL*b * i) % n;
c = (1LL*c * i) % n;
int left = min(a,b);
int right = max(a,b);
// drum[left].color_start_here = true;
drum[left].ev.push_back({timp,c});
// drum[right+1].color_end_here = true;
drum[right+1].time_end.push_back(timp);
// cout<<a<<' '<<b<<' '<<c<<'\n';
}
// int current_color = 0;
priority_queue < pair < int, int > > incepute;
unordered_set < int > de_scos;
for(i=1; i<n; i++)
{
int this_ans = 0;
if(!drum[i].ev.empty())
{
// incepe o culoare noua
for(auto it : drum[i].ev)
incepute.push({it.timp,it.color});
}
if(!drum[i].time_end.empty())
{
for(auto it : drum[i].time_end)
de_scos.insert(it);
}
while(!incepute.empty() and de_scos.find(incepute.top().first)!=de_scos.end())
incepute.pop();
if(!incepute.empty())
this_ans = incepute.top().second;
else
this_ans = 0;
g<<this_ans<<'\n';
}
}
void restart()
{
}
int32_t main()
{
nos();
read();
solve();
restart();
return 0;
}