Cod sursa(job #2652231)

Utilizator Sho10Andrei Alexandru Sho10 Data 24 septembrie 2020 16:50:25
Problema Curcubeu Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 2.08 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[1000005],b[1000005],c[1000005],nxt[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[1]>>b[1]>>c[1];
if(a[1]>b[1]){
    swap(a[1],b[1]);
}
for(ll i=2;i<=n;i++)
{
    a[i]=(1ll*a[i-1]*i)%n;
    b[i]=(1ll*b[i-1]*i)%n;
    c[i]=(1ll*c[i-1]*i)%n;
    if(a[i]>b[i]){
        swap(a[i],b[i]);
    }
}
for(ll i=n-1;i>=1;i--)
{
    for(ll j=a[i];j<=b[i];){
        if(ans[j]==0){
            ans[j]=c[i];
            nxt[j]=b[i]+1;
            j++;
        }else j=nxt[j];
    }
}
for(ll i=1;i<n;i++)
{
    write(ans[i]);
}
}