http://acm.hrbeu.edu.cn/index.php?act=problemid=1001cid=19 人工湖的公路

  1 #include<iostream>
  2 #define MAX 100000
  3 using namespace std;
  4 long A[MAX+1];//环形公路数据 
  5 long com[MAX+1];//树状数组 
  6 long N,M;//节点数和询问次数 
  7 
  8 long lowbit(long x)
  9 {
 10      return x&(-x);
 11 }
 12 
 13 void modify(long pos,int value)
 14 {
 15      while(pos<=N)
 16      {
 17          com[pos]+=value; 
 18          pos+=lowbit(pos);        
 19      }
 20 }
 21 
 22 long query(long x)
 23 {
 24      long sum=0;
 25      while(x>0)
 26      {
 27          sum+=com[x];
 28          x-=lowbit(x);       
 29      }
 30      return sum;
 31 }
 32 
 33 void init()
 34 {
 35      for(long i=1;i<=N;i++)
 36      {
 37          com[i]=0;        
 38      }
 39      for(long i=1;i<=N;i++)
 40      {
 41          modify(i,1);    
 42      }
 43 }
 44 
 45 void solve(long x,long y)
 46 {
 47      long sum1,sum2;
 48      sum1=query(x);
 49      sum2=query(y);
 50      if(sum2-sum1==y-x)
 51      {
 52          cout<<"YES"<<endl;
 53          return;              
 54      }
 55      long sum3;
 56      sum1=query(x);
 57      sum2=query(y);
 58      sum3=query(N);
 59      sum2=sum3-sum2;
 60      if(sum1+sum2==x+N-y)
 61      {
 62          cout<<"YES"<<endl;                
 63      }
 64      else
 65      {
 66          cout<<"NO"<<endl;
 67      }
 68 }
 69 
 70 int main()
 71 {
 72     while(cin>>N>>M)
 73     {
 74         init();
 75         for(long i=1;i<=N;i++)
 76         {
 77             A[i]=1;     
 78         }
 79         int f;
 80         long x,y;
 81         for(long i=0;i<M;i++)
 82         {
 83             cin>>f>>x>>y;
 84             if(x>y)
 85             {
 86                 long temp;
 87                 x=temp;
 88                 x=y;
 89                 y=temp;   
 90             }    
 91             if(f==0)
 92             {
 93                 if(x==1&&y==N)
 94                 {
 95                     if(A[y]==1)  
 96                     {
 97                         modify(x,-1); 
 98                         A[x]=0;       
 99                     }        
100                     else
101                     {
102                         modify(x,1);
103                         A[x]=1;
104                     }
105                 }    
106                 else
107                 {
108                     if(A[y]==1)
109                     {
110                         modify(y,-1);
111                         A[y]=0;        
112                     }
113                     else
114                     {
115                         modify(y,1);
116                         A[y]=1;
117                     }
118                 }                                     
119             }
120             else
121             {
122                 solve(x,y);
123             }
124         }      
125     }
126     return 0;
127 } 

 

#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define FOR(i,s,t) for(int i=(s); i<(t); i++)
#define BUG puts("here!!!")
#define STOP system("pause")
#define file_r(x) freopen(x, "r", stdin)
#define file_w(x) freopen(x, "w", stdout)using namespace std;const int MAX = 100010;struct Tnode{                // 一维线段树 int l,r;bool ok; int len() { return r - l;}
int mid() { return MID(l,r);}bool in(int ll,int rr) { return l >= ll && r <= rr; }void lr(int ll,int rr){ l = ll; r = rr;} }; Tnode node[MAX<<2]; void Build(int t,int l,int r) {node[t].lr(l,r);node[t].ok = true;if( node[t].len() == 1 )return ;int mid = MID(l,r);Build(L(t),l,mid);Build(R(t),mid,r); }void Updata(int t,int l,int r) {if( node[t].in(l,r) ){node[t].ok ^= 1;return ;}if( node[t].len() == 1 ) return ;int mid = node[t].mid();if( l < mid ) Updata(L(t),l,r);if( r > mid ) Updata(R(t),l,r);node[t].ok = node[L(t)].ok & node[R(t)].ok; }bool Query(int t,int l,int r) {if( l >= r ) return true;if( node[t].in(l,r) ) return node[t].ok;if( node[t].len() == 1 ) return 0;int mid = node[t].mid();bool ans = true;if( l < mid ) ans &= Query(L(t),l,r);if( r > mid ) ans &= Query(R(t),l,r);return ans; }int main() {int n, m, x, y, op;while( ~scanf("%d%d", &n, &m) ){Build(1, 1, n+1);while( m-- ){scanf("%d%d%d", &op, &x, &y);if( x > y )swap(x, y);if( op == 0 ){if( y - x > 1 )Updata(1, y, y+1);elseUpdata(1, x, y);}else{bool a = Query(1, x, y) | (Query(1, 1, x) & Query(1, y, n+1));if( a )puts("YES");elseputs("NO");}}}return 0; }

 

转载于:https://www.cnblogs.com/feiguo/archive/2012/05/26/2519511.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/262672.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

不使用注解和使用注解的web-service-dao结构

一、未使用注解的web-service-dao结构 1、action类源码 其中&#xff0c;service作为一个成员属性&#xff0c;采用的是层层调用&#xff0c;service类中dao作为一个成员属性&#xff0c;再成员方法中调用&#xff1b; 2、bean.xml中装配bean&#xff1a; 3、创建spring容器&am…

牛年牛气冲天

新年已始&#xff0c;马上将投入到新的奋斗之中&#xff0c;我们将携手共同创造新的辉煌。 把握每次机会&#xff0c;给自己和亲人一个满意的回复。 09 年是我毕业后的第三个年头&#xff0c;我会用我的行动来证明自己。 转载于:https://www.cnblogs.com/Fly-sky/archive/2009/…

awk特殊用法

一、从固定格式中取出IP所在的class&#xff0c;并列出例&#xff1a;class A { 192.168.1.1 192.168.2.1 192.168.3.1 192.168.169.69}class B { 192.168.1.1 192.168.169.69}sed -nr /\{/{:1;N;/\}/!b1;/192.168.169.69/s#^([^{]).*#\1#p} fileawk -vRScla…

XML基础——extensible markup language

一、xml概念 1、xml和html区别 其中&#xff0c;xml是纯文本文件&#xff0c;跨语言&#xff1b;浏览器有html解析器也有xml解析器&#xff1b; 2、和properties配置文件区别 二、xml语法 1、基本语法 三、xml组成部分 中国电脑默认GBK编码格式&#xff08;中文编码&#xff09…

显示单选列表对话框

通过AlertDialog.Builder类的setSingleChoiceItems方法可以创建带单按钮的列表&#xff1a;方法如下&#xff1a;1、从资源文件中装载数据&#xff1a;public Builder setSingleChoiceItems(int itemsId, int checkedItem, final OnClickListener listener)2、从数据集中装载数…

Facade模式

Facade模式 一、概述Facade&#xff08;外观&#xff09;模式为子系统中的各类&#xff08;或结构与方法&#xff09;提供一个简明一致的界面&#xff0c;隐藏子系统的复杂性&#xff0c;使子系统更加容易使用。实际应用中&#xff0c;我们在对付一些老旧的code&#xff08;尤其…

ceph启动脚本

放在/etc/init.d/目录下&#xff0c;用法如下&#xff1a; 1 rootu253:~# /etc/init.d/ceph 2 mon.a 3 usage: /etc/init.d/ceph [options] {start|stop|restart} [mon|osd|mds]... 4 -c ceph.conf 5 --valgrind run via valgrind 6 --hostname [hostname] …

全修CALL

PUSH -1PUSH 0PUSH 0CALL 005A8690ADD ESP,0Cbp send,点全修CTRLf9一直返回到没有参数 基本上这个返回就是 功能CALL 0012EB08 005869B2 返回到 elementc.005869B2 来自 elementc.0058E8A00012EB1C 00588B1F 返回到 elementc.00588B1F 来自 elementc.005869800012EB28 …

.NET框架类库中的命名空间

.NET 框架类库是一个由 Microsoft .NET 框架 SDK 中包含的类、接口和值类型组成的库。 该库提供对系统功能的访问&#xff0c;并且被设计为 .NET 框架应用程序、组件和控件的生成基础。 .NET 框架类库提供下列命名空间&#xff1a; l Microsoft.CSharp 包含支持用 C# 语言进行…

OSChina 周六乱弹 —— 这个版本的小红帽听说过吗?

2019独角兽企业重金招聘Python工程师标准>>> 想想当年刚出来工作的时候&#xff0c;小小编还真是单纯&#xff0c;以为广阔天地大有作为&#xff0c;可是呢。。。 上热门&#xff1a;刚出来工作的时候&#xff0c;大人千叮万嘱社会很复杂&#xff0c;要学会控制自己…

XML解析

一、解析xml的两种方式 1、 其中&#xff0c;xml文件被解析之后产生的dom树可能是原xml文件内存的成千上万倍&#xff0c;所以占内存&#xff1b;一般是服务器端&#xff1b; 2、sax逐行读取解析的方式&#xff0c;读一行释放一行&#xff0c;移动端采用&#xff1b; 其中&…

Arcgis Server初学笔记(一)

什么是Arcgis Server(以下简称AS)&#xff1f; AS是一个基于web的企业级GIS解决方案。AS为创建和管理基于服务器的GIS应用提供了一个高效的框架平台。AS宿主了各种GIS资源&#xff0c;并把他们作为服务发送到客户端。Accgis Server架构 AS是一个分布系统&#xff0c;…

XML解析——Jsoup解析器

一、Jsoup解析器快速入门案例 Docement对象&#xff0c;文本对象&#xff0c;包含着各个Dom树结构 1、引入Jsoup解析器的jar包放在lib文件夹下后&#xff0c;写java代码 其中&#xff0c; 二、Jsoup对象 1、Jsoup解析器解析xml和html的有关对象 其中&#xff0c;通过统计资源定…

Linux下MPlayer的安装

Linux下MPlayer的安装 收藏 mplayer是linux下播放速度最快(正确安装了显卡驱动)&#xff0c;支持媒体格式最多的播放器之一 &#xff0c;它几乎能播放所有的win媒体文件&#xff01;下面介绍它的安装方法&#xff1a; 安装大前提: 要编译这个软件,确认你系统安装了相应的XFree…

jQuery缓存数据——仿Map

2019独角兽企业重金招聘Python工程师标准>>> 最近在工作中遇到了这样一个情景。有些数据是从后台读取的&#xff0c;但是我暂时不需要展示在页面上&#xff0c;那怎么办呀&#xff1f;——缓存呀。今天我就来分享一下我所了解的Jquery缓存数据的方法。 首先分享1篇博…

【摘抄】百度分词算法详解:查询处理以及分词技术

随着搜索经济的崛起&#xff0c;人们开始越加关注全球各大搜索引擎的性能、技术和日流量。作为企业&#xff0c;会根据搜索引擎的知名度以及日流量来选择是否要投放广告等&#xff1b;作为 普通网民&#xff0c;会根据搜索引擎的性能和技术来选择自己喜欢的引擎查找资料&#x…

Jsoup快速查询

一、selector选择器 二、Xpath查询 转载于:https://www.cnblogs.com/wmqiang/p/11568184.html

ShellAPI 调用搜索引擎

//调用搜索引擎 uses ShellAPI;//google web searchprocedure TForm1.Button1Click(Sender: TObject);var SearchStr:PWideChar; SearchEngineStr:string;begin SearchEngineStr:http://search.yahoo.com/search?p; SearchStr:PWideChar(SearchEngineStr Edit1.Text); …

read name 和 read 在 Bash 中的区别

read 带一个参数和不带参数的区别是什么&#xff0c;我本以为仅仅是被赋值的变量的名字不同而已&#xff1a; $ read name 1 $ echo "$name" 1 $ read 1 $ echo "$REPLY" 1 当没有指定变量名时&#xff0c;read 会给默认的变量 REPLY 赋值&#xff0c;仅此…

李开复:2009地图与移动搜索快速增长

新浪科技讯 2月20日下午消息&#xff0c;谷歌大中华区总裁李开复今日召开媒体见面会&#xff0c;探讨谷歌2009年的发展重点和方向&#xff0c;李开复称地图与移动搜索将会迅速成长。以下为文字实录&#xff1a; 李开复&#xff1a;Google每次有员工大会&#xff0c;会把在北京、…