Cod sursa(job #612408)

Utilizator paul_gabryelPaul Buda paul_gabryel Data 7 septembrie 2011 14:42:14
Problema Order Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb

#include <cstdio>
#include <fstream>

using namespace std;

int n,sol,aib[30001],ct,p;

inline void up (int nd,int x){
	
	for(;nd<=n;nd+= nd& -nd)
		aib[nd]+=x;
	
	}
	
inline int query (int nd){
	
	int r=0;
	for(;nd;nd-= nd& -nd)
		r+=aib[nd];
	
	return r;}
	
inline int solve (int x){
	
	int i;
	for(ct=1;ct<=n;ct<<=1);
	for(i=-1;ct;ct>>=1)
		if(i+ct<n&&query(i+ct+1)<x)
			i+=ct;
	
	return ++i;}

int main ()
{
	
	int i;
	ifstream f ("order.in");
	freopen("order.out","w",stdout);
	f>>n;
	for(i=1;i<=n;++i)
		up(i,1);
	for(sol=1,i=0;i<n;++i){
		sol+=i;
		sol%=n-i;
		p=solve(sol+1)+1;
		if(i)
			printf(" ");
		printf("%d",p);
		up(p,-1);
		}
	
	return 0;}