求助哇
  • 板块学术版
  • 楼主我叕灰来啦
  • 当前回复2
  • 已保存回复2
  • 发布时间2021/7/19 15:40
  • 上次更新2023/11/4 14:10:38
查看原帖
求助哇
173908
我叕灰来啦楼主2021/7/19 15:40
#include <cstdio>
#include <cstring>
#include <algorithm>

struct pair {
	int x, y;
	explicit pair (int x = 0, int y = 0) : x(x), y(y) {}
	bool operator < (const pair &o) const {
		return x != o.x ? x < o.x : y > o.y;
	}
};

const int N = 1000000 + 7;

pair b[N];
int a[N], c[N], n;

int main() {

//	freopen("game.in", "r", stdin);
//	freopen("game.out", "w", stdout);
	
	int x, y, z, m = 0, cnt;
	
	scanf("%d", &n);
	for(int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		if(i >= a[i]) b[++m] = pair(a[i], i - a[i]);
	}

	std::sort(b + 1, b + m + 1);

	c[cnt = 1] = b[1].y;
	for(int i = 2; i <= m; ++i)
		if(b[i].y >= c[cnt]) c[++cnt] = b[i].y;
		else *std::upper_bound(c + 1, c + cnt + 1, b[i].y) = b[i].y;

	printf("%d\n", cnt);

	return 0;

}

老师写的代码,有没有dalao告诉一下"upper_bound"是怎么用的啊,复制过去后老是报错

2021/7/19 15:40
加载中...