Submission #281797

# Submission time Handle Problem Language Result Execution time Memory
281797 2020-08-23T13:33:33 Z Atill83 Permutation Recovery (info1cup17_permutation) C++14
43 / 100
2638 ms 110040 KB
#include <bits/stdc++.h>
#define ff first
#define ss second
#define endl '\n'
using namespace std;
const long long INF = (long long) 1e18;
const int mod = (int) 1e9+7;
const int MAXN = (int) 3e5+5;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int n;
ll d[MAXN];
ll q[MAXN];
const int bs = 300;
map<int, int> mp[MAXN];
ll Dec[MAXN];
ll ans[MAXN];
ll del[MAXN];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);cout.tie(nullptr);

    #ifdef Local
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/int.txt","r",stdin);
        freopen("C:/Users/Admin/Desktop/Yazilim/C/IO/out.txt","w",stdout);
    #endif

    cin>>n;

    for(int i = 0; i < n; i++){
        string s;
        cin>>s;
        for(char c: s){
            int cur = c - '0';
            del[i] *= 10;
            del[i] += cur;
            del[i] %= mod;
        }
    }
    int bc = (n + bs - 1) / bs;
    for(int i = 0; i < bc; i++){
        for(int j = i*bs; j < min(n, (i + 1)*bs); j++){
            q[j] = del[j] - (j == 0 ? 0 : del[j - 1]) + mod;
            q[j] %= mod;
            mp[i][q[j]]++;
            //cerr<<q[j]<<endl;
        }
    }

    for(int i = 1; i <= n; i++){
        int curB = bc - 1;
        while(mp[curB][(1 + Dec[curB])%mod] == 0){
            curB--;
            //assert(curB != -1);
        }
        int idx = -1;
        for(int j = min(n - 1, (curB + 1)*bs - 1); j >= curB*bs; j--){
            if(ans[j]) continue;
            if(q[j] == (1 + Dec[curB])%mod){
                ans[j] = i;
                mp[curB].clear();
                idx = j;
                break;
            }
        }
        ll deg = 0;
        for(int j = bs*curB; j < min(bs*(curB + 1), n); j++){
            if(ans[j]){
                if(j == idx){ 
                    deg = del[j] - (j == 0 ? 0 : del[j - 1]) + mod;
                    deg %= mod;
                }
                continue;
            }
            q[j] -= deg;
            q[j] += mod;
            q[j] %= mod;
            mp[curB][q[j]]++;
        }
        for(int j = curB + 1; j < bc; j++){
            Dec[j] += deg;
        }
    }

    for(int i = 0; i < n; i++){
        cout<<ans[i]<<" ";
    }



    #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
    #endif
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 15 ms 14592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 15 ms 14592 KB Output is correct
3 Correct 25 ms 14592 KB Output is correct
4 Correct 22 ms 14592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 15 ms 14592 KB Output is correct
3 Correct 25 ms 14592 KB Output is correct
4 Correct 22 ms 14592 KB Output is correct
5 Runtime error 2638 ms 110040 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 15 ms 14592 KB Output is correct
3 Correct 25 ms 14592 KB Output is correct
4 Correct 22 ms 14592 KB Output is correct
5 Runtime error 2638 ms 110040 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 15 ms 14592 KB Output is correct
3 Correct 25 ms 14592 KB Output is correct
4 Correct 22 ms 14592 KB Output is correct
5 Runtime error 2638 ms 110040 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 15 ms 14592 KB Output is correct
3 Correct 25 ms 14592 KB Output is correct
4 Correct 22 ms 14592 KB Output is correct
5 Runtime error 2638 ms 110040 KB Execution killed with signal 11
# Verdict Execution time Memory Grader output
1 Correct 10 ms 14464 KB Output is correct
2 Correct 15 ms 14592 KB Output is correct
3 Correct 25 ms 14592 KB Output is correct
4 Correct 22 ms 14592 KB Output is correct
5 Runtime error 2638 ms 110040 KB Execution killed with signal 11