codeforces-1136 (div2)
A.读到第i章,就有N - i + 1章还没读。
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
PII a[maxn];
int main(){
Sca(N);
for(int i = ; i <= N ; i ++){
Sca2(a[i].fi,a[i].se);
}
K = read();
for(int i = ; i <= N ; i ++){
if(a[i].fi <= K && K <= a[i].se){
Pri(N - i + );
break;
}
}
return ;
}
B.很显然,先把起始点的石头扔到一边,然后向离端点距离短的一边走,走到端点再想另一端走,途中一边取硬币,石头全扔到起始点。
推出式子显然
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
PII a[maxn];
int main(){
Sca2(N,K);
Pri( + N + * min(N - K,K - ) + max(N - K,K - ) + N - );
return ;
}
C.发现对2 * 2的矩阵操作就是把斜相邻的两个数交换,其余N * M的矩阵操作都可以通过交换两个斜对角实现,所以交换只能交换左上右下这样一个斜对角。
那么判断两个矩阵的每个斜对角是否是相同的元素即可
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int A[maxn][maxn],B[maxn][maxn];
vector<int>a[maxn * ],b[maxn * ];
int main(){
Sca2(N,M);
For(i,,N) For(j,,M) Sca(A[i][j]);
For(i,,N) For(j,,M) Sca(B[i][j]);
For(i,,N) For(j,,M){
a[i + j].pb(A[i][j]);
b[i + j].pb(B[i][j]);
}
for(int i = ; i <= N + M ; i ++){
sort(a[i].begin(),a[i].end());
sort(b[i].begin(),b[i].end());
if(a[i] != b[i]){
puts("NO");
return ;
}
}
puts("YES");
return ;
}
D.前面的u点可以和后面的v点交换称为u可以吃掉v,点i最终可以排到nastya的后面需要满足在他后面的点是自主排到nastya后面或者它可以被i吃掉。
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
int read(){int x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 3e5 + ;
const int maxm = 5e5 + ;
const int INF = 0x3f3f3f3f;
const int mod = 1e9 + ;
int N,M,K;
int a[maxn];
int pos[maxn];
int pre[maxn];
struct Edge{
int to,next;
}edge[maxm * ];
int head[maxn],tot;
void init(){
for(int i = ; i <= N ; i ++) head[i] = -;
tot = ;
}
void add(int u,int v){
edge[tot].to = v;
edge[tot].next = head[u];
head[u] = tot++;
}
int main(){
Sca2(N,M); init();
for(int i = ; i <= N ; i ++){
a[i] = read();
pos[a[i]] = i;
}
for(int i = ; i <= M ; i ++){
PII e; e.fi = read(); e.se = read();
if(pos[e.fi] < pos[e.se]){
pre[pos[e.fi]]++;
add(pos[e.se],pos[e.fi]);
}
}
int ans = ,now = ;
for(int i = N - ; i >= ; i --){
if(pre[i] == now){
ans++;
for(int j = head[i]; ~j ; j = edge[j].next) pre[edge[j].to]--;
}else{
now++;
}
}
Pri(ans);
return ;
}
D
E.对k求一个前缀和pre,对于u点,属于[u,N]之间的所有点i的最小值都会满足 a[x] >= a[u] + pre[i] - pre[u]
对于i来说,pre[i]是固定的,动态更新的是a[u] - pre[u],所以将pre[i]分离出来,线段树维护每个点的a[u] - pre[u],维护区间和以及最大最小值。
求区间和的时候就是ppre[r] - ppre[l - 1] + 线段树维护的l到r之间的和。
坑点:lazy标记不能打成0,需要设为-INF,因为a[u] - pre[u]可能是负数
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#define For(i, x, y) for(int i=x;i<=y;i++)
#define _For(i, x, y) for(int i=x;i>=y;i--)
#define Mem(f, x) memset(f,x,sizeof(f))
#define Sca(x) scanf("%d", &x)
#define Sca2(x,y) scanf("%d%d",&x,&y)
#define Sca3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define Scl(x) scanf("%lld",&x);
#define Pri(x) printf("%d\n", x)
#define Prl(x) printf("%lld\n",x);
#define CLR(u) for(int i=0;i<=N;i++)u[i].clear();
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define PII pair<int,int>
#define PIL pair<int,long long>
#define PLL pair<long long,long long>
#define pb push_back
#define fi first
#define se second
typedef vector<int> VI;
LL read(){LL x = ,f = ;char c = getchar();while (c<'' || c>''){if (c == '-') f = -;c = getchar();}
while (c >= ''&&c <= ''){x = x * + c - '';c = getchar();}return x*f;}
const double eps = 1e-;
const int maxn = 1e5 + ;
const LL INF = 1e18;
const int mod = 1e9 + ;
int N,M,K;
struct Tree{
int l,r;
LL sum,MIN,MAX,lazy;
}tree[maxn << ];
LL a[maxn],pre[maxn],ppre[maxn];
void Pushup(int t){
tree[t].sum = tree[t << ].sum + tree[t << | ].sum;
tree[t].MIN = min(tree[t << ].MIN,tree[t << | ].MIN);
tree[t].MAX = max(tree[t << ].MAX,tree[t << | ].MAX);
}
void Build(int t,int l,int r){
tree[t].l = l; tree[t].r = r;
tree[t].lazy = -INF;
if(l == r){
tree[t].MAX = tree[t].sum = tree[t].MIN = a[l] - pre[l];
return;
}
int m = l + r >> ;
Build(t << ,l,m); Build(t << | ,m + ,r);
Pushup(t);
}
void change(int t,LL p){
tree[t].lazy = max(p,tree[t].lazy);
tree[t].sum = (tree[t].r - tree[t].l + ) * p;
tree[t].MAX = tree[t].MIN = p;
}
void Pushdown(int t){
if(tree[t].lazy != -INF){
change(t << ,tree[t].lazy); change(t << | ,tree[t].lazy);
tree[t].lazy = -INF;
}
}
void update(int t,int l,int r,LL p){
if(tree[t].MIN >= p) return;
if(l <= tree[t].l && tree[t].r <= r && tree[t].MAX <= p){
change(t,p);
return;
}
Pushdown(t);
int m = (tree[t].r + tree[t].l) >> ;
if(r <= m) update(t << ,l,r,p);
else if(l > m) update(t << | ,l,r,p);
else{
update(t << ,l,m,p);
update(t << | ,m + ,r,p);
}
Pushup(t);
}
LL query(int t,int l,int r){
if(l <= tree[t].l && tree[t].r <= r) return tree[t].sum;
Pushdown(t);
int m = (tree[t].l + tree[t].r) >> ;
if(r <= m) return query(t << ,l,r);
else if(l > m) return query(t << | ,l,r);
else return query(t << ,l,m) + query(t << | ,m + ,r);
}
int main(){
Sca(N);
for(int i = ; i <= N ; i ++) a[i] = read();
for(int i = ; i <= N; i ++){
pre[i] = read() + pre[i - ];
ppre[i] = pre[i] + ppre[i - ];
}
Build(,,N);
int Q; Sca(Q);
while(Q--){
char op[]; int l,r;
scanf("%s%d%d",&op,&l,&r);
if(op[] == '+'){
LL x = query(,l,l) + r + pre[l];
update(,l,N,x - pre[l]);
}else{
Prl(query(,l,r) + ppre[r] - ppre[l - ]);
}
}
return ;
}
E
codeforces-1136 (div2)的更多相关文章
- Codeforces #180 div2 C Parity Game
// Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...
- Codeforces #541 (Div2) - E. String Multiplication(动态规划)
Problem Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...
- Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)
Problem Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...
- Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)
Problem Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...
- Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)
Problem Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...
- 【Codeforces #312 div2 A】Lala Land and Apple Trees
# [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...
- Codeforces 1136 - A/B/C/D/E - (Done)
链接:https://codeforces.com/contest/1136/ A - Nastya Is Reading a Book - [二分] #include<bits/stdc++. ...
- Codeforces #263 div2 解题报告
比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...
- codeforces #round363 div2.C-Vacations (DP)
题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...
- codeforces round367 div2.C (DP)
题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...
随机推荐
- hadoop集群的搭建
hadoop集群的搭建 1.ubuntu 14.04更换成阿里云源 刚刚开始我选择了nat模式,所有可以连通网络,但是不能ping通,我就是想安装一下mysql,因为安装手动安装mysql太麻烦了,然 ...
- Salesforce的对象关系
对象关系 Salesforce中的对象关系和一般的关系数据库不同. 在关系数据库中对象间的关系是由主键.外键等加以定义.而在Salesforce中,对象之间的关系是由自定义字段来确定. 这么做的原因是 ...
- Webpack 4教程 - 第六部分 增强开发时体验
转载请注明出处:葡萄城官网,葡萄城为开发者提供专业的开发工具.解决方案和服务,赋能开发者.原文出处:https://wanago.io/2018/08/06/webpack-4-course-part ...
- 常见的异步方式async 和 await
之前研究过c#的async和await关键字,幕后干了什么,但是不知道为什么找不到相关资料了.现在重新研究一遍,顺便记录下来,方便以后查阅. 基础知识 async 关键字标注一个方法,该方法返回值是一 ...
- TestLink-Windows安装教程
TestLink-Windows安装教程 QQ群交流:585499566 一.这篇文章的目的 以后工作中要使用Testlink来管理测试的流程,需要在本地或者Testlink服务器上练习使用,在个人本 ...
- 基于FPM制作nginx RPM包
目录 环境 配置 FPM安装 环境 系统 其它 CentOS 7.5 需提前配置好epel 配置 [root@localhost ~]# yum clean all && yum ma ...
- CynosDB技术详解——架构设计
本文由腾讯云数据库发表 前言 CynosDB是新一代分布式数据库,100%兼容MySQL和PostgreSQL,支持存储弹性扩展,一主多从共享数据,性能更是超越社区原生MySQL和PostgreSQL ...
- php微信h5支付超简单!!!
本示例应用于tp3.2版本 不懂私聊我QQ:1195989301 请备注来意! 代码链接 请点击下载 密码: ekd4 不喜欢打字望谅解.....
- RocketMQ从3.5.8升级到4.3.2版本实战记录
背景 我们在很早之前大约在2015年8月份左右我们开始使用Rocketmq作为公司消息中间件,那个时候RocketMQ还没有捐赠给Acaphe. RocketMQ版本还是3.2.6,中间升级了一次版本 ...
- Linux下安装Nginx并配置一个图片服务器
首先安装nginx安装环境 nginx是C语言开发,建议在linux上运行,本教程使用Centos6.5作为安装环境. gcc 安装nginx需要先将官网下载的源码进行编译,编译依赖gcc环境,如果没 ...