Cod sursa(job #3127718)

Utilizator PVDoriginalPopescu Vladut Daniel PVDoriginal Data 7 mai 2023 19:01:02
Problema Curcubeu Scor 20
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.47 kb
#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";
        }

    }