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)的更多相关文章

  1. Codeforces #180 div2 C Parity Game

    // Codeforces #180 div2 C Parity Game // // 这个问题的意思被摄物体没有解释 // // 这个主题是如此的狠一点(对我来说,),不多说了这 // // 解决问 ...

  2. Codeforces #541 (Div2) - E. String Multiplication(动态规划)

    Problem   Codeforces #541 (Div2) - E. String Multiplication Time Limit: 2000 mSec Problem Descriptio ...

  3. Codeforces #541 (Div2) - F. Asya And Kittens(并查集+链表)

    Problem   Codeforces #541 (Div2) - F. Asya And Kittens Time Limit: 2000 mSec Problem Description Inp ...

  4. Codeforces #541 (Div2) - D. Gourmet choice(拓扑排序+并查集)

    Problem   Codeforces #541 (Div2) - D. Gourmet choice Time Limit: 2000 mSec Problem Description Input ...

  5. Codeforces #548 (Div2) - D.Steps to One(概率dp+数论)

    Problem   Codeforces #548 (Div2) - D.Steps to One Time Limit: 2000 mSec Problem Description Input Th ...

  6. 【Codeforces #312 div2 A】Lala Land and Apple Trees

    # [Codeforces #312 div2 A]Lala Land and Apple Trees 首先,此题的大意是在一条坐标轴上,有\(n\)个点,每个点的权值为\(a_{i}\),第一次从原 ...

  7. Codeforces 1136 - A/B/C/D/E - (Done)

    链接:https://codeforces.com/contest/1136/ A - Nastya Is Reading a Book - [二分] #include<bits/stdc++. ...

  8. Codeforces #263 div2 解题报告

    比赛链接:http://codeforces.com/contest/462 这次比赛的时候,刚刚注冊的时候非常想好好的做一下,可是网上喝了个小酒之后.也就迷迷糊糊地看了题目,做了几题.一觉醒来发现r ...

  9. codeforces #round363 div2.C-Vacations (DP)

    题目链接:http://codeforces.com/contest/699/problem/C dp[i][j]表示第i天做事情j所得到最小的假期,j=0,1,2. #include<bits ...

  10. codeforces round367 div2.C (DP)

    题目链接:http://codeforces.com/contest/706/problem/C #include<bits/stdc++.h> using namespace std; ...

随机推荐

  1. 超级有爱的五款APP共享 可以让你神操作

    随着科技的不断发展,手机功能的不断完善,让我们更加依赖手机,不得不说手机给我们带来很多的乐趣和方便. 今天就主要给大家分享五款超级有爱的APP软件,感兴趣的小伙伴已经迫不及待了吧! 荔枝 荔枝是一款声 ...

  2. Android 离线人脸识别 ArcFace 2.0 Demo开发分享

    环境要求     1.运行环境 armeabi-v7a     2.系统要求 Android 5.0 (API Level 21)及以上     3.开发环境 Android Studio   下载地 ...

  3. .Net Core3 新特性/新功能 16条

    .net core 3实现了.net 标准2.1. 1.生成可执行文件 以前版本需要dotnet run运行项目,.net core 3支持直接生成目标平台的可执行文件.比如windows就是exe了 ...

  4. 【Linux】【MySQL】CentOS7安装最新版MySQL8.0.13(最新版MySQL从安装到运行)

    1.前言 框框博客在线报时:2018-11-07 19:31:06 当前MySQL最新版本:8.0.13 (听说比5.7快2倍) 官方之前表示:MySQL 8.0 正式版 8.0.11 已发布,MyS ...

  5. C语言面试基础知识整理

    一.预处理 1.什么是预编译?何时需要预编译? (1)预编译又称预处理,是做些代码文本的替换工作,即程序执行前的一些预处理工作.主要处理#开头的指令,如拷贝#include包含的文件代码.替换#def ...

  6. 如何自己制作CHM电子书?

    软件介绍: EasyCHM 非常适合个人和单位制作高压缩比的有目录.索引,同时具有全文检索及高亮显示搜索结果的网页集锦.CHM格式的帮助文件.专业的产品说明书.公司介绍.文章集锦.CHM电子书等等. ...

  7. 订制rpm包到Centos7镜像中

    本文以CentOS 7.4 最小化镜像(CentOS-7-x86_64-Minimal-1708.iso)为模版 要达到的目的: 1.订制所需的rpm软件包集成到iso文件中 2.制作完成的ISO全自 ...

  8. PHP 函数漏洞总结

    1.MD5 compare漏洞 PHP在处理哈希字符串时,会利用"!="或"=="来对哈希值进行比较,它把每一个以"0E"开头的哈希值都解释 ...

  9. Python基础之字典

    字典初识 字典的认识 首先,我们来认识一下字典: # 定义一个字典 user_dict = {"name": "zhangsan", "age&quo ...

  10. Loj #3096. 「SNOI2019」数论

    Loj #3096. 「SNOI2019」数论 题目描述 给出正整数 \(P, Q, T\),大小为 \(n\) 的整数集 \(A\) 和大小为 \(m\) 的整数集 \(B\),请你求出: \[ \ ...