Submission #119726

#TimeUTC-0UsernameProblemLanguageResultExecution timeMemory
1197262019-06-22 03:08:46thebesAncient Books (IOI17_books)C++14
100 / 100
483 ms176172 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MN = 1e6+6;
ll n, s, x, id[MN], l[MN], r[MN], a[MN], b[MN], aa[MN], bb[MN], nxt, ans, arr[MN], i, j, par[MN], dist[MN], L=1<<30, R, vs[MN];
vector<int> adj[MN], rev[MN];
deque<int> q;
void dfs(ll n){
ans += abs(arr[n]-n);
a[id[n]]=min(a[id[n]],n);
b[id[n]]=max(b[id[n]],n);
if(n<=s) aa[id[n]]=max(aa[id[n]],n);
if(n>=s) bb[id[n]]=min(bb[id[n]],n);
if(id[arr[n]]) return;
id[arr[n]]=id[n];
dfs(arr[n]);
}
ll minimum_walk(vector<int> p,int e){
n = p.size(); s = e+1;
for(i=0;i<n;i++) arr[i+1]=p[i]+1;
for(i=1;i<=n;i++){
a[i] = bb[i] = 1<<30;
if(!id[i]){
id[i] = ++nxt;
dfs(i);
}
}
 
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#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...