답안 #430821

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
430821 2021-06-17T06:41:00 Z Antekb 식물 비교 (IOI20_plants) C++14
100 / 100
2015 ms 74408 KB
#include "plants.h"
#include<bits/stdc++.h>
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define st first
#define nd second
using namespace std;
const int N=(1<<18);
int rtab[N+N], lazy[2*N];
int k;
void prop(int v){
	if(v>=N || !lazy[v])return;
	int l=v+v, r=l+1;
	lazy[l]+=lazy[v];
	lazy[r]+=lazy[v];
	rtab[l]+=lazy[v];
	rtab[r]+=lazy[v];
	lazy[v]=0;
}
void add(int v, int L, int R, int l, int r, int c){
	if(l==L && r==R){
		lazy[v]+=c;
		rtab[v]+=c;
		return;
	}
	int M=(L+R)>>1;
	prop(v);
	if(l<=M)add(2*v, L, M, l, min(M, r), c);
	if(r>M)add(2*v+1, M+1, R, max(l, M+1), r, c);
	rtab[v]=max(rtab[2*v], rtab[2*v+1]);
}
int checkk(){
	if(rtab[1]<k)return -1;
	int v=1;
	while(v<N){
		prop(v);
		if(rtab[2*v]==k)v=2*v;
		else v=2*v+1;
	}
	return v-N;
}
int tab[N+N], lazy2[N+N];
void prop2(int v){
	if(v>=N || !lazy2[v])return;
	int l=v+v, r=l+1;
	lazy2[l]+=lazy2[v];
	lazy2[r]+=lazy2[v];
	tab[l]+=lazy2[v];
	tab[r]+=lazy2[v];
	lazy2[v]=0;
}
void add2(int v, int L, int R, int l, int r, int c){
	if(l==L && r==R){
		lazy2[v]+=c;
		tab[v]+=c;
		return;
	}
	int M=(L+R)>>1;
	prop2(v);
	if(l<=M)add2(2*v, L, M, l, min(M, r), c);
	if(r>M)add2(2*v+1, M+1, R, max(l, M+1), r, c);
	tab[v]=max(tab[2*v], tab[2*v+1]);
}
int getmax(){
	int v=1;
	while(v<N){
		prop2(v);
		if(tab[2*v]>tab[2*v+1])v=2*v;
		else v=v*2+1;
	}
	return v-N;
}
int maks[N+N];
void Set(int i, int val){
	for(i+=N, maks[i]=val, i>>=1; i; i>>=1){
		maks[i]=max(maks[2*i], maks[2*i+1]);
	}
}
int find(int l, int r){
	r++;
	int ans=0;
	for( l+=N, r+=N; l<r; l>>=1, r>>=1){
		if(l&1)ans=max(maks[l++], ans);
		if(r&1)ans=max(maks[--r], ans);
	}
	return ans;
}
vector<int> kol, gdzie;
const int K=18;
long long Left[K][N], Right[K][N];
int n;
void init(int _k, std::vector<int> r) {
    n=r.size();
    k=_k-1;
    for(int i=0; i<n; i++){
    	rtab[N+i]=k-r[i];
    }
    for(int i=N-1; i>0; i--){
    	rtab[i]=max(rtab[i+i], rtab[i+i+1]);
	}
	//cerr<<rtab[1]<<" "<<k<<"\n";
	gdzie.resize(n);
	for(int i=0; i<n; i++){
		//cerr<<i<<"\n";
		int t=checkk();
		while(t!=-1){
			//cerr<<t<<"\n";
			add(1, 0, N-1, t, t, -N);
			add2(1, 0, N-1, t, t, N);
			if(t<n-1)add2(1, 0, N-1, t+1, min(n-1, t+k), -1);
			if(t+k>=n)add2(1, 0, N-1, 0, t+k-n, -1);
			t=checkk();
		}
		t=getmax();
		assert(tab[t+N]==N);
		//cerr<<t<<"q\n";
		add2(1, 0, N-1, t, t, -N);
		if(t)add(1, 0, N-1, max(t-k, 0), t-1, 1);
		if(t<k)add(1, 0, N-1, n+t-k, n-1, 1);
		if(t<n-1)add2(1, 0, N-1, t+1, min(n-1, t+k), 1);
		if(t+k>=n)add2(1, 0, N-1, 0, t+k-n, 1);
		gdzie[t]=kol.size();
		kol.pb(t);
	}
	for(int i=n-1; i>=0; i--){
		int a=0;
		int t=kol[i];
		if(t)a=max(a, find(max(t-k, 0), t-1));
		if(t<k)a=max(a, find(n+t-k, n-1));
		if(a==0)Left[0][kol[i]]=n;
		else Left[0][kol[i]]=(n-kol[n-a]+kol[i])%n;
		a=0;
		if(t<n-1)a=max(a, find( t+1, min(n-1, t+k)));
		if(t+k>=n)a=max(a, find(0, t+k-n));
		if(a==0)Right[0][kol[i]]=n;
		else Right[0][kol[i]]=(n+kol[n-a]-kol[i])%n;
		Set(kol[i], n-i);
		//cout<<kol[i]<<" "<<Left[0][kol[i]]<<" "<<Right[0][kol[i]]<<"\n";
	}
	for(int j=1; j<K; j++){
		for(int i=0; i<n; i++){
			Left[j][i]=Left[j-1][i]+Left[j-1][((i-Left[j-1][i])%n+n)%n];
			Right[j][i]=Right[j-1][i]+Right[j-1][(i+Right[j-1][i])%n];
			//cout<<j<<" "<<i<<" "<<Left[j][i]<<" "<<Right[j][i]<<"\n";
		}
	}
}
int compare_plants(int x, int y){
   	int a=1, b=0;
   	if(gdzie[x]>gdzie[y])swap(x, y), a=-1;
	int t=(n+x-y)%n, u=0;
	for(int i=K-1; i>=0; i--){
		if(u+Left[i][(n+x-u)%n]<=t){
			u+=Left[i][(n+x-u)%n];
		}
	}
	//cout<<x<<" "<<y<<" "<<u<<" "<<t<<"\n";
	int s=(n+x-u)%n;
	if(((n+s-y)%n<=k || (n+y-s)%n<=k) && gdzie[(n+x-u)%n]<=gdzie[y])b=1;
	t=(n+y-x)%n, u=0;
	for(int i=K-1; i>=0; i--){
		if(u+Right[i][(u+x)%n]<=t){
			u+=Right[i][(u+x)%n];
		}
	}
	s=(n+x+u)%n;
	if(((n+s-y)%n<=k || (n+y-s)%n<=k) && gdzie[(x+u)%n]<=gdzie[y])b=1;
   	return a*b;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1612 KB Output is correct
2 Correct 2 ms 1612 KB Output is correct
3 Correct 2 ms 1612 KB Output is correct
4 Correct 2 ms 1612 KB Output is correct
5 Correct 2 ms 1612 KB Output is correct
6 Correct 131 ms 5444 KB Output is correct
7 Correct 344 ms 13192 KB Output is correct
8 Correct 1202 ms 71916 KB Output is correct
9 Correct 1240 ms 71820 KB Output is correct
10 Correct 1232 ms 71916 KB Output is correct
11 Correct 1189 ms 71940 KB Output is correct
12 Correct 1117 ms 71764 KB Output is correct
13 Correct 1215 ms 71740 KB Output is correct
14 Correct 1428 ms 71956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1716 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 2 ms 1612 KB Output is correct
4 Correct 2 ms 1612 KB Output is correct
5 Correct 2 ms 1740 KB Output is correct
6 Correct 10 ms 2212 KB Output is correct
7 Correct 247 ms 8224 KB Output is correct
8 Correct 5 ms 1868 KB Output is correct
9 Correct 9 ms 2124 KB Output is correct
10 Correct 270 ms 8120 KB Output is correct
11 Correct 219 ms 8048 KB Output is correct
12 Correct 286 ms 8308 KB Output is correct
13 Correct 256 ms 8116 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1716 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 2 ms 1612 KB Output is correct
4 Correct 2 ms 1612 KB Output is correct
5 Correct 2 ms 1740 KB Output is correct
6 Correct 10 ms 2212 KB Output is correct
7 Correct 247 ms 8224 KB Output is correct
8 Correct 5 ms 1868 KB Output is correct
9 Correct 9 ms 2124 KB Output is correct
10 Correct 270 ms 8120 KB Output is correct
11 Correct 219 ms 8048 KB Output is correct
12 Correct 286 ms 8308 KB Output is correct
13 Correct 256 ms 8116 KB Output is correct
14 Correct 552 ms 13572 KB Output is correct
15 Correct 1886 ms 74284 KB Output is correct
16 Correct 571 ms 13472 KB Output is correct
17 Correct 1897 ms 74168 KB Output is correct
18 Correct 1443 ms 73824 KB Output is correct
19 Correct 1761 ms 74332 KB Output is correct
20 Correct 1898 ms 74348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1612 KB Output is correct
2 Correct 1 ms 1740 KB Output is correct
3 Correct 228 ms 6996 KB Output is correct
4 Correct 1447 ms 73172 KB Output is correct
5 Correct 1565 ms 73524 KB Output is correct
6 Correct 1737 ms 73768 KB Output is correct
7 Correct 1797 ms 73928 KB Output is correct
8 Correct 1964 ms 74196 KB Output is correct
9 Correct 1341 ms 73436 KB Output is correct
10 Correct 1283 ms 73416 KB Output is correct
11 Correct 1206 ms 71804 KB Output is correct
12 Correct 1582 ms 73680 KB Output is correct
13 Correct 1454 ms 73608 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1716 KB Output is correct
2 Correct 1 ms 1612 KB Output is correct
3 Correct 2 ms 1612 KB Output is correct
4 Correct 1 ms 1612 KB Output is correct
5 Correct 2 ms 1612 KB Output is correct
6 Correct 6 ms 1740 KB Output is correct
7 Correct 35 ms 2588 KB Output is correct
8 Correct 33 ms 2692 KB Output is correct
9 Correct 35 ms 2628 KB Output is correct
10 Correct 32 ms 2608 KB Output is correct
11 Correct 32 ms 2608 KB Output is correct
12 Correct 33 ms 2676 KB Output is correct
13 Correct 31 ms 2640 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1612 KB Output is correct
2 Correct 2 ms 1612 KB Output is correct
3 Correct 2 ms 1612 KB Output is correct
4 Correct 2 ms 1664 KB Output is correct
5 Correct 7 ms 1996 KB Output is correct
6 Correct 1384 ms 72644 KB Output is correct
7 Correct 1522 ms 73016 KB Output is correct
8 Correct 1219 ms 73152 KB Output is correct
9 Correct 1954 ms 73336 KB Output is correct
10 Correct 1209 ms 72556 KB Output is correct
11 Correct 1173 ms 73224 KB Output is correct
12 Correct 1114 ms 72384 KB Output is correct
13 Correct 1316 ms 72632 KB Output is correct
14 Correct 1194 ms 72900 KB Output is correct
15 Correct 1693 ms 73244 KB Output is correct
16 Correct 913 ms 72384 KB Output is correct
17 Correct 1079 ms 72752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 1612 KB Output is correct
2 Correct 2 ms 1612 KB Output is correct
3 Correct 2 ms 1612 KB Output is correct
4 Correct 2 ms 1612 KB Output is correct
5 Correct 2 ms 1612 KB Output is correct
6 Correct 131 ms 5444 KB Output is correct
7 Correct 344 ms 13192 KB Output is correct
8 Correct 1202 ms 71916 KB Output is correct
9 Correct 1240 ms 71820 KB Output is correct
10 Correct 1232 ms 71916 KB Output is correct
11 Correct 1189 ms 71940 KB Output is correct
12 Correct 1117 ms 71764 KB Output is correct
13 Correct 1215 ms 71740 KB Output is correct
14 Correct 1428 ms 71956 KB Output is correct
15 Correct 2 ms 1716 KB Output is correct
16 Correct 1 ms 1612 KB Output is correct
17 Correct 2 ms 1612 KB Output is correct
18 Correct 2 ms 1612 KB Output is correct
19 Correct 2 ms 1740 KB Output is correct
20 Correct 10 ms 2212 KB Output is correct
21 Correct 247 ms 8224 KB Output is correct
22 Correct 5 ms 1868 KB Output is correct
23 Correct 9 ms 2124 KB Output is correct
24 Correct 270 ms 8120 KB Output is correct
25 Correct 219 ms 8048 KB Output is correct
26 Correct 286 ms 8308 KB Output is correct
27 Correct 256 ms 8116 KB Output is correct
28 Correct 552 ms 13572 KB Output is correct
29 Correct 1886 ms 74284 KB Output is correct
30 Correct 571 ms 13472 KB Output is correct
31 Correct 1897 ms 74168 KB Output is correct
32 Correct 1443 ms 73824 KB Output is correct
33 Correct 1761 ms 74332 KB Output is correct
34 Correct 1898 ms 74348 KB Output is correct
35 Correct 2 ms 1612 KB Output is correct
36 Correct 1 ms 1740 KB Output is correct
37 Correct 228 ms 6996 KB Output is correct
38 Correct 1447 ms 73172 KB Output is correct
39 Correct 1565 ms 73524 KB Output is correct
40 Correct 1737 ms 73768 KB Output is correct
41 Correct 1797 ms 73928 KB Output is correct
42 Correct 1964 ms 74196 KB Output is correct
43 Correct 1341 ms 73436 KB Output is correct
44 Correct 1283 ms 73416 KB Output is correct
45 Correct 1206 ms 71804 KB Output is correct
46 Correct 1582 ms 73680 KB Output is correct
47 Correct 1454 ms 73608 KB Output is correct
48 Correct 1 ms 1716 KB Output is correct
49 Correct 1 ms 1612 KB Output is correct
50 Correct 2 ms 1612 KB Output is correct
51 Correct 1 ms 1612 KB Output is correct
52 Correct 2 ms 1612 KB Output is correct
53 Correct 6 ms 1740 KB Output is correct
54 Correct 35 ms 2588 KB Output is correct
55 Correct 33 ms 2692 KB Output is correct
56 Correct 35 ms 2628 KB Output is correct
57 Correct 32 ms 2608 KB Output is correct
58 Correct 32 ms 2608 KB Output is correct
59 Correct 33 ms 2676 KB Output is correct
60 Correct 31 ms 2640 KB Output is correct
61 Correct 207 ms 6904 KB Output is correct
62 Correct 440 ms 13368 KB Output is correct
63 Correct 1293 ms 73176 KB Output is correct
64 Correct 1418 ms 73524 KB Output is correct
65 Correct 1757 ms 73820 KB Output is correct
66 Correct 1817 ms 74048 KB Output is correct
67 Correct 2015 ms 74408 KB Output is correct
68 Correct 1250 ms 73608 KB Output is correct
69 Correct 1603 ms 74132 KB Output is correct
70 Correct 1429 ms 73188 KB Output is correct
71 Correct 1587 ms 73548 KB Output is correct
72 Correct 1838 ms 73784 KB Output is correct
73 Correct 1870 ms 74136 KB Output is correct
74 Correct 1335 ms 73208 KB Output is correct
75 Correct 1321 ms 73624 KB Output is correct