답안 #1029171

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1029171 2024-07-20T13:27:59 Z amirhoseinfar1385 고대 책들 (IOI17_books) C++17
50 / 100
123 ms 60756 KB
#include"books.h"
#include <vector>
#include<bits/stdc++.h>
const long long maxn=1000000+10;
using namespace std;
long long vis[maxn],visa[maxn],all[maxn],av[maxn],tr[maxn];
long long n;
long long mainres=0,last=0;
vector<pair<long long,pair<long long,long long>>>alle;

struct dsu{
	long long par[maxn];
	dsu(){
		for(long long i=0;i<maxn;i++){
			par[i]=i;
		}
	}
	void clear(){
		for(long long i=0;i<maxn;i++){
			par[i]=i;
		}
	}	
	long long root(long long u){
		if(u==par[u]){
			return u;
		}
		return par[u]=root(par[u]);
	}
	long long con(long long u,long long v){
		u=root(u);
		v=root(v);
		if(u==v){
			return 0;
		}
		par[u]=v;
		return 1;
	}
}ds;

void solve(long long l,long long r,long long cl,long long cr){
//	cout<<l<<" "<<r<<" "<<cl<<" "<<cr<<" "<<mainres<<"\n";
	if(l!=cl){
		l--;
		cl=min(cl,av[l]);
		cr=max(cr,tr[av[l]]);
		return solve(l,r,cl,cr);
	}
	if(r!=cr){
		r++;
		cl=min(cl,av[r]);
		cr=max(cr,tr[av[r]]);
		return solve(l,r,cl,cr);
	}
	long long fl=0,fr=0,hl=l-1,hr=r+1,mxl=l,mxr=r;
	for(;;hr++){
		if(hr==n){
			break;
		}
		if(hr==all[hr]){
			continue;
		}
		if(hr>mxr){
			fr+=(hr-mxr)*2;
		}
		mxr=max(mxr,tr[av[hr]]);
		if(av[hr]<l){
			break;
		}
	}
	for(;hl>=0;hl--){
		if(hl==all[hl]){
			continue;
		}
		if(hl<mxl){
			fl+=(mxl-hl)*2;
		}
		mxl=min(mxl,av[hl]);
		if(tr[av[hl]]>r){
			break;
		}
	}
	if(hr==n){
		mainres+=fr+fl;
		return ;
	}
	if(fl<fr){
		mainres+=fl;
		return solve(l,r,mxl,cr);
	}else{
		mainres+=fr;
		return solve(l,r,cl,mxr);
	}
}

long long minimum_walk(std::vector<int> p,int s){
	mainres=0;
	n=p.size();
	for(long long i=0;i<=n;i++){
		vis[i]=visa[i]=0;
		all[i]=p[i];
	}
	last=0;
	long long cnt1=0;
	for(long long i=0;i<n;i++){
		if(p[i]>i){
			cnt1++;
			visa[p[i]]=1;
		}
		if(visa[i]){
			cnt1--;
		}
		mainres+=cnt1*2;
		if(cnt1!=0){
			last=i+1;
		}
	}
	for(long long i=0;i<n;i++){
		if(i==p[i]){
			continue;
		}
		if(vis[i]==0){
			//mainres+=2;
			long long now=i;
			do{
				av[now]=i;
				vis[now]=1;
				tr[i]=max(tr[i],now);
				now=p[now];
			}while(now!=i);
		}
	}
	last=-1;
	alle.clear();
	solve(s,s,av[s],tr[av[s]]);
	return mainres;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 5 ms 8284 KB Output is correct
3 Correct 3 ms 8308 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8284 KB Output is correct
7 Correct 3 ms 8088 KB Output is correct
8 Correct 3 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 3 ms 8284 KB Output is correct
11 Correct 3 ms 8284 KB Output is correct
12 Correct 3 ms 8284 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 3 ms 8284 KB Output is correct
15 Correct 3 ms 8284 KB Output is correct
16 Correct 3 ms 8272 KB Output is correct
17 Correct 3 ms 8284 KB Output is correct
18 Correct 3 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 5 ms 8284 KB Output is correct
3 Correct 3 ms 8308 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8284 KB Output is correct
7 Correct 3 ms 8088 KB Output is correct
8 Correct 3 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 3 ms 8284 KB Output is correct
11 Correct 3 ms 8284 KB Output is correct
12 Correct 3 ms 8284 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 3 ms 8284 KB Output is correct
15 Correct 3 ms 8284 KB Output is correct
16 Correct 3 ms 8272 KB Output is correct
17 Correct 3 ms 8284 KB Output is correct
18 Correct 3 ms 8284 KB Output is correct
19 Correct 3 ms 8280 KB Output is correct
20 Correct 3 ms 8284 KB Output is correct
21 Correct 3 ms 8324 KB Output is correct
22 Correct 5 ms 8284 KB Output is correct
23 Correct 5 ms 8284 KB Output is correct
24 Correct 4 ms 8284 KB Output is correct
25 Correct 4 ms 8272 KB Output is correct
26 Correct 3 ms 8536 KB Output is correct
27 Correct 3 ms 8284 KB Output is correct
28 Correct 3 ms 8124 KB Output is correct
29 Correct 3 ms 8284 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 5 ms 8284 KB Output is correct
3 Correct 3 ms 8308 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8284 KB Output is correct
7 Correct 3 ms 8088 KB Output is correct
8 Correct 3 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 3 ms 8284 KB Output is correct
11 Correct 3 ms 8284 KB Output is correct
12 Correct 3 ms 8284 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 3 ms 8284 KB Output is correct
15 Correct 3 ms 8284 KB Output is correct
16 Correct 3 ms 8272 KB Output is correct
17 Correct 3 ms 8284 KB Output is correct
18 Correct 3 ms 8284 KB Output is correct
19 Correct 3 ms 8280 KB Output is correct
20 Correct 3 ms 8284 KB Output is correct
21 Correct 3 ms 8324 KB Output is correct
22 Correct 5 ms 8284 KB Output is correct
23 Correct 5 ms 8284 KB Output is correct
24 Correct 4 ms 8284 KB Output is correct
25 Correct 4 ms 8272 KB Output is correct
26 Correct 3 ms 8536 KB Output is correct
27 Correct 3 ms 8284 KB Output is correct
28 Correct 3 ms 8124 KB Output is correct
29 Correct 3 ms 8284 KB Output is correct
30 Correct 123 ms 52600 KB Output is correct
31 Correct 122 ms 52820 KB Output is correct
32 Correct 80 ms 44888 KB Output is correct
33 Correct 94 ms 60580 KB Output is correct
34 Correct 95 ms 60500 KB Output is correct
35 Correct 98 ms 60756 KB Output is correct
36 Correct 94 ms 60556 KB Output is correct
37 Correct 94 ms 60240 KB Output is correct
38 Correct 91 ms 57424 KB Output is correct
39 Correct 93 ms 56688 KB Output is correct
40 Correct 92 ms 53844 KB Output is correct
41 Correct 107 ms 52692 KB Output is correct
42 Correct 102 ms 52816 KB Output is correct
43 Correct 92 ms 60496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 3 ms 8284 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 8280 KB Output is correct
2 Correct 5 ms 8284 KB Output is correct
3 Correct 3 ms 8308 KB Output is correct
4 Correct 3 ms 8284 KB Output is correct
5 Correct 3 ms 8284 KB Output is correct
6 Correct 3 ms 8284 KB Output is correct
7 Correct 3 ms 8088 KB Output is correct
8 Correct 3 ms 8284 KB Output is correct
9 Correct 4 ms 8284 KB Output is correct
10 Correct 3 ms 8284 KB Output is correct
11 Correct 3 ms 8284 KB Output is correct
12 Correct 3 ms 8284 KB Output is correct
13 Correct 3 ms 8284 KB Output is correct
14 Correct 3 ms 8284 KB Output is correct
15 Correct 3 ms 8284 KB Output is correct
16 Correct 3 ms 8272 KB Output is correct
17 Correct 3 ms 8284 KB Output is correct
18 Correct 3 ms 8284 KB Output is correct
19 Correct 3 ms 8280 KB Output is correct
20 Correct 3 ms 8284 KB Output is correct
21 Correct 3 ms 8324 KB Output is correct
22 Correct 5 ms 8284 KB Output is correct
23 Correct 5 ms 8284 KB Output is correct
24 Correct 4 ms 8284 KB Output is correct
25 Correct 4 ms 8272 KB Output is correct
26 Correct 3 ms 8536 KB Output is correct
27 Correct 3 ms 8284 KB Output is correct
28 Correct 3 ms 8124 KB Output is correct
29 Correct 3 ms 8284 KB Output is correct
30 Correct 123 ms 52600 KB Output is correct
31 Correct 122 ms 52820 KB Output is correct
32 Correct 80 ms 44888 KB Output is correct
33 Correct 94 ms 60580 KB Output is correct
34 Correct 95 ms 60500 KB Output is correct
35 Correct 98 ms 60756 KB Output is correct
36 Correct 94 ms 60556 KB Output is correct
37 Correct 94 ms 60240 KB Output is correct
38 Correct 91 ms 57424 KB Output is correct
39 Correct 93 ms 56688 KB Output is correct
40 Correct 92 ms 53844 KB Output is correct
41 Correct 107 ms 52692 KB Output is correct
42 Correct 102 ms 52816 KB Output is correct
43 Correct 92 ms 60496 KB Output is correct
44 Incorrect 3 ms 8284 KB 3rd lines differ - on the 1st token, expected: '3304', found: '2744'
45 Halted 0 ms 0 KB -