Physical Education Lessons Codeforces - 915E
http://codeforces.com/problemset/problem/915/E
大概有几种思路:
1.动态开点线段树+标记下传
#1.1标记永久化:想了一会没想出来
1.2可以先扫一遍询问把所有需要的点建出来,然后pushdown就不管没建出来的点了,空间跟标记永久化一样
2.离散化+线段树
3.用splay维护区间(估计没人愿意去写)
4.用一个set<pair<int,int>>记所有非工作日(或工作日)区间,修改就暴力找到相关的区间去改
由于每一次操作最多多出O(1)个区间,因此尽管有时会一次删掉多个区间,但复杂度是对的
#include<cstdio>
#include<algorithm>
#include<set>
#define fi first
#define se second
using namespace std;
typedef pair<int,int> P;
set<P> s;
set<P>::iterator it;
int ans,n,q;
int main()
{
int i,idx,l,r;P t;
scanf("%d%d",&n,&q);ans=n;s.insert(P(n,));
while(q--)
{
scanf("%d%d%d",&l,&r,&idx);
it=s.lower_bound(P(l,));
if(it!=s.end()&&it->se<=l)
{
t=*it;s.erase(it);
if(l!=t.se) s.insert(P(l-,t.se));
s.insert(P(t.fi,l));
}
it=s.lower_bound(P(r,));
if(it!=s.end()&&it->se<=r)
{
t=*it;s.erase(it);
if(t.fi!=r) s.insert(P(t.fi,r+));
s.insert(P(r,t.se));
}
for(it=s.lower_bound(P(l,));it!=s.end()&&it->fi<=r;it=s.lower_bound(P(l,)))
ans-=it->fi-it->se+,s.erase(it);
if(idx==) s.insert(P(r,l)),ans+=r-l+;
printf("%d\n",ans);
}
return ;
}
Physical Education Lessons Codeforces - 915E的更多相关文章
- Physical Education Lessons CodeForces - 915E (动态开点线段树)
Physical Education Lessons CodeForces - 915E This year Alex has finished school, and now he is a fir ...
- Codeforces 915E Physical Education Lessons
原题传送门 我承认,比赛的时候在C题上卡了好久(最后也不会),15min水掉D后(最后还FST了..),看到E时已经只剩15min了.尽管一眼看出是离散化+线段树的裸题,但是没有时间写,实在尴尬. 赛 ...
- Codeforces 915E. Physical Education Lessons(动态开点线段树)
E. Physical Education Lessons 题目:一段长度为n的区间初始全为1,每次成段赋值0或1,求每次操作后的区间总和.(n<=1e9,q<=3e5) 题意:用线段树做 ...
- Codeforces 915 E Physical Education Lessons
题目描述 This year Alex has finished school, and now he is a first-year student of Berland State Univers ...
- 【CodeForces】915 E. Physical Education Lessons 线段树
[题目]E. Physical Education Lessons [题意]10^9范围的区间覆盖,至多3*10^5次区间询问. [算法]线段树 [题解]每次询问至多增加两段区间,提前括号分段后线段树 ...
- CF915E Physical Education Lessons 动态开点线段树
题目链接 CF915E Physical Education Lessons 题解 动态开点线段树 代码 /* 动态开点线段树 */ #include<cstdio> #include&l ...
- 【题解】Luogu CF915E Physical Education Lessons
原题传送门:CF915E Physical Education Lessons 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 这道题很简单啊 每个操作就是区间赋值,顺带把总和修 ...
- CF915E Physical Education Lessons
题意: Alex高中毕业了,他现在是大学新生.虽然他学习编程,但他还是要上体育课,这对他来说完全是一个意外.快要期末了,但是不幸的Alex的体育学分还是零蛋! Alex可不希望被开除,他想知道到期末还 ...
- 线段树 离散化 E. Infinite Inversions E. Physical Education Lessons
题目一:E. Infinite Inversions 这个题目没什么思维量,还比较简单,就是离散化要加上每一个值的后面一个值,然后每一个值放进去的不是1 ,而是这个值与下一个点的差值. 因为这个数代表 ...
随机推荐
- HNU 12834 Thread Tree
递归输出即可了 #include<bits/stdc++.h> using namespace std; struct tree{ int dot; string s; } ...
- Centos 6.x 安装Nagios及WEB管理nagiosql实现windows及linux监控指南
一.Nagios简介 Nagios是一款开源的电脑系统和网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等.在系统或服务状态异常时发出邮件或短信报 ...
- Linux性能诊断工具
vmstat:虚拟内存状况 –swpd free buff cache si so in cs 參考:http://www.cnblogs.com/ggjucheng/archi ...
- 重载OverLoad。隐藏new
<1> using System; using System.Collections.Generic; using System.Linq; using System.Text; name ...
- 故障案例:磁盘空间不足可能引起的mysql问题
此前在工作中.由于客户的磁盘空间报警没怎么注意.空间不足引起了下面可能发生的mysql问题 1 mysql进程起不来 2 mysql无法正常关闭,必须kill -9 3 mysql能 ...
- 2016/2/29 html 思维导图
- C#生成Excel文件后彻底解除占用代码(来着CSDN)
http://bbs.csdn.net/topics/280078428 jy251 LS说KILL进程的朋友们···我说...你们真行!!!如果用户是administrator还行,如果不是怎么办? ...
- JDK各版本内容和新特性
JDK各版本内容和新特性 - yanlzhl - 博客园 https://www.cnblogs.com/yanlzhl/articles/5694470.html 版本JDK1.0:1995年 ...
- POJ - 3177 Redundant Paths(边双连通分支)(模板)
1.给定一个连通的无向图G,至少要添加几条边,才能使其变为双连通图. 2. 3. //边双连通分支 /* 去掉桥,其余的连通分支就是边双连通分支了.一个有桥的连通图要变成边双连通图的话, 把双连通子图 ...
- 并不对劲的loj2179:p3714:[BJOI2017]树的难题
题目大意 有一棵树,\(n\)(\(n\leq2*10^5\))个点,每条边\(i\)有颜色\(w_i\),共有\(m\)(\(m\leq n\))种颜色,第\(i\)种颜色的权值是\(c_i\)(\ ...