HDU 多校第一场 D Distinct Values (HDU - 6301 ) 以及该题Runtime error

感谢国家,感谢人民,感谢党,感谢学校提供的账号,当然最要感谢的是zj!!!!!
不是自己是zj!!!!!!!
我最后的写法其实完全没问题啦,不知道是不是给了2s的原因,把并没有起到什么实际作用的set换成了数组就神奇地过了。
但是,那不是最主要的。
最主要的是我交上去都是崩了的啊!runtime  error
为此,我和zj进行了长达两个小时的讨论和辩解。
在这个漫长的过程中不仅下起了雨,我估计还有大约100+的人从雨中走过。
最后确定下来是sort的问题,竟然不能写等于、我也不知道为什么(在我代码里这样的问题遇到的太多了,,= =  不过我并没学过c和c++...(寄几瞎鸡儿摸爬滚打)(不)可能这些东西上课都讲过-.-输入输出什么的也是-.-( 我的代码格式简直不能看 )

这里就涉及到许多骚操作了....
比如他随机生成了一组数据....
比如release不会报错,debug模式才行....
比如..  搜到一个这个  
(链接)https://blog.csdn.net/py_2017/article/details/74995451

好废话说完了... 这个题呢,最可怕的地方不在于样例,而是一环套一环的端点情况
比如2 8 /3 9/ 4 10  
这个时候就要检查前面的拿到后面的,再进行一系列操作,具体代码都有了,还加了一堆注释

看起来会超时的,数据有1w多组,但是其实...  很玄幻哦,zj说set的就2.2s,最后改了就过了
但是其实区间只有那么多,加起来就算你一直是连着的,查询并不会从最开始开始查
哪怕是1,2/1,3,/1,5
按照我的思路_(:з」∠)_  只要2到3  3到5 就可以了_(:з」∠)_
最后还是放 一份  zj大大的超强代码吧
我这个还是投机取巧_(:з」∠)_


#include<iostream>
#include<algorithm>
#include<set>
using namespace std;
typedef long long ll;
int a[100005];
int c[100005];
int d[100005];
struct  node {
	int a1; 
	int a2;
}nodee[100005];
/*
bool cmp(const node &x,const node &y) {
	if (x.a1 == y.a1&&x.a2 == y.a2)return 0;
	else if (x.a1 == y.a1) return x.a2 > y.a2;
	 else	 return x.a1 < y.a1;
}*/
bool cmp(node x, node y) {
	if (x.a1 == y.a1) return x.a2 > y.a2;
	else return x.a1 < y.a1;
}
int n; int m;
int main() {
		//freopen("1004.in", "r", stdin);
		//freopen("1004.out", "w", stdout);
	int t; cin >> t;
		while (t--) {
			cin >> n >> m;
			for (int i = 0; i <= n; i++) {
				d[i] = 0;
				a[i] = 1;
			}//先初始化...
			//cin >> m;
		for (int i = 1; i <= m; i++) { cin >> nodee[i].a1 >> nodee[i].a2; }
		sort(nodee+1, nodee+m+1, cmp);
		//		for (int i = 1; i <= nodee[i].a1 - 1; i++)cout << "1 ";//最后一个没算哦
		int temp = 0;
		//set<int>s;
		//跑进来的第一个,先放成自然的
		for (int i = nodee[1].a1; i <= nodee[1].a2; i++) {
			if (m == 0) break;
			//因为没有重载构造函数....
			//第一个,不用管的
			temp++;
			a[i] = temp;
			d[temp] = 1;//s.insert(a[i]);
		}
		//cout << "第一个:" << endl;
		//for (int i = 1; i <= n; i++)cout << a[i] << " ";
		//cout << endl;
		//然后就是重复的了
		//重复的,和区间太小的,都没了
		for (int i = 2; i <= m; i++) {
			//两种情况 2 10  2 8  3 9 不管

			if (nodee[i].a1 == nodee[i - 1].a1) {
				nodee[i].a2 = nodee[i - 1].a2;
				continue;
			}
			else if (nodee[i].a2 <= nodee[i - 1].a2) {
				nodee[i].a2 = nodee[i - 1].a2;
				nodee[i].a1 = nodee[i - 1].a1;
				continue;//像  2 10 3 9 这样的... 别用了-.-跳过
			}
			// 把前面的都跳过
			//从上一个的1到这一个的1  这中间的access都跳			
			int k;
			//开始插入新区间 如果没有重叠 就clear
			//如果重叠  就前面后面清理一下
			if (nodee[i].a1 <= nodee[i - 1].a2) {
				k = nodee[i - 1].a2 + 1;
				for (int j = nodee[i - 1].a1; j < nodee[i].a1; j++)
				{
					//if ((s.count(a[j])) == 1)
					//s.erase(a[j]);
					if (d[a[j]] == 1)d[a[j]] = 0;
				}
			}
			else if (nodee[i].a1 > nodee[i - 1].a2) {
				//不重合  就清空  然后打开新世界.. 
				//s.clear();//没错吧
				for (int i = 0; i <= n; i++)d[i] = 0;
				k = nodee[i].a1;
			}
			int temp = 1; int kk = 1;
			for (int j = k; j <= nodee[i].a2; j++) {
				while (d[temp] == 1)
					temp++;
				//while ((s.count(temp)) == 1)temp++;
				a[j] = temp;
				d[a[j]] = 1;//s.insert(a[j]);
			}
			//cout << "第几次:"<<i<< endl;
			//for (int l = 1; l <= n; l++)cout << a[l] << " ";
			//cout << endl;
		}
		//跑完了,找最后没被覆盖的
		//cout << "跑完了之后:" << endl;
		//for (int i = 1; i <= n; i++)cout << a[i] << " ";
		//cout << endl;
		for (int i = nodee[m].a2+1; i <= n; i++) {
			a[i] = 1;
		}
		for (int i = 1; i < n; i++)cout << a[i] << " ";
		cout << a[n] << endl;
		}
		return 0;	
}

啊_(:з」∠)_就像前面那个题 自己过是过了
还要看别人是怎么写的!!!!!!

a

我还真是... 好不容易A个题能高兴成这样(小声bb)

加油呀 这段日子又充实又快乐呢 ୧(๑•̀◡•́๑)૭

猜你喜欢

转载自blog.csdn.net/strongerirene/article/details/81175875