Cod sursa(job #2652214)

Utilizator Sho10Andrei Alexandru Sho10 Data 24 septembrie 2020 16:26:47
Problema Curcubeu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.16 kb
#include <bits/stdc++.h> //Andrei Alexandru a.k.a Sho10
#define ll long long
#define double long double
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#define all(a) (a).begin(), (a).end()
#define sz size
#define f first
#define s second
#define pb push_back
#define er erase
#define in insert
#define mp make_pair
#define pi pair
#define rc(s) return cout<<s,0
#define endl '\n'
#define mod 1000000007
#define PI 3.14159265359
#define MAXN 100005
#define INF 1000000005
#define LINF 1000000000000000005ll
#define CODE_START  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
ll n,a,b,c,l[1000005],r[1000005],nr[1000005],last[1000005],ans[1000005];

const int B = 4000000;
char outBuffer[B + 100]; unsigned int p;

__attribute__((always_inline)) void write(unsigned int x)
{
    unsigned int digits = x > 0x3B9AC9FF ? 0xA :
                 x > 0x5F5E0FF  ? 0x9 :
                 x > 0x98967F   ? 0x8 :
                 x > 0xF423F    ? 0x7 :
                 x > 0x1869F    ? 0x6 :
                 x > 0x270F     ? 0x5 :
                 x > 0x3E7      ? 0x4 :
                 x > 0x63       ? 0x3 :
                 x > 0x9        ? 0x2 : 0x1;

    for(unsigned int i = ~-digits; ~i; --i)
    {
        outBuffer[p + i] = x % 0xA + 0x30;

        x = x / 0xA;
    }

    p = p + digits;
    outBuffer[p++] = '\n';
    if (p > B)
    {
        puts(outBuffer);
        for (int i = 0; i <= p; i++)
        {
            outBuffer[i] = 0;
        }
        p = 0;
    }
}
int32_t main(){
CODE_START;
ifstream cin("curcubeu.in");
ofstream cout("curcubeu.out");
cin>>n>>a>>b>>c;
l[1]=min(a,b);
r[1]=max(a,b);
nr[1]=c;
last[1]=1;
for(ll i=2;i<n;i++)
{
    a*=1ll*i;
    a%=n;
    b*=1ll*i;
    b%=n;
    c*=1ll*i;
    c%=n;
    l[i]=min(a,b);
    r[i]=min(a,b);
    nr[i]=c;
    last[i]=i;
}
for(ll i=n-1;i>=1;i--)
{
    for(ll j=l[i];j<=r[i];j++)
    {
        if(ans[j]){
            ll x=last[j];
            last[j]=max(last[j],r[i]);
            j=x;
        }else {
        ans[j]=nr[i];
        last[j]=r[i];
    }
}
}
for(ll i=1;i<n;i++)
{
    write(ans[i]);
}
}