Submission #790603

# Submission time Handle Problem Language Result Execution time Memory
790603 2023-07-22T22:39:30 Z FEDIKUS Ancient Books (IOI17_books) C++17
Compilation error
0 ms 0 KB
#include "books.h"
#include<bits/stdc++.h>
 
using ll = long long;
using namespace std;
 
const int maxn=1e6+10;
 
int n;
int mini[maxn];
int maxi[maxn];
bitset<maxn> bio;
int cale[maxn];
int mini[maxn];
int maxi[maxn];
int klk=0;
 
ll minimum_walk(vector<int> p, int s) {
	n=p.size();
	ll ret=0;
	int imal=n,imar=-1;
	for(int i=0;i<n;i++){
		if(p[i]!=i) imal=min(imal,i);
		if(p[i]!=i) imar=i;
		ret+=abs(p[i]-i);
		if(bio[i]) continue;
		int tren=i;
		mini[klk]=tren; maxi[klk]=tren;
		while(!bio[tren]){
			bio[tren]=true;
			cale[tren]=klk;
			mini[klk]=min(mini[klk],tren);
			maxi[klk]=max(maxi[klk],tren);
			tren=p[tren];
		}
		klk++;
	}
	imal=min(imal,s);
	imar=max(imar,s);
	int l=s,r=s;
	int tl=mini[cale[s]],tr=maxi[cale[s]];
	int dodaol=0,dodaor=0;
	while(l!=imal || r!=imar){
		bool pl=false,pr=false;
		if(l!=tl || r!=tr){
			if(l!=tl){
				l--;
				tl=min(tl,mini[cale[l]]);
				tr=max(tr,maxi[cale[l]]);
			}
			if(r!=tr){
				r++;
				tl=min(tl,mini[cale[r]]);
				tr=max(tr,maxi[cale[r]]);
			}
			continue;
		}

		while(l>imal && maxi[cale[l-1]]<=r){
			l--;
			if(l<tl){
				ret+=2;
				dodaol++;
			}
			tl=min(tl,mini[cale[l]]);
		}

		while(r<imar && mini[cale[r+1]]>=l){
			r++;
			if(r>tr){
				ret+=2;
				dodaor++;
			}
			tr=max(tr,maxi[cale[r]]);
		}

		if(l==imal && r==imar) break;
		
		ret-=2*max(dodaol-int(r>=tr),dodaor-int(l<=tl));
		l--;
		tl=min(tl,mini[cale[l]]);
		tr=max(tr,maxi[cale[l]]);
		dodaol=0;
		dodaor=0;
	}
	return ret;
}

Compilation message

books.cpp:14:5: error: redefinition of 'int mini [1000010]'
   14 | int mini[maxn];
      |     ^~~~
books.cpp:10:5: note: 'int mini [1000010]' previously declared here
   10 | int mini[maxn];
      |     ^~~~
books.cpp:15:5: error: redefinition of 'int maxi [1000010]'
   15 | int maxi[maxn];
      |     ^~~~
books.cpp:11:5: note: 'int maxi [1000010]' previously declared here
   11 | int maxi[maxn];
      |     ^~~~
books.cpp: In function 'll minimum_walk(std::vector<int>, int)':
books.cpp:44:8: warning: unused variable 'pl' [-Wunused-variable]
   44 |   bool pl=false,pr=false;
      |        ^~
books.cpp:44:17: warning: unused variable 'pr' [-Wunused-variable]
   44 |   bool pl=false,pr=false;
      |                 ^~