日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Division and Union CodeForces - 1101C (排序后处理)

發布時間:2023/12/18 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Division and Union CodeForces - 1101C (排序后处理) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

There are?nn?segments?[li,ri][li,ri]?for?1in1≤i≤n. You should divide all segments into two?non-empty?groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do it. Each segment should belong to exactly one group.

To optimize testing process you will be given multitest.

Input

The first line contains one integer?TT?(1T500001≤T≤50000) — the number of queries. Each query contains description of the set of segments. Queries are independent.

First line of each query contains single integer?nn?(2n1052≤n≤105) — number of segments. It is guaranteed that?n∑n?over all queries does not exceed?105105.

The next?nn?lines contains two integers?lili,?riri?per line (1liri2?1051≤li≤ri≤2?105) — the?ii-th segment.

Output

For each query print?nn?integers?t1,t2,,tnt1,t2,…,tn?(ti{1,2}ti∈{1,2}) — for each segment (in the same order as in the input)?titi?equals?11?if the?ii-th segment will belongs to the first group and?22?otherwise.

If there are multiple answers, you can print any of them. If there is no answer, print??1?1.

Example

Input 3 2 5 5 2 3 3 3 5 2 3 2 3 3 3 3 4 4 5 5 Output 2 1 -1 1 1 2

Note

In the first query the first and the second segments should be in different groups, but exact numbers don't matter.

In the second query the third segment intersects with the first and the second segments, so they should be in the same group, but then the other group becomes empty, so answer is??1?1.

In the third query we can distribute segments in any way that makes groups non-empty, so any answer of?66?possible is correct.

?

題意:給你N個區間,讓你把這N個區間分成2個非空的集合,使不存在任意一個元素x,它即被第一個集合的某一個區間包含即L<=x<=R,也被第二個集合的某些區間包含。

如果不可以分,輸出-1,如果可以,輸出1~n個數,代表第i的區間放在第d個集合,d為1或2.

思路,根據L和R把區間排序后,先把排序后的第一個區間的L和R作為第一個集合的總L和R,那么我們來維護這個L和R,使第一個集合的L~R是一個連續的區間。(L~R每一個元素都可以在第一個集合中找到區間包含

接下來從2~n遍歷區間

如果下一個區間和L~R有交集,那么加入到第一個集合,更新L和R,

否則加入到第二個集合之中。

細節見代碼:

#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include <cmath> #include <queue> #include <stack> #include <map> #include <set> #include <vector> #define rep(i,x,n) for(int i=x;i<n;i++) #define repd(i,x,n) for(int i=x;i<=n;i++) #define pii pair<int,int> #define pll pair<long long ,long long> #define gbtb ios::sync_with_stdio(false),cin.tie(0),cout.tie(0) #define MS0(X) memset((X), 0, sizeof((X))) #define MSC0(X) memset((X), '\0', sizeof((X))) #define pb push_back #define mp make_pair #define fi first #define se second #define gg(x) getInt(&x) using namespace std; typedef long long ll; inline void getInt(int* p); const int maxn=1000010; const int inf=0x3f3f3f3f; /*** TEMPLATE CODE * * STARTS HERE ***/ int t; struct node {int l;int r;int id; }; typedef struct node node; std::vector<node> v; int n; bool cmp(node a,node b) {if(a.l!=b.l){return a.l<b.l;}else{return a.r<b.r;} } int ans[maxn]; int main() {scanf("%d",&t);while(t--){v.clear();scanf("%d",&n);node temp;repd(i,1,n){scanf("%d %d",&temp.l,&temp.r);temp.id=i;v.push_back(temp);}sort(v.begin(), v.end(),cmp);int le,ri;le=v[0].l;ri=v[0].r;int is2=0;ans[v[0].id]=1;for(int i=1;i<=n-1;i++){temp=v[i];if(temp.l<=le&&temp.r>=ri){le=temp.l;ri=temp.r;ans[v[i].id]=1;}else if(temp.l<=ri&&temp.r<=ri){ // ri=temp.r;ans[v[i].id]=1;}else if(temp.l<=ri&&temp.r>ri){ri=temp.r;ans[v[i].id]=1;}else if(temp.l>ri){is2=1;ans[v[i].id]=2;}}if(is2){repd(i,1,n){printf("%d ",ans[i]);}printf("\n");}else{printf("-1\n");}}return 0; }inline void getInt(int* p) {char ch;do {ch = getchar();} while (ch == ' ' || ch == '\n');if (ch == '-') {*p = -(getchar() - '0');while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 - ch + '0';}}else {*p = ch - '0';while ((ch = getchar()) >= '0' && ch <= '9') {*p = *p * 10 + ch - '0';}} }

?

?

轉載于:https://www.cnblogs.com/qieqiemin/p/10259473.html

總結

以上是生活随笔為你收集整理的Division and Union CodeForces - 1101C (排序后处理)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。

主站蜘蛛池模板: 女色综合 | 中文字幕在线播出 | 五月天综合 | 最新中文字幕在线观看视频 | 爱操视频| 舒淇裸体午夜理伦 | 91久久精品国产91久久性色tv | 91久热| 国产玖玖在线 | 欧美黑人性猛交xxxx | 欧美一区二区日韩一区二区 | 正在播放木下凛凛88av | 毛片在线播放视频 | 免费看黄色小视频 | 色阁av | 撸啊撸在线视频 | 亚洲视频网站在线观看 | 高清av一区二区三区 | 亚洲第一视频在线播放 | 毛片久久久久久 | 免费不卡av在线 | 亚洲精品福利视频 | 欧美视频免费 | 天天槽| 久久666 | 在线观看日韩视频 | 日韩亚州 | 亚洲精品网址 | 蜜臀少妇久久久久久久高潮 | 亚洲精品在线免费观看视频 | 欧美日韩不卡合集视频 | 美女扒开内裤让男人桶 | 亚洲色图另类小说 | 香蕉视频网站在线观看 | 深夜福利视频导航 | 一区二区三区高清 | 女人黄色片 | 亚洲视频黄 | 国产高清无遮挡 | 内射毛片内射国产夫妻 | 国产精品毛片久久 | 国产丝袜久久 | 国产综合区 | h片网站在线观看 | 九九热国产在线 | 一区二区三区国产精品视频 | 欧美成人天堂 | 高清一区在线观看 | 青青草娱乐视频 | 91人人爱 | 免费性爱视频 | 久久久久人妻一区精品色 | 黄色三级视频在线观看 | 爱爱三级视频 | n0659极腔濑亚美莉在线播放播放 | 大乳女喂男人吃奶视频 | av一区不卡 | 欧美亚州| 日韩欧美电影一区二区三区 | 国产精品久久9 | 国产乱人伦精品 | 欧美一区二区三区婷婷 | 日韩免费在线视频观看 | 久久精品在线免费观看 | 99热这里只有精品99 | 国产5区 | av成人在线电影 | 亚洲色图另类小说 | 亚洲天堂欧美 | 天天色综合天天 | 公侵犯人妻中文字慕一区二区 | 日本少妇b | 图片区亚洲色图 | 国产精品亚洲欧美 | 欧美freesex黑人又粗又大 | 视频免费观看在线 | 姐姐av| 少妇无套内谢久久久久 | 欧美乱大交xxxxx潮喷 | 波多野结衣视频免费观看 | 免费一级肉体全黄毛片 | 浮生影视在线观看免费 | 色人阁在线视频 | 麻豆三级 | 亚洲涩涩爱 | aaa一区二区 | 性欧美久久| 一区久久| 一级欧美日韩 | 国产18p| 成人黄色短视频在线观看 | 国产精品亚洲一区二区三区在线观看 | 少妇激情偷人三级 | 日批免费网站 | 三级网站免费看 | 成人一区二 | 久久三级视频 | 亚洲国产情侣 | 一本色道久久综合亚洲精品酒店 |