首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 其他教程 > 其他相关 >

Codeforces Round #207 (Div. 二) - C

2013-10-17 
Codeforces Round #207 (Div. 2) - C题目搞懂了,就是优化啊,在 test11 TLE两次,看人家的解法,优化的很精巧

Codeforces Round #207 (Div. 2) - C

  题目搞懂了,就是优化啊,在 test11 TLE两次,看人家的解法,优化的很精巧

#include<stdio.h>#include<stdlib.h>using namespace std;#define MN 300005int ans[MN],p[MN];int getl(int x){int i = x,j;while(x != p[x]){x = p[x];}while(i != p[i]){j = p[i];p[i] = x;i = j;}return x;}int main(void){int m,n,l,r,x;scanf("%d %d",&n,&m);for(int i=1;i<=n+1;i++)    p[i] = i;for(int i=1;i<=m;i++){scanf("%d %d %d",&l,&r,&x);int j = getl(l);while(j <= r){if(j != x ){ans[j] = x;p[j] = j+1;}j = j + 1;j = getl(j);}}for(int i=1;i<=n;i++)     printf("%d ",ans[i]);//system("pause");return 0;}


热点排行