Submission #57506

# Submission time Handle Problem Language Result Execution time Memory
57506 2018-07-15T08:00:03 Z 김세빈(#1671) Teams (CEOI11_tea) C++11
80 / 100
631 ms 140504 KB
#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> pii;

vector <int> V[1010101];
pii K[1010101];
int T[22202020];
int D[1010101], M[1010101];
int n, sz;

void insert(int p)
{
	T[p + sz] = p;
	p += sz;
	
	for(p>>=1;p;p>>=1){
		if(D[T[p<<1]] > D[T[p<<1|1]]) T[p] = T[p<<1];
		else T[p] = T[p<<1|1];
	}
}

int get_max(int l, int r)
{
	int ret = 0;
	
	l += sz; r += sz;
	for(;l<r;){
		if(l & 1){
			if(D[ret] < D[T[l]] || (D[ret] == D[T[l]] && ret < T[l])) ret = T[l];
		}
		if(~r & 1){
			if(D[ret] < D[T[r]] || (D[ret] == D[T[r]] && ret < T[r])) ret = T[r];
		}
		l = l+1 >> 1;
		r = r-1 >> 1;
	}
	if(l == r){
		if(D[ret] < D[T[l]] || (D[ret] == D[T[l]] && ret < T[l])) ret = T[l];
	}
	
	return ret;
}

int main()
{
	int i, j, a, k;
	
	scanf("%d", &n);
	
	for(sz=1;sz<=n;sz<<=1);
	
	for(i=1;i<=n;i++){
		scanf("%d", &a);
		K[i] = pii(a, i);
	}
	
	sort(K+1, K+n+1);
	
	for(i=1;i<=n;i++){
		for(auto t: V[i]) insert(t);
		
		if(i >= K[i].first){
			k = get_max(0, i - K[i].first);
			D[i] = D[k] + 1;
			M[i] = i - k;

			V[i + M[i]].push_back(i);
		}
	}
	
	printf("%d\n", D[n]);
	
	for(i=n;i;){
		k = M[i];
		printf("%d ", k);
		for(j=0;j<k;j++,i--) printf("%d ", K[i].second); 
		printf("\n");
	}

	return 0;
}

Compilation message

tea.cpp: In function 'int get_max(int, int)':
tea.cpp:36:8: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   l = l+1 >> 1;
       ~^~
tea.cpp:37:8: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
   r = r-1 >> 1;
       ~^~
tea.cpp: In function 'int main()':
tea.cpp:50:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
tea.cpp:55:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a);
   ~~~~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 26 ms 24056 KB Output is correct
2 Correct 28 ms 24168 KB Output is correct
3 Correct 28 ms 24244 KB Output is correct
4 Correct 27 ms 24256 KB Output is correct
5 Correct 23 ms 24256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 24256 KB Output is correct
2 Correct 26 ms 24360 KB Output is correct
3 Correct 26 ms 24360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 24360 KB Output is correct
2 Correct 28 ms 24388 KB Output is correct
3 Correct 23 ms 24388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 24556 KB Output is correct
2 Correct 30 ms 24592 KB Output is correct
3 Correct 27 ms 24756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 24756 KB Output is correct
2 Correct 27 ms 24756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 28556 KB Output is correct
2 Correct 79 ms 30036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 90 ms 30176 KB Output is correct
2 Correct 100 ms 30252 KB Output is correct
3 Correct 88 ms 30792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 552 ms 71748 KB Output is correct
2 Correct 493 ms 74680 KB Output is correct
3 Correct 503 ms 74680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 631 ms 140504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 376 ms 140504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -