Submission #688221

# Submission time Handle Problem Language Result Execution time Memory
688221 2023-01-27T08:48:55 Z alexdd Permutation Recovery (info1cup17_permutation) C++17
10 / 100
1 ms 340 KB
#pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>
using namespace std;
int bucket_size;
int update_timer;
int n;
int q[70001];

struct bucket
{
    int sum;
    vector<int> v;
};
bucket gol;

vector<bucket> buckets;
void balance_buckets()///O(n)
{
    vector<int> ramas;
    for(int i=0;i<buckets.size();i++)
        for(int j=0;j<buckets[i].v.size();j++)
            ramas.push_back(buckets[i].v[j]);
    buckets.clear();
    for(int i=0;i<ramas.size();i+=bucket_size)
    {
        buckets.push_back(gol);
        int limit = ramas.size()-1;
        limit = min(limit, i+bucket_size-1);
        for(int j=i;j<=limit;j++)
        {
            buckets[buckets.size()-1].v.push_back(ramas[j]);
            buckets[buckets.size()-1].sum = buckets[buckets.size()-1].sum + q[ramas[j]];
        }
    }
}

void insereaza(int b, int poz, int ramas)///O(marimea bucketului in care inserez)
{
    buckets[b].sum = buckets[b].sum + q[poz];
    for(int i=0;i<buckets[b].v.size();i++)
    {
        if(ramas==0)
        {
            buckets[b].v.insert(buckets[b].v.begin()+i, poz);
            return;
        }
        ramas = ramas - q[buckets[b].v[i]];
    }
    buckets[b].v.insert(buckets[b].v.end(), poz);
}

int rez[70001];
signed main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cin>>n;
    bucket_size = sqrt(n);
    update_timer = sqrt(n);
    buckets.push_back(gol);
    int prec=0,ceva;
    for(int i=1;i<=n;i++)
    {
        cin>>q[i];
        ceva = q[i];
        q[i] = q[i] - prec;
        prec = ceva;

        int aux = q[i] - 1;
        int unde = 0;
        bool bl=0;
        for(int j=0;j<buckets.size();j++)
        {
            unde = j;
            if(aux - buckets[j].sum<=0)
            {
                bl=1;
                break;
            }
            aux = aux - buckets[j].sum;
        }
        insereaza(unde, i, aux);

        if(i<n && i%update_timer==0)
        {
            balance_buckets();
        }
    }

    int cate=0;
    for(int i=0;i<buckets.size();i++)
    {
        for(int j=0;j<buckets[i].v.size();j++)
        {
            cate++;
            rez[buckets[i].v[j]]=cate;
        }
    }
    for(int i=1;i<=n;i++)
        cout<<rez[i]<<" ";
    return 0;
}

Compilation message

permutation.cpp: In function 'void balance_buckets()':
permutation.cpp:20:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bucket>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   20 |     for(int i=0;i<buckets.size();i++)
      |                 ~^~~~~~~~~~~~~~~
permutation.cpp:21:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   21 |         for(int j=0;j<buckets[i].v.size();j++)
      |                     ~^~~~~~~~~~~~~~~~~~~~
permutation.cpp:24:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   24 |     for(int i=0;i<ramas.size();i+=bucket_size)
      |                 ~^~~~~~~~~~~~~
permutation.cpp: In function 'void insereaza(int, int, int)':
permutation.cpp:40:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     for(int i=0;i<buckets[b].v.size();i++)
      |                 ~^~~~~~~~~~~~~~~~~~~~
permutation.cpp: In function 'int main()':
permutation.cpp:71:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bucket>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   71 |         for(int j=0;j<buckets.size();j++)
      |                     ~^~~~~~~~~~~~~~~
permutation.cpp:70:14: warning: variable 'bl' set but not used [-Wunused-but-set-variable]
   70 |         bool bl=0;
      |              ^~
permutation.cpp:90:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<bucket>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   90 |     for(int i=0;i<buckets.size();i++)
      |                 ~^~~~~~~~~~~~~~~
permutation.cpp:92:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   92 |         for(int j=0;j<buckets[i].v.size();j++)
      |                     ~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -