Cod sursa(job #3285067)

Utilizator Carnu_EmilianCarnu Emilian Carnu_Emilian Data 12 martie 2025 14:59:23
Problema Curcubeu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fcin("curcubeu.in");
ofstream fcout("curcubeu.out");

const int N = 1e6 + 5;
int n, a, b, c, mx, mn;
vector<vector<pair<int, int>>> v(N);
multiset<pair<int, int>> m;
/**
2 1 3
4 2 1
2 1 3
3 4 2

3 3 2 2
*/
int main()
{
    fcin >> n >> a >> b >> c;
    mn = min(a, b);
    mx = max(a, b);
    v[mn].push_back({c, 1});
    v[mx + 1].push_back({-c, 1});
    for (int i = 2; i < n; i++)
    {
        a = (1ll * a * i) % n;
        b = (1ll * b * i) % n;
        c = (1ll * c * i) % n;
//        cout << a << ' ' << b << ' ' << c << endl;
        mn = min(a, b);
        mx = max(a, b);
        v[mn].push_back({c, i});
        v[mx + 1].push_back({-c, i});
    }
    for (int i = 1; i < n; i++)
    {
        for (pair<int, int> p : v[i])
        {
            if (p.second < 0)
                m.erase({p.first, -p.second});
            else
                m.insert(p);
        }
        int r;
        if (m.empty())
            r = 0;
        else
            r = m.rbegin()->second;
        fcout << r << '\n';
    }
    return 0;
}