Submission #270521

# Submission time Handle Problem Language Result Execution time Memory
270521 2020-08-17T17:25:32 Z egekabas Permutation Recovery (info1cup17_permutation) C++14
0 / 100
4 ms 5760 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<ll, ll> pll;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
ll sq = 300;
ll mod = 2987623948576237;
ll n;
ll a[70009];
vector<pll> v[70009];
ll tot[70009];
unordered_map<ll, ll> val[70009];
void add(ll seg, ll idx, ll num){
    tot[seg] = (tot[seg]+a[num])%mod;
    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])%mod, num});
    if(idx+2 < v[seg].size())
        val[seg].erase(v[seg][idx+2].ff);
    val[seg][seg[v][idx+1].ff] = idx+2;
    for(int i = idx+2; i < v[seg].size(); ++i){
        if(i+1 < v[seg].size())
            val[seg].erase(v[seg][i+1].ff);   
        v[seg][i].ff = (a[v[seg][i].ss]+v[seg][i-1].ff)%mod;
        val[seg][v[seg][i].ff] = i+1;
        //cout << i << " -- " << v[seg][i].ff << '\n';

    }
}
void restruct(){
    vector<ll> tmp;
    for(ll 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(ll i = 0; i < tmp.size(); ++i)
        add(i/sq, v[i/sq].size()-1, tmp[i]);
}
ll 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(ll i = 1; i <= n; ++i){
        string s;
        cin >> s;
        for(auto u : s){
            a[i] = a[i]*10%mod;
            a[i] = (a[i]+u-'0')%mod;
        }
    }
    for(ll i = n; i >= 1; --i)
        a[i] = (a[i]-a[i-1]+mod)%mod;
    for(ll i = 1; i <= n; ++i){
        
        ll lookfor = a[i]-1;
        for(ll j = 0;; ++j){
            if(a[i] == 1 || val[j][lookfor]){
                add(j, val[j][lookfor]-1, i);
                if(v[j].size() == 2*sq)
                    restruct();
                
                break;
            }
            lookfor = (lookfor-tot[j]+mod)%mod;
            if(v[j].empty()) break;
        }
    }
    ll cur = 1;
    for(ll i = 0; v[i].size(); ++i)
        for(auto u : v[i])
            ans[u.ss] = cur++;
    for(ll i = 1; i <= n; ++i)
        cout << ans[i] << ' ';
}

Compilation message

permutation.cpp: In function 'void add(ll, ll, ll)':
permutation.cpp:28:14: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     if(idx+2 < v[seg].size())
      |        ~~~~~~^~~~~~~~~~~~~~~
permutation.cpp:31:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |     for(int i = idx+2; i < v[seg].size(); ++i){
      |                        ~~^~~~~~~~~~~~~~~
permutation.cpp:32:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |         if(i+1 < v[seg].size())
      |            ~~~~^~~~~~~~~~~~~~~
permutation.cpp: In function 'void restruct()':
permutation.cpp:49:21: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   49 |     for(ll i = 0; i < tmp.size(); ++i)
      |                   ~~^~~~~~~~~~~~
permutation.cpp: In function 'int main()':
permutation.cpp:77:32: warning: comparison of integer expressions of different signedness: 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   77 |                 if(v[j].size() == 2*sq)
      |                    ~~~~~~~~~~~~^~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 5760 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 5760 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 5760 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 5760 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 5760 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 5760 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 5760 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 5760 KB Output isn't correct