A:显然从大到小排序后贪心放在第一个能放的位置即可。并查集维护。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 300010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,a[N],b[N],id[N],fa[N<<1];
ll ans;
bool cmp(const int&x,const int&y)
{
return a[x]>a[y];
}
int find(int x){return fa[x]==x?x:fa[x]=find(fa[x]);}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),m=read();
for (int i=1;i<=n;i++) id[i]=i,a[i]=read();
sort(id+1,id+n+1,cmp);
for (int i=m+1;i<=m+n+1;i++) fa[i]=i;
for (int i=1;i<=n;i++)
{
b[id[i]]=find(max(m+1,id[i]));
ans+=1ll*a[id[i]]*(b[id[i]]-id[i]);
fa[b[id[i]]]=find(b[id[i]]+1);
}
cout<<ans<<endl;
for (int i=1;i<=n;i++) printf("%d ",b[i]);
return 0;
//NOTICE LONG LONG!!!!!
}

  B:对前后缀处理出答案,two pointers即可。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,m,k;
ll pre[N],suf[N],cost[N];
bool flag[N];
struct data
{
int t,x,y,c;
bool operator <(const data&a) const
{
return t<a.t;
}
}a[N];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),m=read(),k=read();
for (int i=1;i<=m;i++)
{
int t=read(),x=read(),y=read(),c=read();
a[i].t=t,a[i].x=x,a[i].y=y,a[i].c=c;
}
sort(a+1,a+m+1);
memset(pre,42,sizeof(pre));int cnt=0;
memset(cost,42,sizeof(cost));
memset(flag,0,sizeof(flag));
for (int i=1;i<=m;i++)
{
pre[i]=pre[i-1];
if (a[i].y==0)
{
if (!flag[a[i].x])
{
cnt++;
cost[a[i].x]=a[i].c;
flag[a[i].x]=1;
if (cnt==n)
{
pre[i]=0;
for (int j=1;j<=n;j++) pre[i]+=cost[j];
}
}
else
if (a[i].c<cost[a[i].x])
{
if (cnt==n) pre[i]-=cost[a[i].x]-a[i].c;
cost[a[i].x]=a[i].c;
}
}
}
memset(suf,42,sizeof(suf));cnt=0;
memset(cost,42,sizeof(cost));
memset(flag,0,sizeof(flag));
for (int i=m;i>=1;i--)
{
suf[i]=suf[i+1];
if (a[i].x==0)
{
if (!flag[a[i].y])
{
cnt++;flag[a[i].y]=1;
cost[a[i].y]=a[i].c;
if (cnt==n)
{
suf[i]=0;
for (int j=1;j<=n;j++) suf[i]+=cost[j];
}
}
else
if (a[i].c<cost[a[i].y])
{
if (cnt==n) suf[i]-=cost[a[i].y]-a[i].c;
cost[a[i].y]=a[i].c;
}
}
}
int x=0;ll ans=pre[0];
for (int i=1;i<=m;i++)
{
while (a[i].t-a[x+1].t>k) x++;
if (x) ans=min(ans,pre[x]+suf[i]);
}
if (ans==pre[0]) cout<<-1;
else cout<<ans;
return 0;
//NOTICE LONG LONG!!!!!
}

  C:根据查询矩形边界将平面分成九块,讨论两端点位置即可,主席树支持查询矩形内点的个数。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 200010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,q,a[N],root[N],cnt;
struct data{int l,r,x;
}tree[N<<6];
void ins(int &k,int l,int r,int x)
{
tree[++cnt]=tree[k];k=cnt;tree[k].x++;
if (l==r) return;
int mid=l+r>>1;
if (x<=mid) ins(tree[k].l,l,mid,x);
else ins(tree[k].r,mid+1,r,x);
}
int Query(int x,int y,int l,int r,int p,int q)
{
if (!y) return 0;
if (l==p&&r==q) return tree[y].x-tree[x].x;
int mid=l+r>>1;
if (q<=mid) return Query(tree[x].l,tree[y].l,l,mid,p,q);
else if (p>mid) return Query(tree[x].r,tree[y].r,mid+1,r,p,q);
else return Query(tree[x].l,tree[y].l,l,mid,p,mid)+Query(tree[x].r,tree[y].r,mid+1,r,mid+1,q);
}
int query(int l,int r,int x,int y)
{
if (l>r||x>y) return 0;
return Query(root[l-1],root[r],1,n,x,y);
}
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read(),q=read();
for (int i=1;i<=n;i++)
{
root[i]=root[i-1];
a[i]=read();
ins(root[i],1,n,a[i]);
}
for (int _=1;_<=q;_++)
{
int l=read(),d=read(),r=read(),u=read();
int x=query(l,r,d,u),f=query(l,r,1,d-1),g=query(l,r,u+1,n);
int v=query(1,l-1,d,n),w=query(1,l-1,1,u);
ll ans=0;
ans+=1ll*f*v;
ans+=1ll*g*w;
ans+=1ll*x*(l-1);
ans+=1ll*(r-l+1)*(r-l)/2;
ans-=1ll*f*(f-1)/2;
ans-=1ll*g*(g-1)/2;
ans+=1ll*query(r+1,n,1,d-1)*(x+g+v);
ans+=1ll*query(r+1,n,u+1,n)*(x+f+w);
ans+=1ll*query(r+1,n,d,u)*r;
printf("%I64d\n",ans);
}
return 0;
//NOTICE LONG LONG!!!!!
}

  D:显然每天要么不用优惠,要么就尽量用优惠。并且显然如果某天可以优惠到免费,使用优惠不会更劣。所以直接f[i][j]表示前i天剩余优惠为j时的最小代价,瞎转移即可,由上面的性质j不会超过21。

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
#define ll long long
#define N 300010
char getc(){char c=getchar();while ((c<'A'||c>'Z')&&(c<'a'||c>'z')&&(c<'0'||c>'9')) c=getchar();return c;}
int gcd(int n,int m){return m==0?n:gcd(m,n%m);}
int read()
{
int x=0,f=1;char c=getchar();
while (c<'0'||c>'9') {if (c=='-') f=-1;c=getchar();}
while (c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^48),c=getchar();
return x*f;
}
int n,a[N],f[N][32];
signed main()
{
#ifndef ONLINE_JUDGE
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
#endif
n=read();
for (int i=1;i<=n;i++) a[i]=read()/100;
memset(f,42,sizeof(f));f[0][0]=0;
for (int i=1;i<=n;i++)
{
for (int j=0;j<=30;j++)
if (j>=a[i]/10) f[i][j]=f[i-1][j-a[i]/10]+a[i];
for (int j=0;j<=30-a[i];j++)
f[i][j]=min(f[i][j],f[i-1][j+a[i]]);
for (int j=0;j<=a[i];j++) f[i][0]=min(f[i][0],f[i-1][j]+a[i]-j);
}
int ans=1000000000;
for (int i=0;i<=30;i++) ans=min(ans,f[n][i]);
cout<<100ll*ans;
return 0;
//NOTICE LONG LONG!!!!!
}

  

Codeforces Round #433 Div. 1的更多相关文章

  1. Codeforces Round #433 (Div. 2)【A、B、C、D题】

    题目链接:Codeforces Round #433 (Div. 2) codeforces 854 A. Fraction[水] 题意:已知分子与分母的和,求分子小于分母的 最大的最简分数. #in ...

  2. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)

    A. Fraction 题目链接:http://codeforces.com/contest/854/problem/A 题目意思:给出一个数n,求两个数a+b=n,且a/b不可约分,如果存在多组满足 ...

  3. codeforces 853b//Jury Meeting// Codeforces Round #433 (Div. 1)

    题意:几个人要去一个城市k天,现给出各航班的日期和花费,让这n个人能相会k天的最小花费? 用数组arr1[i]记录在第i天人到齐的最小花费.arr2[i]记录第i天之后才有人开始走的最小花费.然后取a ...

  4. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D. Jury Meeting(双指针模拟)

    D. Jury Meeting time limit per test 1 second memory limit per test 512 megabytes input standard inpu ...

  5. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D

    Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the ...

  6. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C

    Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n ...

  7. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) B

    Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartme ...

  8. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A

    Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned tha ...

  9. 【Codeforces Round #433 (Div. 1) B】Jury Meeting

    [链接]h在这里写链接 [题意] 有n个人,它们都要在某一时刻开始,全都到达0位置,然后维持最少k个时间单位,然后再全都回到原来的位置; 第i个人初始的位置是i. 且一共有m班航班. 每一班航班,要么 ...

随机推荐

  1. FineUIMvc随笔(7)扩展通知对话框(显示多个不重叠)

    声明:FineUIMvc(基础版)是免费软件,本系列文章适用于基础版. 这篇文章我们将改造 FineUIMvc 默认的通知对话框,使得同时显示多个也不会重叠.并提前出一个公共的JS文件,供大家使用. ...

  2. SQL Server-聚焦事务、隔离级别详解(二十九)

    前言 事务一直以来是我最薄弱的环节,也是我打算重新学习SQL Server的出发点,关于SQL Server中事务将分为几节来进行阐述,Always to review the basics. 事务简 ...

  3. 破解爱奇艺优酷等Vip视频

    现在网络上兴起卖低价Vip会员的,博主在这里介绍一个破解软件,不需要登录,找到视频播放页就可以观看! 软件下载地址:http://zyzpp.cn/ 1.下载软件安装后打开: 2.比如我们要看爱奇艺的 ...

  4. PayPal、支付宝诞生的故事 | 概述起源篇

    你知道第三方支付是如何由来的吗? 第三方支付概述 说起第三方支付,好像大家都知道,天天不是用支付宝和微信吗?支付宝和微信支付确实是行业内非常具有代表的第三方支付公司,但现在他们已经不完全是一家第三方支 ...

  5. NCC Meetup 2018 Shanghai 活动小结(含PPT与视频)

    NCC Meetup 2018 上海的活动于2018年6月30日在微软上海港汇办公室进行.原本计划30人规模的小型活动,结果收到了逾60人的报名,其中大部均来到现场参加了活动. 本次活动得到了微软公司 ...

  6. vue 饿了么项目笔记

    vue 饿了么项目 1.图标字体引用 链接 2.scss 二三倍图切换 1像素边框 链接 3.better-scroll 4.布局 商品主页面 <div id="app"&g ...

  7. Linux登录MySQL时出现 Can't connect to local MySQL server through socket '/tmp/mysql.sock'解决方法

    在Linux上登录MySQL时出现如下提示,如下图: 通过查找资料了解到: MySQL有两种连接方式: (1)TCP/IP (2)socket 对mysql.sock来说,其作用是程序与mysqlse ...

  8. B-Tree 和 B+Tree

    B-Tree和B+Tree 本文来自 Hubery_James 的CSDN 博客 ,全文地址请点击:原文地址-干货满满 B+树索引是B+树在数据库中的一种实现,是最常见也是数据库中使用最为频繁的一种索 ...

  9. Django model操作

    一.各种查询统计操作   def all(self) # 获取所有的数据对象 def filter(self, *args, **kwargs) # 条件查询 # 条件可以是:参数,字典,Q def ...

  10. Python之拆分目录

    成分目录的好习惯,使得代码保持整洁,为以后的代码管理提供方便. 一.概念 一般目录有以下几个: bin:程序入口,存放start文件. conf:存放固定的配置信息,比如:连接redis的配置信息.连 ...