目大意:有$n(n\leqslant10^6)$个数,$5$种操作:

  1. $D\;x:$从数列中删除$x$,相同的数只删除一个
  2. $B:$最大值
  3. $S:$最小值
  4. $M:$输出$max^{min}\pmod{317847191}$
  5. $T:$输出乘积模$317847191$

题解:堆,没有插入,可以离线倒着搞,把删除变成插入即可

题解:卡$map$

 

C++ Code:

#include <cstdio>
#include <algorithm>
#include <map>
#include <vector>
#include <queue>
#include <cctype>
namespace R {
int x, ch;
inline int read() {
ch = getchar();
while (isspace(ch)) ch = getchar();
for (x = ch & 15, ch = getchar(); isdigit(ch); ch = getchar()) x = x * 10 + (ch & 15);
return x;
}
}
using R::read; #define maxn 1000010
const int mod = 317847191;
inline int pw(int base, int p) {
int res = 1;
for (; p; p >>= 1, base = static_cast<long long> (base) * base % mod) if (p & 1) res = static_cast<long long> (res) * base % mod;
return res;
} int n, m;
long long prod = 1;
int s[maxn], c[maxn];
int ans[maxn];
int ret[maxn], num[maxn], cnt[maxn];
char op[maxn]; std::priority_queue<int> Max;
std::priority_queue<int, std::vector<int>, std::greater<int> > Min; int main() {
n = read(), m = read();
for (int i = 1; i <= n; i++) s[i] = read();
std::sort(s + 1, s + n + 1);
for (int i = 1, x; i <= n; i++) {
if (s[i] != s[i - 1]) x = i;
else x = num[i - 1];
num[i] = x;
ret[x] = s[i];
}
for (int i = 1; i <= m; i++) {
scanf("%1s", op + i);
if (op[i] == 'D') c[i] = read(), cnt[std::lower_bound(s + 1, s + n + 1, c[i]) - s]++;
}
for (int i = 1; i <= n; i++) if (!cnt[num[i]]) {
Max.push(s[i]);
Min.push(s[i]);
prod = prod * s[i] % mod;
} else cnt[num[i]]--;
for (int i = m; i; i--) {
switch (op[i]) {
case 'D': {
Max.push(c[i]);
Min.push(c[i]);
prod = prod * c[i] % mod;
break;
}
case 'B': ans[i] = Max.top(); break;
case 'S': ans[i] = Min.top(); break;
case 'M': ans[i] = pw(Max.top(), Min.top()); break;
case 'T': ans[i] = prod;
}
}
for (int i = 1; i <= m; i++) if (op[i] != 'D') printf("%d\n", ans[i]);
return 0;
}

  

[洛谷P2174]小Z的神奇数列的更多相关文章

  1. 洛谷 2186 小Z的栈函数

    https://www.luogu.org/problem/show?pid=2186 题目描述 小Z最近发现了一个神奇的机器,这个机器的所有操作都是通过维护一个栈来完成的,它支持如下11个操作: N ...

  2. Bzoj2038/洛谷P1494 小Z的袜子(莫队)

    题面 Bzoj 洛谷 题解 考虑莫队算法,首先对询问进行分块(分块大小为\(sqrt(n)\)),对于同一个块内的询问,按照左端点为第一关键字,右端点为第二关键字排序.我们统计这个区间内相同的颜色有多 ...

  3. 洛谷——P2117 小Z的矩阵

    P2117 小Z的矩阵 题目描述 小Z最近迷上了矩阵,他定义了一个对于一种特殊矩阵的特征函数G.对于N*N的矩阵A,A的所有元素均为0或1,则G(A)等于所有A[i][j]*A[j][i]的和对2取余 ...

  4. 洛谷P2188 小Z的 k 紧凑数

    P2188 小Z的 k 紧凑数 题目描述 小 Z 在草稿纸上列出了很多数,他觉得相邻两位数字差的绝对值不超过 k 的整数特别奇特,称其为 k 紧凑数. 现在小 Z 想知道 [l,r] 内有多少个 k ...

  5. 洛谷—— P2117 小Z的矩阵

    https://www.luogu.org/problemnew/show/2117 题目描述 小Z最近迷上了矩阵,他定义了一个对于一种特殊矩阵的特征函数G.对于N*N的矩阵A,A的所有元素均为0或1 ...

  6. 洛谷 P2117 小Z的矩阵

    P2117 小Z的矩阵 题目描述 小Z最近迷上了矩阵,他定义了一个对于一种特殊矩阵的特征函数G.对于N*N的矩阵A,A的所有元素均为0或1,则G(A)等于所有A[i][j]*A[j][i]的和对2取余 ...

  7. [洛谷P2186] 小Z的栈函数

    题目链接: 传送门 题目分析: 大模拟,先得存操作,然后再处理每个数-- 有一个小优化,在处理操作的时候顺便判一下最后栈里是不是有且仅有一个数,但A完了才想起来,所以就算了-- 总之就是个模拟题--没 ...

  8. 洛谷 2187 小Z的笔记

    [题解] DP.  设f[i]表示前i个字母,保留第i个字母,最多可以保留多少个字母:设g[i]为当前字母为i的位置对应的f的最大值. 转移方程就是f[i]=max(f[i], g[j]+1) (j与 ...

  9. [洛谷P2107] 小Z的AK计划

    题目类型:贪心,堆 传送门:>Here< 题意:给出\(N\)个房间,每个房间距离起点的距离为\(x[i]\),每个房间可以选择进去和不进去,如果进去了那么要\(t[i]\)秒后才能出来. ...

随机推荐

  1. ethereum Pet Shop

    在部署宠物商店时遇到的一些坑,给大家总结一下,以免大家多走弯路 转载的地址(详细):https://steemit.com/cn/@lucia3/ethereum-pet-shop 启动"n ...

  2. phpspider 的简单使用

    phpspider 的简单使用 phpspider是一款PHP开发蜘蛛爬虫框架. 官方github下载地址:https://github.com/owner888/phpspider官方文档下载地址: ...

  3. js 节点

    var chils= s.childNodes; //得到s的全部子节点 var par=s.parentNode;  //得到s的父节点 var ns=s.nextSbiling;  //获得s的下 ...

  4. video.js使用技巧

    https://www.awaimai.com/2053.html https://www.jianshu.com/p/16fa00a1ca8e

  5. JavaSE 第二次学习随笔(四)

    ---------------------------------------------------------------------------------------------------- ...

  6. Leecode刷题之旅-C语言/python-66加一

    /* * @lc app=leetcode.cn id=66 lang=c * * [66] 加一 * * https://leetcode-cn.com/problems/plus-one/desc ...

  7. Lucene如何实现多条件搜索?

    有两种方式可以实现, 一是:Lucene搜索API中提供了一个布尔查询器(BooleanQuery),它可以包含多个查询器,每个查询器Occur枚举控制是“and” 还是“or” BooleanQue ...

  8. javac、jar使用实录

    因项目管理部署需要,记录一下过程,以免下次忘记了,再次使用又需要重头再来,只记录正确的操作方式,可能会提到某些错误 建立项目所在目录F:\www 案例一 其下建立项目的java源文件的包目录结构.ja ...

  9. jar命令:打包、查看、更新等

    如何把写好的Java程序打包为jar文件呢?下面说的就是java使用命令行打包JAR的方法 1.命令行的方式:打包jar cf JAR文件名称 程序文件名称或者程序所在的文件夹举例:jar cf My ...

  10. C++怎么用二维数组作为形参传入

    原文地址:http://blog.csdn.net/xuleicsu/article/details/919801 如何将二维数组作为函数的参数传递 今天写程序的时候要用到二维数组作参数传给一个函数, ...