Cod sursa(job #1464595)

Utilizator andreey_047Andrei Maxim andreey_047 Data 23 iulie 2015 22:52:23
Problema Schi Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.83 kb
#include <fstream>
#define nmax 31000

using namespace std;
int a[nmax],AIB[nmax],N,v[nmax];
inline void Update(int poz , int x){
 for(int i = poz; i <= N; i+=(i&-i))
    AIB[i]+=x;
}
inline int Compute(int poz){
 int s = 0;
  for(int i = poz; i; i-=(i&-i))
    s+=AIB[i];
  return s;
}
int main(){
    int i,last,x,k;
    ifstream fin("schi.in");
    fin >> N;
    for(i = 1; i <= N; ++i)
        fin >> a[i];
    fin.close();
     i = N;

    while(i){
      last = Compute(a[i]);
      x = a[i] + last;
      k = a[i];
      while(last){
         last = Compute(x) - Compute(k);
         k = x;
         x += last;
      }
      v[x] = i;
      Update(x,1);
      --i;
    }
    ofstream fout("schi.out");
    for(i = 1; i <= N; ++i)
        fout << v[i] << '\n';
    fout.close();

    return 0;
}