题意:求问数列区间奇偶信息正确与否

和上一题一样(甚至弱化),加个离散就ok啦

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#define rep(i,j,k) for(register int i=j;i<=k;i++)
#define rrep(i,j,k) for(register int i=j;i>=k;i--)
#define erep(i,u) for(register int i=head[u];~i;i=nxt[i])
#define iin(a) scanf("%d",&a)
#define lin(a) scanf("%lld",&a)
#define din(a) scanf("%lf",&a)
#define s0(a) scanf("%s",a)
#define s1(a) scanf("%s",a+1)
#define print(a) printf("%lld",(ll)a)
#define enter putchar('\n')
#define blank putchar(' ')
#define println(a) printf("%lld\n",(ll)a)
#define IOS ios::sync_with_stdio(0)
using namespace std;
const int maxn = 2e5+11;
const int oo = 0x3f3f3f3f;
const double eps = 1e-7;
typedef long long ll;
ll read(){
ll x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
return x*f;
}
int p[maxn],r[maxn];
void init(int n){
memset(r,0,sizeof r);
rep(i,0,n+2) p[i]=i;
}
int find(int x){
if(x==p[x])return x;
int oldp=p[x];
int t=find(p[x]);
r[x]=(r[x]+r[oldp])&1;
return p[x]=t;
}
void link(int fa,int fb,int a,int b,int w){
p[fb]=fa;
r[fb]=(r[a]-r[b]+w+4)&1;
}
int b[maxn],n,m,tot;
struct P{
int a,b;
bool odd;
}a[maxn];
char s[66];
inline int pos(int i){
return lower_bound(b+1,b+1+tot,i)-b;
}
int main(){
while(cin>>n>>m){
tot=0;
rep(i,1,m){
scanf("%d%d%s",&a[i].a,&a[i].b,s);
if(s[0]=='e')a[i].odd=0;
else a[i].odd=1;
if(a[i].a>a[i].b)swap(a[i].a,a[i].b);
a[i].a--;
b[++tot]=a[i].a;
b[++tot]=a[i].b;
}
sort(b+1,b+1+tot);
int nn=unique(b+1,b+1+tot)-b-1;
tot=nn;
init(nn);
int flag=0;
rep(i,1,m){
int x=pos(a[i].a),y=pos(a[i].b);
int odd=a[i].odd;
int fx=find(x),fy=find(y);
if(flag)continue;
if(fx==fy){
if((r[y]-r[x]+4&1)!=odd){
flag=i;
}
}else{
link(fx,fy,x,y,odd);
}
}
printf("%d\n",flag==0?m:flag-1);
}
return 0;
}

最新文章

  1. HDU5977 Garden of Eden(树的点分治)
  2. Color Transfer between Images code实现
  3. css定位 与position
  4. node.js建立简单应用
  5. 笔记二、本地git命令
  6. 能在你离开时照顾你的宠物的3D打印机器人
  7. 动态添加子视图 UIView 的正确方法
  8. Python入门-----Windows安装
  9. GNU/Linux超级本ZaReason Ultralap 440体验
  10. iOS 关于退出键盘两种方法和避免遮挡
  11. TP手册学习第四内置天
  12. Java中三种比较常见的数组排序
  13. class类初始化之后调用赋值问题记录
  14. jQuery 替换元素
  15. POJ-1753 Flip Game (BFS+状态压缩)
  16. EMNLP 2018 | 用强化学习做神经机器翻译:中山大学&amp;MSRA填补多项空白
  17. cas单点登陆系统-建立单点登陆系统的应用
  18. NMS—卷积神经网络
  19. linux cat显示若干行
  20. 2018-2019-20172329 《Java软件结构与数据结构》第三周学习总结

热门文章

  1. Opennebula自定义VM 实现方法-Contextualizing Virtual Machines 2.2
  2. Solidity oraclize 常用数据源
  3. C# 用代码返回上一页
  4. Yii2邮箱发送与配置
  5. C# DateTime.ToString()的各种日期格式
  6. Struts2获取Action中的数据
  7. HTML__图片轮播ion-slide-box
  8. Mac OS X 下android环境搭建
  9. 关于hibernate的查询
  10. Js杂谈-单体模式