19-10-15-W
暴力终于不跪了$\text{QvQ}$
z总j结
考试开始看到几个大字:Day1
Happy~(××终于不用爆〇了哈哈哈哈!!)
开T1。一看,不是在线仙人球嵌套动态网络路径剖分优化的分支定界贪心剪枝启发式迭代加深人工智能搜索决策算法么……好!
码完一看,过不了大阳历……
关于大阳历,我是这么评价她的……
不给大阳历嫌他不给了,给了又过不了=.=
发现贪心错了。
于是马上……(×××的day1)
看T2。
发现是数学,研究一番,推了一番柿子,然后就弃了。
这时我有点慌了(开考$1h$啥都没打??)
于是马上看T3(?)
暴力好打$\text{QvQ}$
打完T3回去想了下T1
码了一个$\Theta(N^2\log N)$的法子(全是在线仙人球嵌套动态网络路径剖分优化的分支定界贪心剪枝启发式迭代加深人工智能搜索决策算法)
然后T2的暴力也出来了。
最后是……
|
28
|
Miemeng | 70
03:11:56
|
30
03:11:57
|
50
03:11:57
|
150
03:11:57
|
T1
法1
讲个我的$\Theta(N^2\log N)$
想到了让点找段,但是没来得及打。
于是我让段找点。
但是从左往右扫一定会死,因为贪心……
于是我想到可以维护段内的点数来贪。
从内部点数最少的段向更大的段贪。
每次修改都要重新计算和 sort
交上去$70$
(话说为啥本地对拍一直WA)
#include <algorithm>
#include <iostream>
#include <climits>
#include <cstring>
#include <cstdio>
#define N 222222 using namespace std; struct Seg{
int l,r;
int pn;
}dse[N];
int dpo[N],sen,pon,ans=0;
bool is_del[N];
int findv(int val){
return lower_bound(dpo+1,dpo+pon+1,val)-dpo;
}
inline bool CMP(const Seg &a,const Seg &b){
return a.pn<b.pn;
}
int main(){
// freopen("dream.in" ,"r",stdin);\
freopen("dream.out","w",stdout);
scanf("%d%d",&sen,&pon);
for(int i=1;i<=sen;i++)
scanf("%d%d",&dse[i].l,&dse[i].r);
for(int i=1;i<=pon;i++)
scanf("%d",dpo+i);
sort(dpo+1,dpo+pon+1);
for(int i=1;i<=sen;i++){
dse[i].pn=findv(dse[i].r+1)-findv(dse[i].l);
}
sort(dse+1,dse+sen+1,CMP);
for(int i=1;i<=sen;i++){
// cout<<dse[i].l<<" "<<dse[i].r<<" "<<dse[i].pn<<endl;
int l=findv(dse[i].l),
r=findv(dse[i].r+1);
bool is_c=0;
// cout<<"["<<dpo[l]<<","<<dpo[r]<<")"<<endl;
if(l<r){
// cout<<i<<" ++++ "<<endl;
is_c=1;
dpo[l]=INT_MAX;
ans++;
}
if(is_c){
sort(dpo+1,dpo+pon+1);
for(int k=i+1;k<=sen;k++){
dse[k].pn=findv(dse[k].r+1)-findv(dse[k].l);
}
sort(dse+i+1,dse+sen+1,CMP);
}
}
printf("%d\n",ans);
}
正解……
点找段,堆优化……
首先对于每一个懵点,从左到右扫,一定是能覆盖它且右端点更靠左的更优。
于是用堆优化这个过程。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue> #define N 222222 using namespace std; struct Seg{
int l,r;
friend bool operator < (const Seg &a,const Seg &b){
return a.r>b.r;
}
}seg[N];
int sen,pn;
void pour(priority_queue<Seg>s){
puts("---------===VV===----------");
while(!s.empty()){
cout<<s.top().l<<" "<<s.top().r<<endl;
s.pop();
}
puts("---------===^^===----------");
}
priority_queue<Seg>q;
int po[N],ans=0;
int main(){
scanf("%d%d",&sen,&pn);
for(int i=1;i<=sen;i++)
scanf("%d%d",&seg[i].l,&seg[i].r);
for(int i=1;i<=pn;i++)
scanf("%d",po+i);
sort(po+1,po+pn+1);
sort(seg+1,seg+sen+1,[](const Seg &a,const Seg &b){return a.l<b.l;});
int sid=1;
for(int i=1;i<=pn;i++){
while(sid<=sen && seg[sid].l<=po[i])q.push(seg[sid]),sid++;
while(!q.empty() && q.top().r<po[i])q.pop();
if(!q.empty() && q.top().l<=po[i] && po[i]<=q.top().r){
ans++;
q.pop();
}
}
printf("%d\n",ans);
}
T2
很显然(不会)的$dp$
T3
莫队直接过,$\Theta(1)$转移一下就好了。
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#define N 222222 using namespace std; struct Query{
int l,r;
int id;
}qs[N];
struct SR{
int next,t;
}rs[2*N];
int pn,qn,
fl[N],
inp[N],
ans[N],
fa[N],
ason[N],
pl,
nans,
cnt=0;
bool isc[N]; inline bool CMP(const Query &a,const Query &b){
return inp[a.l]==inp[b.l]?(inp[a.l]&1?a.r<b.r:a.r>b.r):inp[a.l]<inp[b.l];
}
void add(int f,int t){
rs[cnt].t=t;
rs[cnt].next=fl[f];
fl[f]=cnt++;
}
void dfs(int k,int pre){
for(int i=fl[k];i!=-1;i=rs[i].next){
int t=rs[i].t;
if(t!=pre){
fa[t]=k;
dfs(t,k);
}
}
}
void add(int id){
ason[fa[id]]++;
nans-=ason[id]+isc[fa[id]]-1;
isc[id]=true;
}
void del(int id){
ason[fa[id]]--;
nans+=ason[id]+isc[fa[id]]-1;
isc[id]=false;
}
int main(){
int a,b;
memset(fl,-1,sizeof fl);
scanf("%d%d",&pn,&qn);pl=sqrt(pn)+1;
for(int i=1;i<=pn;i++)
inp[i]=(i-1)/pl+1;
for(int i=1;i<pn;i++){
scanf("%d%d",&a,&b);
add(a,b);
add(b,a);
}
dfs(1,0);
for(int i=1;i<=qn;i++){
scanf("%d%d",&qs[i].l,&qs[i].r);
qs[i].id=i;
}
sort(qs+1,qs+qn+1,CMP);
int l=1,r=1;
add(1);
for(int i=1;i<=qn;i++){
while(l>=qs[i].l){
l--;
add(l);
}
while(r<=qs[i].r){
r++;
add(r);
}
while(l<qs[i].l){
del(l);
l++;
}
while(r>qs[i].r){
del(r);
r--;
}
ans[qs[i].id]=nans;
}
for(int i=1;i<=qn;i++)
printf("%d\n",ans[i]);
}
19-10-15-W的更多相关文章
- 程序员的 Ubuntu 19.10 配置与优化指南
原文地址:程序员的 Ubuntu 19.10 配置与优化指南 0x00 环境 CPU: Intel Core i9-9900k GPU: GeForce RTX 2070 SUPER RAM: DDR ...
- 7.12-7.19 id、w、who、last、lastb、lastlog
7.12-7.19 id.w.who.last.lastb.lastlog 目录 7.12 id:显示用户与用户组的信息 7.13 w:显示已登录用户信息 7.14 who:显示已登录用户信息 显示最 ...
- CVE-2015-1328 Ubuntu 12.04, 14.04, 14.10, 15.04 overlayfs Local Root
catalog . 引言 . Description . Effected Scope . Exploit Analysis . Principle Of Vulnerability . Patch ...
- macOS 10.15 Catalina Apache设置:多个PHP版本
第1部分:macOS 10.15 Catalina Web开发环境 在macOS上开发Web应用程序真是令人高兴.有许多设置开发环境的选项,包括广受欢迎的MAMP Pro,它在Apache,PHP和M ...
- 背水一战 Windows 10 (15) - 动画: 缓动动画
[源码下载] 背水一战 Windows 10 (15) - 动画: 缓动动画 作者:webabcd 介绍背水一战 Windows 10 之 动画 缓动动画 - easing 示例演示缓动(easing ...
- Linux Kernel 3.11.4/3.10.15/3.4.65/3.0.99
Linux 今天又发布了4个更新版本,分别是: 3.11.4 2013-10-05 [tar.xz] [pgp] [patch] [view patch] [view inc] [cgit] [cha ...
- WTL汉化版2013.10.15
汉化内容: 2013.10.15 版本:当前可下载Trunk最新版,wtl-code-467-trunk.zip 汉化内容: 1.应用向导的部分汉化,考虑到部分词汇的表述问题,只汉化无影响部分 2.资 ...
- [Mon Feb 10 15:21:06 2014] [notice] child pid 7101 exit signal File size limit exceeded (25)
今天遇到的问题: LAMP的LOG里报如下错误. 然后IE和FIREFOX里显示连接被重置或是无法访问. 但自己建一个正常的PHP测试探针倒可以. 原来是PHP错误日志太多,无法写入LOG导致. [r ...
- Datatables插件1.10.15版本服务器处理模式ajax获取分页数据实例解析
一.问题描述 前端需要使用表格来展示数据,找了一些插件,最后确定使用dataTables组件来做. 后端的分页接口已经写好了,不能修改.接口需要传入页码(pageNumber)和页面显示数据条数(pa ...
- Ubuntu 19.10 发布 | 云原生生态周报 Vol. 24
作者 | 木苏.进超.冬岛.元毅.心水.衷源 业界要闻 1.云原生编程语言 Pulumi 1.0 pulumi ,一款中立的开源云开发平台,Pulumi 支持多语言.混合云环境.完全可扩展.初期支持 ...
随机推荐
- XAMPP的安装及使用教程
https://blog.csdn.net/qq_36595013/article/details/80373597#3%E9%85%8D%E7%BD%AEapache
- linux操作练习题
linux操作练习题 一.总结 一句话总结: 多练练一下子就会了,很简单的 1.在当前目录下建立文件exam.c,将文件exam.c拷贝到/tmp这个目录下,并改名为 shiyan.c? touch ...
- spring源码读书笔记
如果我们在web项目里面使用spring的话,通常会在web.xml里面配置一个listener. <listener> <listener-class> org.spring ...
- 数据库小技巧:使用distinct去除重复行
这里有2个表 问题question表 楼层question_floor表 需求:已知某用户的id为uid,实现“我的回复”功能,即查看我回复的所有问题 遇到的问题:如果直接对question表和que ...
- ie9table排列不对.td错行,多了一列
发现问题是ie9,本地用google/ie11都是好的. 有合并行的问题,本来就5列,偏偏莫名其妙多了一列,某一行上就有一个单元格空着,往后推了一列,刷新无数次都是同一行错位. 略微改动一下jsp(删 ...
- 6_1.springboot2.x整合JDBC与数据源配置原理解析
1.引言 对于数据访问层,无论是SQL还是NOSQL,Spring Boot默认采用整合 Spring Data的方式进行统一处理,添加大量自动配置,屏蔽了很多设置.引入各种xxxTemplate,x ...
- 我最恨ubuntu的自动升级内核功能
总是提示我boot分区空间不足, 怎么办, 删除原有不用的内核呗,手动来做. 1.查看当前使用内核版本号.输入 uname -a 查看.uname -a 2.删除旧内核. 切换root: su 输入命 ...
- android 使用现成做get请求
//接受子线程发来的消息 Handler hanler = new Handler() { @Override public void handleMessage(Message msg) { // ...
- python全栈开发:hashlib加密
哈希加密代码 #!/usr/bin/env python # -*- coding;utf-8 -*- """ 哈希加密模块中有很多算法,调用不同的算法执行不同的加密, ...
- Codeforces 839D Winter is here
链接:CF839D 题目大意 给定一个数组大小为\(n(1\leq n\leq 200000)\)的数组\(a\),满足\(1\leq a_i \leq 1000000\). 选择其中任意\(len\ ...