题意

分析

我们将所有修改操作的左右端点都拿出来混合着排序。
然后扫描线一样扫描每个端点,维护一个堆储存当前最大值,然后就可以把这些修改操作分成O(m) 个不相交的区间,各自贡献独立。
复杂度为\(O(m \log m)\)。

浅谈扫描线

把每个区间的l,r+1的左闭右开区间端点混合排序后,其实在扫描左闭右开的区间过程中主要是以下4种情况:

  1. 前一个是l1,这一个是l2,那么其实要加的是[l1,l2-1]这个区间,而l2-1-l1+1=l2-l1
  2. 前一个是l1,这一个是r2+1,那么要加的是[l1,r2]这个区间,而r2-l1+1=r2+1-l1
  3. 前一个是r1+1,这一个是l2,那么要加的是[r1+1,l2-1]这个区间,而l2-1-r1-1+1=l2-r1-1
  4. 前一个是r1+1,这一个是r2+1,那么要加的是[r1+1,r2]这个区间,而r2+1-r1-1=r2-r1-1+1

所以可以直接对区间端点执行减操作,统计答案。
左闭右开区间真好用。

代码

#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<ctime>
#include<iostream>
#include<string>
#include<vector>
#include<list>
#include<deque>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<complex>
#pragma GCC optimize ("O0")
using namespace std;
template<class T> inline T read(T&x)
{
    T data=0;
    int w=1;
    char ch=getchar();
    while(!isdigit(ch))
    {
        if(ch=='-')
            w=-1;
        ch=getchar();
    }
    while(isdigit(ch))
        data=10*data+ch-'0',ch=getchar();
    return x=data*w;
}
typedef long long ll;
typedef pair<ll,ll> pii;
const int INF=0x7fffffff;

const int MAXN=1e5+7,mod=998244353;

ll maxv[MAXN];

pii A[MAXN<<1];
int sz;

multiset<ll>S;
ll ans;

int pow2(ll x)
{
    x%=mod;
    return (ll)x*x%mod;
}

void addedge(ll x,ll y)
{
    if(S.empty())
        return;
    (ans += (ll)( y-x ) % mod * pow2( *S.rbegin() ) % mod ) %= mod;
}

int main()
{
  freopen("segment.in","r",stdin);
  freopen("segment.out","w",stdout);
    ll n;
    int m;
    read(n);read(m);
    for(int i=1;i<=m;++i)
    {
        ll l,r;
        read(l);read(r);read(maxv[i]);
        A[++sz]=pii(l,i);
        A[++sz]=pii(r+1,-i);
    }
    sort(A+1,A+sz+1);
    for(int i=1;i<=sz;++i)
    {
        if(i > 1 && A[i-1].first < A[i].first)
            addedge(A[i-1].first,A[i].first);
        if(A[i].second > 0)
            S.insert(maxv[A[i].second]);
        else
            S.erase(maxv[-A[i].second]);
    }
    printf("%lld",ans);
//  fclose(stdin);
//  fclose(stdout);
    return 0;
}

test20180919 区间最大值的更多相关文章

  1. POJ2482 Stars in Your Window 和 test20180919 区间最大值

    Stars in Your Window Language:Default Stars in Your Window Time Limit: 1000MS Memory Limit: 65536K T ...

  2. POJ3264 Balanced Lineup 线段树区间最大值 最小值

    Q个数 问区间最大值-区间最小值 // #pragma comment(linker, "/STACK:1024000000,1024000000") #include <i ...

  3. hdoj 2795 Billboard【线段树区间最大值】

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  4. hdoj1754 I Hate It【线段树区间最大值维护+单点更新】

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  5. HDU 2795 Billboard 线段树,区间最大值,单点更新

    Billboard Time Limit: 20000/8000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  6. HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值)

    HDOJ(HDU).1754 I Hate It (ST 单点替换 区间最大值) 点我挑战题目 题意分析 从题目中可以看出是大数据的输入,和大量询问.基本操作有: 1.Q(i,j)代表求区间max(a ...

  7. 2018中国大学生程序设计竞赛 - 网络选拔赛 1010 YJJ's Salesman 【离散化+树状数组维护区间最大值】

    题目传送门:http://acm.hdu.edu.cn/showproblem.php?pid=6447 YJJ's Salesman Time Limit: 4000/2000 MS (Java/O ...

  8. HDU - 1754 I Hate It (线段树单点修改,求区间最大值)

    很多学校流行一种比较的习惯.老师们很喜欢询问,从某某到某某当中,分数最高的是多少. 这让很多学生很反感. 不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问.当然,老师有 ...

  9. Codeforces Round #321 (Div. 2)-B. Kefa and Company,区间最大值!

    ->链接在此<- B. Kefa and Company time limit per test 2 seconds memory limit per test 256 megabytes ...

随机推荐

  1. win10 自己DIY的arp绑定小脚本

    @echo off&mode con cols=80 lines=22&title ARP_bind Tools setlocal enabledelayedexpansion rem ...

  2. centos 7安装vmtools时提示The path "" is not a valid path to the xxx kernel headers.

    解决办法: yum -y install kernel-headers kernel-devel gcc reboot

  3. inherit

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace { cl ...

  4. Authentication failed (rejected by the remote node), please check the Erlang

    官网提供的解决方案 Synchronise Erlang Cookies (when running a manually installedWindows Service) Erlang Secur ...

  5. POJ 2499 A*求第K短路

    DES就是给你一个图.然后给你起点和终点.问你从起点到终点的第K短路. 第一次接触A*算法. 题目链接:Remmarguts' Date 转载:http://blog.csdn.net/mbxc816 ...

  6. PatePoco中对sql参数化时Top参数化的问题

    PatePoco中对sql参数化是直接用@+参数名来处理,但是想用如下语句时竟然报错了 SELECT TOP @num * FROM tableA 执行时抛出异常,根据错误提示搞了很久都没找到原因,最 ...

  7. Cetus

    转自:https://github.com/Lede-Inc/cetus Cetus 简介 Cetus是由C语言开发的关系型数据库MySQL的中间件,主要提供了一个全面的数据库访问代理功能.Cetus ...

  8. Python sqlalchemy使用

    import sqlalchemy from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declar ...

  9. Struts2自定义拦截器——完整实例代码

    比如一个网上论坛过滤系统,将网友发表的不文明.不和谐的语言,通过拦截器对这些文字进行自动替代. 该项目包含: 1.自定义拦截器(MyInterceptor.java) 2.发表评论的页面(news.j ...

  10. MyEclipse教程:使用UML创建模块库——第一部分(二)

    MyEclipse 在线购买低至75折!火爆开抢>> [MyEclipse最新版下载] UML1建模文件存储在建模库中,建模可用于生成Java代码,或者可以从代码中生成模型.本教程将向您展 ...