因为shift操作中的数不多,所以直接用单点更新模拟一下就好了。

太久不写线段树,手好生啊,不是这错一下就是那错一下。

PS:输入写的我有点蛋疼,不知道谁有没有更好的写法。

 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
using namespace std; const int maxn = + ;
const int maxnode = (maxn << );
const int INF = 0x3f3f3f3f; void scan(int& x)
{
x = ;
char c = ' ';
while(c < '' || c > '') c = getchar();
while(c >= '' && c <= '') { x = x * + c - ''; c = getchar(); }
} int qL, qR;
int p, v;
int n, Q;
int minv[maxnode]; int a[maxn]; void build(int o, int L, int R)
{
if(L == R) { scan(a[L]); minv[o] = a[L]; return ; }
int M = (L + R) / ;
build(o<<, L, M);
build(o<<|, M+, R);
minv[o] = min(minv[o<<], minv[o<<|]);
} void update(int o, int L, int R)
{
//if(v >= minv[o]) return ;
if(L == R) { minv[o] = v; return ; } int M = (L + R) / ;
if(p <= M) update(o<<, L, M);
else update(o<<|, M+, R);
minv[o] = min(minv[o<<], minv[o<<|]);
} int query(int o, int L, int R)
{
if(qL <= L && R <= qR) return minv[o];
int ans = INF;
int M = (L + R) / ;
if(qL <= M) ans = min(ans, query(o<<, L, M));
if(qR > M) ans = min(ans, query(o<<|, M+, R));
return ans;
} char op[]; int main()
{
while(scanf("%d%d", &n, &Q) == && n)
{
build(, , n);
while(Q--)
{
scanf("%s", op);
int l = strlen(op);
if(op[] == 'q')
{
int i = ;
qL = ;
while(i < l && op[i] >= '' && op[i] <= '') { qL = qL * + op[i] - ''; i++; }
while(i < l && (op[i] < '' || op[i] > '')) i++;
qR = ;
while(i < l && op[i] >= '' && op[i] <= '') { qR = qR * + op[i] - ''; i++; }
printf("%d\n", query(, , n));
}
else
{
vector<int> hehe; for(int i = ; i < l;)
{
while(i < l && (op[i] < '' || op[i] > '')) i++;
if(i >= l) break;
int x = ;
while(i < l && op[i] >= '' && op[i] <= '') { x = x * + op[i] - ''; i++; }
hehe.push_back(x);
} int sz = hehe.size();
for(int i = ; i < sz - ; i++)
{
v = a[hehe[i + ]];
p = hehe[i];
update(, , n);
}
v = a[hehe[]];
p = hehe[sz - ];
update(, , n); int t = a[hehe[]];
for(int i = ; i < sz - ; i++) a[hehe[i]] = a[hehe[i+]];
a[hehe[sz - ]] = t;
}
}
} return ;
}

代码君

最新文章

  1. Nginx设置线程数为整机内核数的俩倍!
  2. JS组件系列——开源免费图表组件:Chart.js
  3. iptables四个表与五个链间的处理关系
  4. git常见命令
  5. mssql 用户只能查看授权的数据库
  6. R语言基因组数据分析可能会用到的data.table函数整理
  7. Hive metastore源码阅读(三)
  8. 使用Apache JMeter对SQL Server、Mysql、Oracle压力测试(四)
  9. SQL kaggle learn : WHERE AND
  10. spark-yarn
  11. Examples of GoF Design Patterns in Java&#39;s core libraries
  12. redis,nodejs,php,pub/sub 实战: 微信语音识别
  13. python中list的sort方法
  14. hdoj 4445 Crazy Tank 物理题/枚举角度1
  15. 基于python复制蓝鲸作业平台
  16. echarts中跨域动态获取数据时,当某些对应的数据为空时,鼠标滑动到所在位置卡死
  17. thinkphp 如何调用百度echarts 数据报表插件
  18. 03-24 Winform图表Chart
  19. modalTransitionStyle各种present效果
  20. [LOJ #6433]「PKUSC2018」最大前缀和

热门文章

  1. javascript 关于hashtable
  2. 洛谷P1081 开车旅行70分
  3. springboot 学习笔记(三)
  4. 常用API(正则表达式、Date、DateFormat、Calendar)
  5. mongodb的创建删除数据库
  6. 如何移除网站Response Headers中的X-Powered-By信息?
  7. 安装vs2013提示必须安装ie10的解决办法
  8. css3的过渡、动画、2D、3D效果
  9. redis自启动配置详解
  10. windows7桌面小工具打不开的解决方案