50分其他都T飞了,求帮忙优化。
  • 板块P4198 楼房重建
  • 楼主lwyyds
  • 当前回复2
  • 已保存回复2
  • 发布时间2022/12/16 18:26
  • 上次更新2023/10/24 07:31:51
查看原帖
50分其他都T飞了,求帮忙优化。
817297
lwyyds楼主2022/12/16 18:26
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#define lson h<<1
#define rson (h<<1)+1
using namespace std;
typedef long long ll;
const int max1 = 1000300;
ll m, n = 1, k, tot = 1, mod, su1, su2, su3, su4, su5, arr[max1], brr[max1];
string  s, s1, s2, s3;
char a, b, c;
struct A {
	ll l, r,lac;
	double k;
}tree[max1 * 4];
ll read() {
	ll f = 1, x = 0; char ch = getchar();
	while (ch > '9' || ch < '0') {
		if (ch == '-')f = -f;
		ch = getchar();
	}
	while (ch <= '9' && ch >= '0') {
		x = x * 10 + ch - 48;
		ch = getchar();
	}
	return f * x;
}
void upshup(ll h) {
	if (tree[lson].k >= tree[rson].k) {
		tree[h].k = tree[lson].k;
		tree[h].lac = tree[lson].lac;
	}
	else {
		tree[h].k = tree[rson].k;
		tree[h].lac = tree[rson].lac;
	}
}
void build(ll h, ll l, ll r) {
	tree[h].l = l;
	tree[h].r = r;
	if (l == r) {
		tree[h].k = 0;
		tree[h].lac = l;
		return;
	}
	ll mid = (l + r) / 2;
	build(lson, l, mid);
	build(rson, mid + 1, r);
	upshup(h);
}
void modify(ll h, ll g, double H) {
	if (tree[h].l >= g && tree[h].r <= g) {
		tree[h].k = H / tree[h].lac;
		return;
	}
	if (tree[lson].r >= g)modify(lson, g, H);
	if (tree[rson].l <= g)modify(rson, g, H);
	upshup(h);
}
A ask(ll h,ll l,ll r) {
	ll ans = 0;
	if (tree[h].l >= l && tree[h].r <= r) {
		return tree[h];
	}
	if (tree[lson].r < l)return ask(rson, l, r);
	if (tree[rson].l > r)return ask(lson, l, r);
	ll mid = (tree[h].r + tree[h].l) / 2;
	A L = ask(lson, l, mid), R = ask(rson, mid + 1, r), G;
	if (L.k >= R.k) {
		G.k = L.k;
		G.lac = L.lac;
	}
	else {
		G.k = R.k;
		G.lac = R.lac;
	}
	return G;
}
ll query() {
	ll ans = 1, wer=n;
	while (ask(1, 1, wer).lac != 1) {
		wer = ask(1, 1, wer).lac - 1;
		ans++;
	}
	return ans;
}
int main() {
	//cin >> n >> m;
	n = read(); m = read();
	ll flag = 1;
	build(1, 1, n);
	for (int i = 1; i <= m; i++){
		//cin >> su1 >> su2;
		su1 = read(); su2 = read();
		if (su1 == 1)flag = 0;
		modify(1, su1, su2);
		cout << query()-flag << endl;
	}
	return 0;
}
2022/12/16 18:26
加载中...