Cod sursa(job #2708085)

Utilizator AACthAirinei Andrei Cristian AACth Data 18 februarie 2021 11:46:57
Problema Curcubeu Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.14 kb
#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;
    priority_queue < pair < int, int > > incepute;
    unordered_set < int > de_scos;
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;

    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())
        {
            de_scos.erase(incepute.top().first);
             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;
}