답안 #67804

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
67804 2018-08-15T10:05:42 Z yusufake Permutation Recovery (info1cup17_permutation) C++
25 / 100
4 ms 560 KB
#include<bits/stdc++.h> 
using namespace std; 

#define pb push_back
typedef long long ll; 
typedef pair < int , int > pp; 
const int mod = 1e9 + 7; 
const int N   = 2e5 + 5; 

ll pri[N],sz[N],s[N],lz[N],L[N],R[N],A[N],ans[N];

void put(int x){
    if(!x) return;
    lz[x] = 1 - lz[x];
    swap(L[x],R[x]);
}
void push(int x){
    if(!lz[x]) return;
    lz[x] = 0;
    put(L[x]); put(R[x]);
}
void relax(int x){ 
    sz[x] = sz[ L[x] ] + sz[ R[x] ] + 1; 
    s[x] = s[ L[x] ] + s[ R[x] ] + A[x];    
}
int mrg(int x, int y){
    if(!x) return y;
    if(!y) return x;
    if(pri[x] < pri[y]){
        push(y);
        L[y] = mrg(x,L[y]);
        relax(y);
        return y;
    }
    else{
        push(x);
        R[x] = mrg(R[x],y);
        relax(x);
        return x;
    }
}

void split(int x, ll k, int &a, int &b){
    if(x == 0){
        a = b = 0;
        return;
    }
    push(x);
    if(k <= s[ L[x] ]){
        split(L[x], k, a, b);
        L[x] = b;
        b = x;
    }
    else{
        split(R[x], k-s[ L[x] ]-A[x], a, b);
        R[x] = a;
        a = x;
    }
    relax(x);    
}    


void f(int x, int h){
    if(x==0) return;
    push(x);
    f(L[x],h); ans[x] = h+sz[ L[x] ]+1; f(R[x],h+sz[ L[x] ]+1);
}    

int main(){
    ll n,i,x,y=0,t;
    scanf("%lld",&n);
    int a,b,root = 0;
    srand(time(NULL));
    for(i=1;i<=n;i++){
        scanf("%lld",&x);
        t = x-y-1;
        split(root, t, a, b);
        sz[i] = 1;
        pri[i] = rand();
        s[i] = A[i] = x-y;
        root = mrg( mrg(a,i) , b );
        y = x;
    }
    
    f(root,0);
    for(i=1;i<=n;i++) printf("%lld ",ans[i]);
    return 0;
}    

Compilation message

permutation.cpp: In function 'int main()':
permutation.cpp:71:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%lld",&n);
     ~~~~~^~~~~~~~~~~
permutation.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld",&x);
         ~~~~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 380 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 380 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Incorrect 3 ms 560 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 380 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Incorrect 3 ms 560 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 380 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Incorrect 3 ms 560 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 380 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Incorrect 3 ms 560 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 380 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Incorrect 3 ms 560 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 380 KB Output is correct
2 Correct 3 ms 484 KB Output is correct
3 Incorrect 3 ms 560 KB Output isn't correct
4 Halted 0 ms 0 KB -