萌新不知道这个代码为什么会运行时错误,很短,求助,谢谢啦
  • 板块学术版
  • 楼主Xiongzx
  • 当前回复6
  • 已保存回复6
  • 发布时间2023/3/25 09:33
  • 上次更新2023/10/23 20:37:56
查看原帖
萌新不知道这个代码为什么会运行时错误,很短,求助,谢谢啦
956071
Xiongzx楼主2023/3/25 09:33
#include <bits/stdc++.h>

#define rep(i, a, b) for(int i = (a); i <= (b); i++)
#define pre(i, a, b) for(int i = (a); i >= (b); i--)
#define Ede(i, u) for(int i = h[u]; i; i = ne[i])
#define go(i, a) for(auto i : a)
//#define int long long
#define LL long long
#define ULL unsigned long long
#define PII pair<int, int>
#define PIL pair<int, long long>
#define PLI pair<long long, int>
#define PLL pair<long long, long long>
#define mp make_pair
#define eb emplace_back
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define sf scanf
#define prf printf
#define el putchar('\n')
#define mms(arr, n) memset(arr, n, sizeof(arr))
#define mmc(arr1, arr2) memcpy(arr1, arr2, sizeof(arr2))
const int inf = 0x3f3f3f3f;

template <typename T> inline void rd(T &x){
	x = 0; bool f = true; char ch = getchar();
	while(ch < '0' || ch > '9'){ if(ch == '-') f = false; ch = getchar();}
	while(ch >= '0' && ch <= '9'){ x = (x << 1) + (x << 3) + (ch ^ '0'); ch = getchar();}
	if(!f) x = -x;
}
template <typename T, typename ...Args> inline void rd(T &x, Args &...args){ rd(x); rd(args...);}

using namespace std;

const int N = 5e4 + 10;
int n, cre[N], ans[N];
struct Cow{
	int l, r, id;
}cow[N]; 
bool cmp(Cow a, Cow b){
	return a.l < b.l;
}
priority_queue<PII, vector<PII>, greater<PII>> heap;

int main(){
	/*
	freopen(".in", "r", stdin);
	freopen(".out", "w", stdout);
	*/
	rd(n);
	rep(i, 1, n) rd(cow[i].l, cow[i].r), cow[i].id = i;
	sort(cow + 1, cow + n + 1, cmp);
	int cnt = 0;
	rep(i, 1, n){
		auto t = heap.top();
		if(cow[i].l <= t.fi) cnt++;
//		else heap.pop();
//		heap.push(mp(cow[i].r, cnt));
//		cre[i] = cnt;
	}
	rep(i, 1, n) ans[cow[i].id] = cre[i];
	prf("%d\n", cnt);
	rep(i, 1, n) prf("%d\n", ans[i]);
	return 0;
}





2023/3/25 09:33
加载中...