当前位置: 首页 > news >正文

bzoj 1067 特判

  这道题的大题思路就是模拟

  假设给定的年份是x,y,首先分为4个大的情况,分别是

  x的信息已知,y的信息已知

  x的信息已知,y的信息未知

  x的信息未知,y的情况已知

  x的信息未知,y的情况未知

  然后对于每一种情况可以根据x到y区间是否存在空位,最大值是否唯一,以及x,y,区间最大值的关系来判定。

  所以对于区间的问题的合并与处理我们用线段树来存就行了。

  反思:开始对情况的优先级判断不清,没有整理好思路就开始写。最后发现线段树的合并函数写错了。

/**************************************************************
    Problem: 1067
    User: BLADEVIL
    Language: Pascal
    Result: Accepted
    Time:580 ms
    Memory:5304 kb
****************************************************************/
 
//By BLADEVIL
type
    rec                     =record
        left, right         :longint;
        max                 :longint;
        flag, flag2         :boolean;
        pred, succ          :longint;
    end;
 
var
    n, m                    :longint;
    a, b                    :array[0..50010] of longint;
    t                       :array[0..200010] of rec;
     
function getmax(a,b:longint):longint;
begin
    if a>b then exit(a) else exit(b);
end;
     
function combine(a,b:rec):rec;
begin
    with combine do
    begin
        max:=getmax(a.max,b.max);
        pred:=a.pred;
        succ:=b.succ;
        if a.succ=b.pred-1 then flag:=true else flag:=false;
        flag:=flag and a.flag and b.flag;
         
        if a.max=b.max then flag2:=false else flag2:=true;
        if max=a.max then flag2:=flag2 and a.flag2;
        if max=b.max then flag2:=flag2 and b.flag2;
        left:=a.left;
        right:=b.right;
    end;
end;
     
procedure build(x,l,r:longint);
var
    mid                     :longint;
begin
    t[x].left:=l; t[x].right:=r;
    if l=r then
    begin
        with t[x] do
        begin
            pred:=a[l];
            succ:=a[l];
            flag2:=true;
            max:=b[l];
            flag:=true;
        end;
        exit;
    end;
    with t[x] do mid:=(left+right)>>1;
    build(x<<1,l,mid); build(x<<1+1,mid+1,r);
    t[x]:=combine(t[x<<1],t[x<<1+1]);
end;    
     
procedure init;
var
    i                       :longint;
begin
    read(n);
    for i:=1 to n do read(a[i],b[i]);
    a[0]:=-1;
    build(1,1,n);
end;
 
function getadress(x:longint):longint;
var
    l, r, mid               :longint;
    ans                     :longint;
begin
    l:=1; r:=n;
    ans:=0;
    while l<=r do
    begin
        mid:=(l+r)>>1;
        if a[mid]<=x then
        begin
            ans:=mid;
            l:=mid+1;
        end else r:=mid-1;
    end;
    exit(ans);
end;
 
function ask(x,l,r:longint):rec;
var
    mid                     :longint;
begin
    if (t[x].left=l) and (t[x].right=r) then
        exit(t[x]);
    with t[x] do mid:=(left+right)>>1;
    if mid<l then exit(ask(x<<1+1,l,r)) else
    if mid>=r then exit(ask(x<<1,l,r)) else
        exit(combine(ask(x<<1,l,mid),ask(x<<1+1,mid+1,r)));
end;
 
procedure main;
var
    i                       :longint;
    x, y                    :longint;
    u, v                    :longint;
    query                   :rec;
     
begin
    read(m);
    for i:=1 to m do
    begin
        read(x,y);
        if x>y then
        begin
            writeln('false');
            continue;
        end;
        if x=y then
        begin
            writeln('true');
            continue;
        end;
        u:=getadress(x);
        v:=getadress(y);
        if (a[u]=x) and (a[v]=y) then
        begin
            if b[v]>b[u] then
            begin
                writeln('false');
                continue;
            end;
            query:=ask(1,u+1,v);
            if not query.flag2 then
            begin
                writeln('false');
                continue;
            end;
            if query.max<>b[v] then
            begin
                writeln('false');
                continue;
            end;
            query:=ask(1,u,v);
            if not query.flag then
            begin
                writeln('maybe');
                continue;
            end else
            begin
                writeln('true');
                continue;
            end;
        end else
        if (a[u]<>x) and (a[v]<>y) then
        begin
            writeln('maybe');
            continue;
        end else
        if (a[u]=x) and (a[v]<>y) then
        begin
            if u=v then
            begin
                writeln('maybe');
                continue;
            end;
            query:=ask(1,u+1,v);
            if query.max>=b[u] then
            begin
                writeln('false');
                continue;
            end else
            begin
                writeln('maybe');
                continue;
            end;
        end else
        if (a[u]<>x) and (a[v]=y) then
        begin
            if u=v then
            begin
                writeln('maybe');
                continue;
            end;
            query:=ask(1,u+1,v);
            if not query.flag2 then
            begin
                writeln('false');
                continue;
            end;
            if query.max<>b[v] then
            begin
                writeln('false');
                continue;
            end else
            begin
                writeln('maybe');
                continue;
            end;
        end;
    end;
end;
 
begin
    init;
    main;
end.
 

 

转载于:https://www.cnblogs.com/BLADEVIL/p/3530254.html

相关文章:

  • 【实验】修改数据文件名字的三种途径
  • 开发中的版本问题(2)—配置tomcat使用特定的jdk版本
  • 枚举格式化字符串
  • 安装CentOS 6停在selinux-policy-targeted卡住的问题解决
  • DB_NAME,DB_UNIQUE_NAME 和 SID 的理解
  • 域名劫持的问题从组织上着手解决也是重要的一环
  • 分享我的个人项目:Wildfire 野火评论系统
  • Linux(Ubuntu)下面SecureCRT 完全破解
  • iOS 画虚线的重新理解
  • 没有方向,不叫发展
  • vmstat命令之linux性能分析
  • Tiny并行计算框架之实现机理
  • (转)大道至简,职场上做人做事做管理
  • RabbitMQ 入门指南(Java)
  • iOS用libcurl发起一个get请求,并保存返回数据到沙盒
  • .pyc 想到的一些问题
  • [js高手之路]搞清楚面向对象,必须要理解对象在创建过程中的内存表示
  • Angular6错误 Service: No provider for Renderer2
  • AWS实战 - 利用IAM对S3做访问控制
  • ESLint简单操作
  • es的写入过程
  • IIS 10 PHP CGI 设置 PHP_INI_SCAN_DIR
  • Material Design
  • nodejs实现webservice问题总结
  • Python 使用 Tornado 框架实现 WebHook 自动部署 Git 项目
  • Python十分钟制作属于你自己的个性logo
  • Rancher-k8s加速安装文档
  • React16时代,该用什么姿势写 React ?
  • SQLServer之索引简介
  • TypeScript迭代器
  • 不发不行!Netty集成文字图片聊天室外加TCP/IP软硬件通信
  • 动态规划入门(以爬楼梯为例)
  • 排序算法学习笔记
  • Oracle Portal 11g Diagnostics using Remote Diagnostic Agent (RDA) [ID 1059805.
  • shell使用lftp连接ftp和sftp,并可以指定私钥
  • ​LeetCode解法汇总2583. 二叉树中的第 K 大层和
  • ​软考-高级-系统架构设计师教程(清华第2版)【第15章 面向服务架构设计理论与实践(P527~554)-思维导图】​
  • ​学习一下,什么是预包装食品?​
  • $.ajax()参数及用法
  • (附源码)python房屋租赁管理系统 毕业设计 745613
  • (附源码)spring boot火车票售卖系统 毕业设计 211004
  • (附源码)ssm基于jsp高校选课系统 毕业设计 291627
  • (六)软件测试分工
  • (原创) cocos2dx使用Curl连接网络(客户端)
  • (源码版)2024美国大学生数学建模E题财产保险的可持续模型详解思路+具体代码季节性时序预测SARIMA天气预测建模
  • (转)MVC3 类型“System.Web.Mvc.ModelClientValidationRule”同时存在
  • .NET Core、DNX、DNU、DNVM、MVC6学习资料
  • .NET Core6.0 MVC+layui+SqlSugar 简单增删改查
  • .NET 表达式计算:Expression Evaluator
  • .NET企业级应用架构设计系列之开场白
  • .py文件应该怎样打开?
  • .secret勒索病毒数据恢复|金蝶、用友、管家婆、OA、速达、ERP等软件数据库恢复
  • [ 云计算 | AWS ] 对比分析:Amazon SNS 与 SQS 消息服务的异同与选择
  • [2021ICPC济南 L] Strange Series (Bell 数 多项式exp)
  • [2024最新教程]地表最强AGI:Claude 3注册账号/登录账号/访问方法,小白教程包教包会