关于flag,都立下了

T1

考试的时候就觉得是贪心,但是不会反悔emm……

于是正解就是一个堆优化可反悔的贪心=。=

每次找前面最小的,于是是小根堆。

我们在交易的时候发现后面的一个可以更优。

于是可以发现$x_i-x_j+x_j-x_k=x_i-x_k$

这样就可以反悔,如果发现$k$可以更优,就把$j$退回去,

所以每次决策完,直接压堆或是更新,并把两个数一起放进去。

一个用来退货,另一个用来再买。

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
#define N 111111
#define LL long long using namespace std; priority_queue<int,vector<int>,greater<int> >q;
LL pn,arr[N],ans=0;
int main(){
scanf("%lld",&pn);
for(int i=1;i<=pn;i++)
scanf("%lld",arr+i);
for(int i=1;i<=pn;i++){
if(q.empty())q.push(arr[i]);
else if(q.top()<arr[i]){
ans+=arr[i]-q.top();
q.pop();
for(int j=0;j<2;j++)
q.push(arr[i]);
}
else q.push(arr[i]);
}
printf("%lld\n",ans);
}

T2

一个数学题,但是转换成莫队了。

打个样辉三角就可以知道这两个柿子。

$$\begin{align}
S_{n,m}=S_{n,m-1}+C_n^m \tag 1\\
S_{n,m}=S_{n-1,m} \times 2 - C_{n-1}^m \tag 2
\end{align}$$

我没写错吧

于是化为序列询问。

从$[m,n]$向$[m+1,n],[m-1,n],[m,n+1],[m,n-1]$移动。

#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#define N 111111
#define LL long long using namespace std; const int Mod=1e9+7;
struct Query{
int n,m;
int id;
}qs[N];
int qn;
LL ans[N],fac[N],inv[N];
int inp[N],pl; inline int get_part(int id){
return (id-1)/pl+1;
}
LL ppow(LL a,LL b){
LL res(1);
while(b){
if(b&1)res=res*a%Mod;
a=a*a%Mod;
b>>=1;
}
return res;
}
void prerun(){
pl=sqrt(100000)+1;
for(int i=0;i<=100000;i++)
inp[i]=get_part(i);
fac[0]=inv[0]=1;
for(int i=1;i<=100000;i++){
fac[i]=fac[i-1]*i%Mod;
inv[i]=ppow(fac[i],Mod-2);
}
}
LL C(int n,int m){
return fac[n]*inv[m]%Mod*inv[n-m]%Mod;
}
int main(){
// freopen("1.in","r",stdin);
// freopen("wa.out","w",stdout);
prerun();
scanf("%*d%d",&qn);
for(int i=1;i<=qn;i++){
scanf("%d%d",&qs[i].n,&qs[i].m);
qs[i].id=i;
}
sort(qs+1,qs+qn+1,[](const Query &x,const Query &y){return inp[x.n]<inp[y.n]||(inp[x.n]==inp[y.n]&&(inp[x.n]&1?x.m<y.m:x.m>y.m));});
int nn=1,nm=1;//S(0,0)
LL nans=2;
for(int i=1;i<=qn;i++){
while(nn<qs[i].n){
nans=(nans*2%Mod-C(nn,nm)+Mod)%Mod;
nn++;
}
while(nn>qs[i].n){
nans=(nans+C(nn-1,nm))%Mod*inv[2]%Mod;
nn--;
}
while(nm<qs[i].m){
nans+=C(nn,nm+1);
nans%=Mod;
nm++;
}
while(nm>qs[i].m){
nans-=C(nn,nm);
nans=(nans+Mod)%Mod;
nm--;
}
ans[qs[i].id]=nans%Mod;
}
for(int i=1;i<=qn;i++)
printf("%lld\n",ans[i]);
}

T3

考试的时候一直没看见边长至少有一个是$1$……

于是按$x,y$分别排序并建边,具体实现……没打完。

我想的是用两个$set$维护。

有人要部分代码么……啥都没有

/*CECECECECECECECE*/
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <set>
#define N 111111 using namespace std;
struct XBLOCK{
int lx,ly,rx,ry;
int id;
XBLOCK(int a,int b,int c,int d,int e):lx(a),ly(b),rx(c),ry(d),id(e){}
friend operator < (const XBLOCK &a,const XBLOCK &b){
if(a.lx==b.lx)
return a.ly<b.ly;
return a.lx<b.lx;
}
};
struct YBLOCK{
int lx,ly,rx,ry;
int id;
YBLOCK(int a,int b,int c,int d,int e):lx(a),ly(b),rx(c),ry(d),id(e){}
friend operator < (const YBLOCK &a,const YBLOCK &b){
if(a.ly==b.ly)
return a.lx<b.lx;
return a.ly<b.ly;
}
};
set<XBLOCK>xb;
set<YBLOCK>yb;
int lines,cols,bn,qn;
int ans[N];
int pre[N];
int fa[N];
void prerun(){
for(int i=1;i<=bn;i++)
fa[i]=i;
}
int faind(int x){
if(x!=fa[x])fa[x]=faind(fa[x]);
return fa[x];
}
void unite(int a,int b){
a=faind(a);
b=faind(b);
fa[a]=b;
}
int main(){
int lx,ly,rx,ry,opt,qd;
scanf("%*d%d%d%d%d",&lines,&cols,&bn,&qn);
prerun();
for(int i=1;i<=bn;i++){
scanf("%d%d%d%d",&lx,&ly,&rx,&ry);
pre[lx-1]-=ry-ly+1;
pre[ly]+=ry-ly+1;
xb.insert(XBLOCK(lx,ly,rx,ry,i));
yb.insert(YBLOCK(lx,ly,rx,ry,i));
}
for(int i=1;i<=lines;i++)
pre[i]+=pre[i-1];
for(int i=1;i<=lines;i++)
pre[i]+=pre[i-1];
for(auto i:xb){
if(i.lx==1){
auto f=yb.lower_bound(i.lx,i.ly-1,-1,-1),
t=yb.lower_bound(i.rx+1,i.ly-1,-1,-1);
for(auto i=f;i!=t;i++){
i->id
}
continue;
}
auto xf=xb.lower_bound(XBLOCK(i.lx-1,i.ly,-1,-1)),
xt=xb.lower_bound(XBLOCK(i.lx-1,i.ry+1,-1,-1));
for(auto i=f;i!=t;i++){ }
auto yf=yb.lower_bound(YBLOCK()),
yt=yb.lower_bound(YBLOCK());
for(auto i=f;i!=t;i++){ }
}
for(int i=1;i<=qn;i++){
scanf("%d%d",&opt,&qd);
if(opt)
printf("%d\n",ans[qd]);
else
printf("%d\n",pre[qd]);
}
return 0;
}

1008-Redo的更多相关文章

  1. MySQL,MariaDB:Undo | Redo [转]

    本文是介绍MySQL数据库InnoDB存储引擎重做日志漫游 00 – Undo LogUndo Log 是为了实现事务的原子性,在MySQL数据库InnoDB存储引擎中,还用Undo Log来实现多版 ...

  2. iOS: 为画板App增加 Undo/Redo(撤销/重做)操作

    这个随笔的内容以上一个随笔为基础,(在iOS中实现一个简单的画板),上一个随笔实现了一个简单的画板:   今天我们要为这个画板增加Undo/Redo操作,当画错了一笔,可以撤销它,或者撤销之后后悔了, ...

  3. 【msql】关于redo 和 undo log

    InnoDB 有两块非常重要的日志,一个是undo log,另外一个是redo log,前者用来保证事务的原子性以及InnoDB的MVCC,后者用来保证事务的持久性.和大多数关系型数据库一样,Inno ...

  4. HDOJ 1008. Elevator 简单模拟水题

    Elevator Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  5. [转]undo log与redo log原理分析

    数据库通常借助日志来实现事务,常见的有undo log.redo log,undo/redo log都能保证事务特性,这里主要是原子性和持久性,即事务相关的操作,要么全做,要么不做,并且修改的数据能得 ...

  6. [转]MySQL日志——Undo | Redo

    本文是介绍MySQL数据库InnoDB存储引擎重做日志漫游 00 – Undo LogUndo Log 是为了实现事务的原子性,在MySQL数据库InnoDB存储引擎中,还用Undo Log来实现多版 ...

  7. 【转】ORACLE的REDO与UNDO

    一.什么是redo?redo:oracle在在线或者归档重做日志文件中的记录的信息,外以出现失败时可以利用这些数据来"重放"事务.每个oracle数据都至少有二个在线重做日志组,每 ...

  8. BULK操作减少redo实验

    建表: create table sm_histable ( sm_id ), sm_subid ), service_type ), orgton ), orgnpi ), destton ), d ...

  9. 从Undo,Redo谈命令模式

    一般的应用软件中,通常会提供Redo和Undo的操作,比如Paint.NET中的动作面板,Word中的撤销重做,一般我们按Ctrl-Z即可回退到上次操作. 要实现上面的这一功能,最直观的想法就是,我们 ...

  10. Undo/Redo for Qt Tree Model

    Undo/Redo for Qt Tree Model eryar@163.com Abstract. Qt contains a set of item view classes that use ...

随机推荐

  1. linux下phpstudy安装

    linux下phpstudy安装 一.总结 一句话总结: 就是下载然后一步步用指令安装即可 二.linux下phpstudy安装 参考:linux下phpstudy安装https://www.cnbl ...

  2. mysql用户管理和pymysql

    mysql用户管理 为了使不同的人员访问到对应身份的数据库资源,每个人都有不同的权限. mysql本质上是一款cs软件,它具备用户认证,那么如何实现呢?那就是写入文件,但是在mysql把文件称作表,只 ...

  3. CSS 属性2

    CSS背景属性   background-color:背景颜色.   background-image:背景图片地址.如:background-image:url(images/bg.gif)   b ...

  4. SpringBoot--Banner的定制和关闭

    SpringBoot项目启动的时候控制台会打印如下信息: 上面红色框框内的“SPRING BOOT”被称为Banner,意为横幅,默认会开启并在控制台打印,其实我们可以修改它的内容和样式,即定制:并选 ...

  5. 18.scrapy_maitian

    ershoufang.py # -*- coding: utf-8 -*- import scrapy class ErshoufangSpider(scrapy.Spider): name = 'e ...

  6. POJ 1269 /// 判断两条直线的位置关系

    题目大意: t个测试用例 每次给出一对直线的两点 判断直线的相对关系 平行输出NODE 重合输出LINE 相交输出POINT和交点坐标 1.直线平行 两向量叉积为0 2.求两直线ab与cd交点 设直线 ...

  7. 面试系列24 dubbo负载均衡策略和集群容错策略

    (1)dubbo负载均衡策略 1)random loadbalance 默认情况下,dubbo是random load balance随机调用实现负载均衡,可以对provider不同实例设置不同的权重 ...

  8. Nginx 教程 1:基本概念

    简介 我们会告诉你 Nginx 是如何工作的,其背后的概念有哪些,以及如何优化它以提升应用程序的性能.还会告诉你如何安装,如何启动.运行. 这个教程包括三节: 基础概念——你可以了解命令(direct ...

  9. atom的使用

    一,Atom介绍 Atom 是 Github 开源的文本编辑器,这个编辑器完全是使用Web技术构建的(基于Node-Webkit).启动速度快,提供很多常用功能的插件和主题,可以说Atom已经足以胜任 ...

  10. 位运算 - 左移右移运算符 >>, <<, >>>

    1-左移运算符m<<n,表示把m左移n位.左移n位的时候,最左边的n位数将被丢弃,同时在最右边补上n个0.例如: 00001010<<2 = 00101000 10001010 ...