Submission #67799

#TimeUsernameProblemLanguageResultExecution timeMemory
67799yusufakePermutation Recovery (info1cup17_permutation)C++98
0 / 100
3 ms376 KiB
#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] ]-1, 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] = t+1; 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 (stderr)

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);
         ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...