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. Android Studio教程04-Task和Back stack

    目录 1.Tasks and Back Stack 1.1. 当点击Back按钮返回到上一个Activity时发生了什么? 1.2. 点击HOME按钮 1.3.多次点击进入Activity-Back按 ...

  2. 大整数相乘问题总结以及Java实现

    最近在跟coursera上斯坦福大学的算法专项课,其中开篇提到了两个整数相乘的问题,其中最简单的方法就是模拟我们小学的整数乘法,可想而知这不是比较好的算法,这门课可以说非常棒,带领我们不断探索更优的算 ...

  3. Java设计模式视频讲解

    设计模式(JAVA) 视频网址: http://www.qghkt.com/ 设计模式(JAVA)视频地址: https://ke.qq.com/course/318643?tuin=a508ea62 ...

  4. Python进阶教程001内置数据类型

    关于Python的基础知识已经告一段落了,我们接下来深入的研究Python的使用方法,以及以后将要使用到的类库. 格式化字符串 Python是支持字符串的格式化输出的,在之前的学习中我们也遇到过和使用 ...

  5. activemq读取剩余消息队列中消息的数量

    先上原文链接: http://blog.csdn.net/bodybo/article/details/5647968  ActiveMQ在C#中的应用 ActiveMQ是个好东东,不必多说.Acti ...

  6. (light oj 1024) Eid (最小公倍数)

    题目链接: http://lightoj.com/volume_showproblem.php?problem=1024 In a strange planet there are n races. ...

  7. 开发中,IDEA常用的快捷键

    Settings文件: Ctrl+Alt+S 搜索文件:Ctrl+Shift+N 全文搜索: Ctrl+Shift+F 全文替换: Ctrl+Shift+R 搜索内容: Ctrl+F 内容替换: Ct ...

  8. Education CodeForces Round 63 Div.2

    A. Reverse a Substring 代码: #include <bits/stdc++.h> using namespace std; int N; string s; int ...

  9. linux系统设置cpu孤立

    介绍 针对cpu密集型的任务,消耗cpu较高,最好设置cpu亲和度,以提高任务执行效率,避免cpu进行上下文切换,浪费不必要的性能. 特定任务(进程/线程)需要独占一个cpu核心并且不想让其他任务(进 ...

  10. golang项目练习

    一.记账系统 1.该软件能够记录收入.支出,并能够打印收支明细表 2. 代码 package main import ( . "fmt" ) func menu() string{ ...