NOIp 0910 爆零记
这套题是神犇chty出的。
刚拿到题的时候有点懵逼,因为按照一般的套路第一题都是一眼题,但是看到第一题后想了很多个算法和数据结构好像都不能很好的解决。然后就随手敲了个暴力去看T2。
嗯...文件名是bag这道题还真就是bag,听说是分组背包?背包现在我也就会个0/1了,所以怒上并查集优化相对关系。顺利AC
//T2
//by Cydiater
//2016.9.10
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <queue>
#include <map>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
using namespace std;
#define ll long long
#define up(i,j,n) for(int i=j;i<=n;i++)
#define down(i,j,n) for(int i=j;i>=n;i--)
#define FILE "bag"
;
const int oo=0x3f3f3f3f;
inline int read(){
,f=;
;ch=getchar();}
+ch-';ch=getchar();}
return x*f;
}
],Ans=,q[MAXN];
struct _data{
int v,group_id,w;
}a[MAXN];
namespace solution{
int getf(int k){
if(f[k]==k)return k;
f[k]=getf(f[k]);
return f[k];
}
inline void merge(int x,int y){f[getf(x)]=getf(y);}
inline bool cmp(_data x,_data y){return x.group_id<y.group_id;}
void init(){
N=read();M=read();K=read();
up(i,,N){
a[i].v=read();
a[i].w=read();
f[i]=i;
}
up(i,,K){
int x=read(),y=read();
merge(x,y);
}
up(i,,N)a[i].group_id=getf(i);
sort(a+,a+N+,cmp);
}
void DP(){
a[].group_id=;
up(i,,N){
].group_id){
head=;tail=;q[++tail]=i++;
].group_id)q[++tail]=i++;i--;
}
down(k,M,)up(j,head,tail){
int id=q[j];
if(a[id].w+k<=M){
ans[a[id].w+k]=max(ans[a[id].w+k],ans[k]+a[id].v);
Ans=max(Ans,ans[a[id].w+k]);
}
}
}
}
void output(){
cout<<Ans<<endl;
}
}
int main(){
freopen(FILE".in","r",stdin);
freopen(FILE".out","w",stdout);
//freopen("input.in","r",stdin);
using namespace solution;
init();
DP();
output();
;
}
T2
然后扭过头去看T1了...看着题,开始想怎么优化线段树..想了五分钟,弃疗。正准备去看第三题,忽然想到貌似这个是莫队的模板题。敲了一下,不是很放心,拍了半小时,好像没什么问题。就交了。
//test for bat
//by Cydiater
//2016.9.10
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <iomanip>
#include <cmath>
#include <ctime>
using namespace std;
#define ll long long
#define up(i,j,n) for(int i=j;i<=n;i++)
#define down(i,j,n) for(int i=j;i>=n;i--)
#define FILE "tower"
;
const int oo=0x3f3f3f3f;
inline int read(){
,f=;
;ch=getchar();}
+ch-';ch=getchar();}
return x*f;
}
,head,tail;
struct Query{
int x,y,id,ans;
}q[MAXN];
namespace solution{//vio makes different
inline bool cmp(Query x,Query y){return btBlock[x.y]==btBlock[y.y]?x.x<y.x:btBlock[x.y]<btBlock[y.y];}
inline bool re_cmp(Query x,Query y){return x.id<y.id;}
void init(){
N=read();M=read();
up(i,,N)a[i]=read();
up(i,,M){
int x=read(),y=read();
if(y<x)swap(x,y);
q[i].x=x;q[i].y=y;q[i].id=i;
}
tmp=sqrt(1.0*N);
up(i,,N)btBlock[i]=(i/tmp)+;
sort(q+,q+M+,cmp);
}
void push(int id,int tag){
Count[a[id]]+=tag;
&&Count[a[id]]==)ans++;
&&Count[a[id]]==)ans--;
}
void MosAlg(){
memset(Count,,sizeof(Count));
head=;tail=;
up(k,,M){
int x=q[k].x,y=q[k].y;
);
);
);
);
q[k].ans=ans;
}
}
void output(){
sort(q+,q+M+,re_cmp);
up(i,,M)printf("%d\n",q[i].ans);
//cout<<"Time has passed"<<1.0*clock()/1000<<"s!"<<endl;
}
}
int main(){
//freopen("input.in","r",stdin);
//freopen("out1.out","w",stdout);
freopen(FILE".in","r",stdin);
freopen(FILE".out","w",stdout);
using namespace solution;
init();
MosAlg();
output();
;
}
T1
然后考完试后有人给我说把所有可能的询问存下来就行了= =....我还能说些什么
然后就去看喜闻乐见的T3了。
一眼贪心,然后就很快速的想到了$O(NM)$的算法。这个$N$后的$M$是可优化的,其本质就是查找一个动态集合里$num$的后继,这不就是treap吗?
但是思考具体实现好像出了些问题,因为我的贪心排序是递增排序(实际上应该是递减排序,递减排序的话也就没有了下面所说的麻烦),而递增排序的话每次访问过的节点必定是$id$以后的节点,这就很不优雅了,我需要维护一个$node$和$v$的关系。
然后$v$还可以重复...
exm?
思考了半天怎么防止区间重复的删除,到了11:20,弃疗,敲暴力。
然后暴力就敲崩了。
这个是最后改好的:
//OJ 1939
//by Cydiater
//2016.9.10
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <queue>
#include <map>
#include <ctime>
#include <cmath>
#include <string>
#include <iomanip>
using namespace std;
#define ll long long
#define up(i,j,n) for(int i=j;i<=n;i++)
#define down(i,j,n) for(int i=j;i>=n;i--)
;
const ll oo=0x3f3f3f3f;
inline ll read(){
,f=;
;ch=getchar();}
+ch-';ch=getchar();}
return x*f;
}
,tol=,tmp;
ll ans=;
struct _data{
int x,y;
}a[MAXN],b[MAXN];
struct tree{
int leftt,rightt,v,siz,cnt,rnd;
}t[MAXN];
namespace solution{
inline bool cmpfory(_data x,_data y){return x.y>y.y;}
inline void updata(int k){t[k].siz=t[t[k].leftt].siz+t[t[k].rightt].siz+t[k].cnt;}
void init(){
N=read();M=read();
up(i,,N){
a[i].x=read();a[i].y=read();
}
up(i,,M){
b[i].x=read();b[i].y=read();
}
sort(a+,a+N+,cmpfory);
sort(b+,b+M+,cmpfory);
}
void lefturn(int &k){
int tt=t[k].rightt;t[k].rightt=t[tt].leftt;t[tt].leftt=k;
t[tt].siz=t[k].siz;updata(k);k=tt;
}
void righturn(int &k){
int tt=t[k].leftt;t[k].leftt=t[tt].rightt;t[tt].rightt=k;
t[tt].siz=t[k].siz;updata(k);k=tt;
}
void insert(int &k,int v){
){
k=++tol;t[k].leftt=t[k].rightt=;
t[k].rnd=rand();t[k].v=v;t[k].siz=t[k].cnt=;
return;
}
t[k].siz++;
if(t[k].v==v){
t[k].cnt++;
return;
}
if(v<t[k].v){
insert(t[k].leftt,v);
if(t[k].rnd>t[t[k].leftt].rnd)righturn(k);
}else if(v>t[k].v){
insert(t[k].rightt,v);
if(t[k].rnd>t[t[k].rightt].rnd)lefturn(k);
}
}
void nxt(int k,int v){
)return;
if(t[k].v>=v){
tmp=t[k].v;
nxt(t[k].leftt,v);
}else nxt(t[k].rightt,v);
}
void del(int &k,int v){
)return;
if(v==t[k].v){
){
t[k].cnt--;
t[k].siz--;
return;
}
){
k=t[k].leftt+t[k].rightt;
return;
}
if(t[t[k].leftt].rnd<t[t[k].rightt].rnd){
righturn(k);
del(k,v);
}else{
lefturn(k);
del(k,v);
}
}
else if(v<t[k].v){
t[k].siz--;
del(t[k].leftt,v);
}else{
t[k].siz--;
del(t[k].rightt,v);
}
}
void slove(){
;
up(i,,N){
while(b[j].y>=a[i].y&&j<=M)
insert(root,b[j++].x);
tmp=-;
nxt(root,a[i].x);ans+=tmp;
){
puts("-1");
exit();
}
del(root,tmp);
}
}
void output(){
cout<<ans<<endl;
}
}
int main(){
//freopen("input.in","r",stdin);
using namespace solution;
init();
slove();
output();
;
}
T3
最后$100+100+0$滚粗。
小结:
还是应该提高自己的姿势水平,贪心这种东西太玄了。而且比赛也要多打,思路要放宽。对我们来说NOIp比的实际上已经是谁能AK了。
NOIp 0910 爆零记的更多相关文章
- NOIp 0916 爆零记
题目来自神犇chad 上次爆零是说着玩,这次真的爆零了QAQ 好吧貌似是TYVJ的模拟赛打多了..一直按照TYVJ的格式提交的压缩包.. 然后莫名其妙就AK了hhh 来的时候迟到了半小时,昨晚痛苦的补 ...
- 「游记」NOIP 2021 爆零记
推荐访问本人自建博客 \(\text{cjwen.top}\) 欧拉欧拉欧拉欧拉欧拉欧拉欧拉欧拉,第一次参加 \(NOIP\),欧拉欧拉欧拉欧拉欧拉欧拉欧拉欧拉. 第一题比较简单,用类似于筛质数的做法 ...
- Codeforces Round #423 (Div. 2, rated, based on VK Cup Finals)爆零记
昨晚一个瓜皮说今晚有cf,听说是晚间场,我瞅了一眼,娃,VK Cup,上分的好机会,看着比赛时间就有点心酸了,0:35,当时一直在纠结要不要打的问题,当时想着应该不难吧,要不打一下吧,要不还是看看题先 ...
- HNOI2019 爆零记
HNOI2019爆零记 day \(-inf\) ~ day \(0\) 开学一周之后才停的课,停课之后就开始每天被包菜.我三月份几乎没有更博,就是因为每天都被虐的自闭了. day \(0\) 本来是 ...
- PKUWC 2019&WC 2019爆零记
PKUWC 2019&WC 2019爆零记 毕竟过了很久了,杂七杂八的东西就不写了,并且除成绩之外的内容不保证其正确性. Day1 T1:看到这道题很舒服啊,枚举top序算合法图的数量,状压D ...
- 雅礼集训1-9day爆零记
雅礼集训1-9day爆零记 先膜一下虐爆我的JEFF巨佬 Day0 我也不知道我要去干嘛,就不想搞文化科 (文化太辣鸡了.jpg) 听李总说可以去看(羡慕)各路大佬谈笑风声,我就报一个名吧,没想到还真 ...
- CTS&&APIO2019爆零记
如果你只好奇测试相关请跳至day 2 day 3 day 6 scoi 2019 之后 由于实力问题,省选的时候排名在三十多,显然是没有进队.不过可能是受过的打击比较多,所以还没有特别颓废,甚至连 ...
- [日常] NOIWC 2018爆零记
开个坑慢慢更(逃 (然而没准会坑掉?) day 0 大概 $8:30$ 就滚去雅礼了qwq 过去的时候发现并没有人...进报到处楼门的时候还被强行拍照围观了一波OwO 然后就领了HZ所有人的提包和狗牌 ...
- HNOI2019爆零记
HNOI2019真-爆零祭 我怎么这么菜QAQ day-37 从学科溜过来搞OI. 班主任一直在谈论我退役的事情,这就是NOIP挂分的后果...说我没考好就找理由,人家xxxxxxx可不是xxxxxx ...
随机推荐
- ASP.NET MVC3入门教程之ajax交互
本文转载自:http://www.youarebug.com/forum.php?mod=viewthread&tid=100&extra=page%3D1 随着web技术的不断发展与 ...
- ASP.NET MVC3入门教程之第一个WEB应用程序
本文转载自:http://www.youarebug.com/forum.php?mod=viewthread&tid=91&extra=page%3D1 上一节,我们已经搭建好了AS ...
- 20151120 - 蓝牙鼠标与 WiFi 冲突的解决办法
问题现象描述:Windows 下蓝牙鼠标移动时不连贯 电脑:Dell 2015 版 NEW XPS 15 鼠标:Microsoft Bluetooth Designer Mouse 操作系统:Wind ...
- XSS attack
<html> <form action="" method="post"> <input type="text" ...
- java.awt.Robot
import java.awt.AWTException; import java.awt.Robot; import java.awt.event.KeyEvent; public class Te ...
- Eclipse添加代码注释模板
Eclipse支持我们自定义模板,比如文件的注释,类注释,函数注释等功能.eclipse自身有自带的模板,我们也可以自己定义.一次点击:windows->preference—>java- ...
- github page 和 hexo 搭建在线博客
目录: 安装node.js与git 常用git命令 安装hexo 配置hexo hexo发布到github 1.安装node.js和git工具 https://nodejs.org/en/ 直接下载安 ...
- git介绍
简介:Git是一个开源的分布式版本控制系统,用于敏捷高效地处理任何或小或大的项目.Git 是 Linus Torvalds 为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件.Git ...
- asp.net mvc输出自定义404等错误页面,非302跳转。
朋友问到一个问题,如何输出自定义错误页面,不使用302跳转.当前页面地址不能改变. 还要执行一些代码等,生成一些错误信息,方便用户提交反馈. 500错误,mvc框架已经有现成解决方法: filters ...
- C#-WinForm-布局-Anchor-锁定布局、Dock-填充布局、工具箱中的<容器>
Anchor - 锁定布局,锁定控件对于其父控件或窗体的位置,保持与边框固定的距离还是居中等 Dock - 填充布局,控件是否如何进行填充 ============================== ...