Submission #775874

# Submission time Handle Problem Language Result Execution time Memory
775874 2023-07-07T05:42:29 Z ttamx Ancient Books (IOI17_books) C++14
0 / 100
1 ms 340 KB
#include "books.h"
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N=1e6+5;

struct fenwick{
	ll t[N];
	void add(int i,ll v){
		while(i<N)t[i]+=v,i+=i&-i;
	}
	ll read(int i){
		ll res=0;
		while(i>0)res+=t[i],i-=i&-i;
		return res;
	}
}f;

long long minimum_walk(vector<int> p, int s){
	for(auto &x:p)x++;
	int n=p.size();
	ll ans=0;
	ll pos=0;
	ll lz=0;
	f.add(p[0],1);
	for(int i=1;i<n;i++){
		ll res=f.read(p[i]);
		if(res!=i){
			ans+=(i-pos)+(i-res);
			if(res<pos)lz=pos;
			else lz=0;
			pos=res;
		}
		f.add(p[i],1);
	}
	ans+=abs(pos-lz)+lz;
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB 3rd lines differ - on the 1st token, expected: '3304', found: '6858'
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Incorrect 0 ms 340 KB 3rd lines differ - on the 1st token, expected: '6', found: '8'
3 Halted 0 ms 0 KB -