Submission #57831

# Submission time Handle Problem Language Result Execution time Memory
57831 2018-07-16T09:48:04 Z ainta(#1666) Teams (CEOI11_tea) C++11
100 / 100
654 ms 44516 KB
#include<cstdio>
#include<algorithm>
using namespace std;
int n;
struct point {
	int x, num;
	bool operator <(const point &p)const {
		return x > p.x;
	}
}w[1010000];
int Deq[1010000], head, tail, P[1010000], U[1010000], BB[1010000], EE[1010000];
int Get(int M) {
	int i, r = 0, res = 0;
	head = 1, tail = 0;
	int b = 1, e = 1;
	Deq[++tail] = 1;
	while (1) {
		BB[r] = b, EE[r] = e, U[r] = Deq[head];
		int b2, e2;
		e2 = min(n + 1, e + M);
		if (head > tail)break;
		b2 = P[Deq[head]];
		if (b2 > e2)break;
		r++;
		if (e2 == n + 1) {
			res = r;
		}
		while (e < e2) {
			e++;
			if (e == n + 1)continue;
			while (head <= tail && P[Deq[tail]] >= P[e])tail--;
			Deq[++tail] = e;
		}
		while (head <= tail && Deq[head] < b2)head++;
		b = b2;
	}
	return res;
}
int rr;
void Print(int b, int e) {
	if (b >= e || e-b > rr) {
		while (1) {}
	}
	printf("%d ", e - b);
	for (int i = b; i < e; i++)printf("%d ", w[i].num);
	puts("");
}
int main() {
	int i;
	scanf("%d", &n);
	for (i = 1; i <= n; i++) {
		scanf("%d", &w[i].x);
		w[i].num = i;
	}
	sort(w + 1, w + n + 1);
	for (i = 1; i <= n; i++)P[i] = i + w[i].x;
	int pv = 0, cnt;
	cnt = Get(n);
	int b = w[1].x, e = n, mid, res;
	while (b <= e) {
		mid = (b + e) >> 1;
		if (Get(mid) == cnt) {
			res = mid;
			e = mid - 1;
		}
		else b = mid + 1;
	}
	Get(res);
	pv = n + 1;
	int cur = cnt;
	rr = res;
	printf("%d\n", cnt);
	while (cur) {
		if (pv - res >= BB[cur - 1]) {
			Print(pv - res, pv);
			pv -= res;
		}
		else {
			Print(U[cur - 1], pv);
			pv = U[cur - 1];
		}
		cur--;
	}
	if (pv != 1) {
		while (1) {}
	}
	return 0;
}

Compilation message

tea.cpp: In function 'int Get(int)':
tea.cpp:13:6: warning: unused variable 'i' [-Wunused-variable]
  int i, r = 0, res = 0;
      ^
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:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &w[i].x);
   ~~~~~^~~~~~~~~~~~~~~
tea.cpp:74:10: warning: 'res' may be used uninitialized in this function [-Wmaybe-uninitialized]
   if (pv - res >= BB[cur - 1]) {
       ~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 504 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 548 KB Output is correct
2 Correct 2 ms 576 KB Output is correct
3 Correct 3 ms 576 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 576 KB Output is correct
2 Correct 3 ms 576 KB Output is correct
3 Correct 2 ms 620 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 620 KB Output is correct
2 Correct 4 ms 876 KB Output is correct
3 Correct 5 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 876 KB Output is correct
2 Correct 4 ms 876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 30 ms 2400 KB Output is correct
2 Correct 32 ms 2656 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 31 ms 2896 KB Output is correct
2 Correct 29 ms 2896 KB Output is correct
3 Correct 57 ms 2896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 307 ms 17780 KB Output is correct
2 Correct 494 ms 20128 KB Output is correct
3 Correct 296 ms 24236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 342 ms 29804 KB Output is correct
2 Correct 654 ms 44516 KB Output is correct
3 Correct 316 ms 44516 KB Output is correct
4 Correct 425 ms 44516 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 402 ms 44516 KB Output is correct
2 Correct 318 ms 44516 KB Output is correct
3 Correct 344 ms 44516 KB Output is correct
4 Correct 429 ms 44516 KB Output is correct