Cod sursa(job #2449696)

Utilizator PatrickCplusplusPatrick Kristian Ondreovici PatrickCplusplus Data 20 august 2019 14:52:30
Problema Curcubeu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.26 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("curcubeu.in");
ofstream fout("curcubeu.out");
set <int> heap;
int n, q, ans[1000001], fr[1000001], a, b, c, id[1000001];
struct operatii
{
    vector <int> op;
}v[1000001];
bool cmp(int a, int b)
{
    return a > b;
}
int main()
{
    fin >> n >> a >> b >> c;
    v[a].op.push_back(1);
    v[b].op.push_back(-1);
    id[1] = c;
    for (int i = 2; i < n; ++i)
    {
        a = (a * i) % n;
        b = (b * i) % n;
        c = (c * i) % n;
        v[a].op.push_back(i);
        v[b].op.push_back(-i);
        id[i] = c;
    }
    for (int i = 1; i < n; ++i)
    {
        sort(v[i].op.begin(), v[i].op.end(), cmp);
    }
    for (int i = 1; i < n; ++i)
    {
        if (heap.size() > 0)
            if (ans[i] < *heap.rbegin())
                ans[i] = *heap.rbegin();
        for (int j = 0; j < v[i].op.size(); ++j)
        {
            if (v[i].op[j] > 0)
                heap.insert(v[i].op[j]);
            else
                heap.erase(abs(v[i].op[j]));
            if (heap.size() > 0)
                if (ans[i] < *heap.rbegin())
                    ans[i] = *heap.rbegin();
        }
    }
    for (int i = 1; i < n; ++i)
        fout << id[ans[i]] << "\n";
}