Submission #270573

# Submission time Handle Problem Language Result Execution time Memory
270573 2020-08-17T18:40:25 Z egekabas Permutation Recovery (info1cup17_permutation) C++14
25 / 100
7 ms 5888 KB
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ull, ull> pll;
typedef pair<ull, ull> pull;
typedef pair<ull, ull> pii;
typedef pair<ld, ld> pld;
ull sq = 100;
ull n;
ull a[70009];
vector<pll> v[70009];
ull tot[70009];
unordered_map<ull, ull> val[70009];
void add(ull seg, ull idx, ull num){
    tot[seg] = tot[seg]+a[num];

    if(idx == -1)
        v[seg].insert(v[seg].begin()+idx+1, {a[num], num});
    else
        v[seg].insert(v[seg].begin()+idx+1, {(seg[v][idx].ff+a[num]), num});
    for(ull i = idx+2; i < v[seg].size(); ++i)
        val[seg].erase(v[seg][i].ff);      
    val[seg][seg[v][idx+1].ff] = idx+2;
    for(ull i = idx+2; i < v[seg].size(); ++i){
        v[seg][i].ff = (a[v[seg][i].ss]+v[seg][i-1].ff);
        val[seg][v[seg][i].ff] = i+1;
        //cout << i << " -- " << v[seg][i].ff << '\n';
    
    }
}
void restruct(){
    vector<ull> tmp;
    for(ull i = 0; v[i].size(); ++i){
        val[i].clear();
        for(auto u : v[i])
            tmp.pb(u.ss);
        v[i].clear();
        tot[i] = 0;
    }
    for(ull i = 0; i < tmp.size(); ++i)
        add(i/sq, v[i/sq].size()-1, tmp[i]);
}
ull ans[70009];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n;
    for(ull i = 1; i <= n; ++i){
        string s;
        cin >> s;
        for(auto u : s){
            a[i] = a[i]*10;
            a[i] += u-'0';
        }
    }
    for(ull i = n; i >= 1; --i){
        a[i] = a[i]-a[i-1];
    }
    for(ull i = 1; i <= n; ++i){
        ull lookfor = a[i]-1;
        for(ull j = 0;; ++j){
            if(a[i] == 1 || val[j][lookfor]){
                add(j, val[j][lookfor]-1, i);
                break;
            }
            lookfor = lookfor-tot[j];
            if(v[j].empty()) break;
        }
        if(i%sq == 0)
            restruct();
    }
    ull cur = 1;
    for(ull i = 0; v[i].size(); ++i)
        for(auto u : v[i])
            ans[u.ss] = cur++;
    for(ull i = 1; i <= n; ++i)
        cout << ans[i] << ' ';
}

Compilation message

permutation.cpp: In function 'void add(ull, ull, ull)':
permutation.cpp:24:12: warning: comparison of integer expressions of different signedness: 'ull' {aka 'long long unsigned int'} and 'int' [-Wsign-compare]
   24 |     if(idx == -1)
      |        ~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5760 KB Output is correct
2 Correct 7 ms 5888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5760 KB Output is correct
2 Correct 7 ms 5888 KB Output is correct
3 Incorrect 5 ms 5888 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5760 KB Output is correct
2 Correct 7 ms 5888 KB Output is correct
3 Incorrect 5 ms 5888 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5760 KB Output is correct
2 Correct 7 ms 5888 KB Output is correct
3 Incorrect 5 ms 5888 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5760 KB Output is correct
2 Correct 7 ms 5888 KB Output is correct
3 Incorrect 5 ms 5888 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5760 KB Output is correct
2 Correct 7 ms 5888 KB Output is correct
3 Incorrect 5 ms 5888 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5760 KB Output is correct
2 Correct 7 ms 5888 KB Output is correct
3 Incorrect 5 ms 5888 KB Output isn't correct
4 Halted 0 ms 0 KB -