Cod sursa(job #2926253)

Utilizator GasparAndreiGaspar Andrei GasparAndrei Data 17 octombrie 2022 14:47:44
Problema Order Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <fstream>
#include <queue>
#include <vector>
#include <algorithm>
#include <cstring>
#include <tuple>

using namespace std;
#define Inf 0x3f3f3f3f

ifstream cin("order.in");
ofstream cout("order.out");

int n;
int aint[1000005];

void build(int nod,int st,int dr){

    if(st == dr){
        aint[nod] = 1;
        return;
    }
    int mij = (st + dr) / 2;
    build(nod * 2,st,mij);
    build(nod * 2 + 1, mij + 1, dr);
    aint[nod] = aint[nod * 2] + aint[nod * 2 + 1];

}
void update(int nod,int st,int dr,int poz){

    if(st == dr){
        
        aint[nod] = 0;
        cout << st << ' ';

        return;

    }
    int mij = (st + dr) / 2; 
    if(aint[nod * 2] >= poz)
        update(nod * 2, st ,mij,poz);
    else
        update(nod * 2 + 1,mij + 1, dr,poz - aint[nod * 2]);

    aint[nod] = aint[nod * 2] + aint[nod * 2 + 1];


}

int main(){

    cin >> n;
    build(1,1,n);

    int poz = 1;
    for(int i = 1 ; i <= n ; ++i){

		poz = (poz + i - 1) % (n - i + 1) + 1;
		update(1,1,n,poz);
        poz--;
	

    }

    

 

    
    return 0;
}