Submission #119138

#TimeUsernameProblemLanguageResultExecution timeMemory
119138tinjyuAncient Books (IOI17_books)C++14
50 / 100
154 ms16124 KiB
#include "books.h" #include <bits/stdc++.h> using namespace std; long long int tag[1000005]; int l[1000005],r[1000005]; long long int ans; long long minimum_walk(std::vector<int> p, int s) { int n=p.size(); int t=0; int far=0; for(int i=0;i<n;i++) { if(i==p[i])continue; ans+=abs(i-p[i]); if(i>p[i]) { if(p[i]<s && s<i) { tag[s-1]--; tag[s+1]++; } tag[p[i]]++; tag[i]--; } else { if(p[i]<s && s<i) { tag[s-1]--; tag[s+1]++; } tag[i]++; tag[p[i]]--; } } for(int i=s+1;i<n;i++)tag[i]+=tag[i-1]; int r=s; for(int i=n-1;i>=s;i--) { if(tag[i]!=0) { r=i+1; break; } } for(int i=s;i<r;i++) { if(tag[i]==0)ans+=2; } for(int i=s-1;i>=0;i--)tag[i]+=tag[i+1]; r=0; for(int i=0;i<=s;i++) { if(tag[i]!=0) { r=i-1; break; } } for(int i=0;i<r;i++) { if(tag[i]==0)ans+=2; } return ans; }

Compilation message (stderr)

books.cpp: In function 'long long int minimum_walk(std::vector<int>, int)':
books.cpp:9:6: warning: unused variable 't' [-Wunused-variable]
  int t=0;
      ^
books.cpp:10:6: warning: unused variable 'far' [-Wunused-variable]
  int far=0;
      ^~~
#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...