4942: [Noi2017]整数


Time Limit: 50 Sec  Memory Limit: 512 MB
Submit: 363  Solved: 237
[Submit][Status][Discuss]

Description


http://www.lydsy.com/JudgeOnline/upload/Noi2017D1.pdf

Input

Output

Sample Input

Sample Output

HINT

分析:


 如果维护一个3*10^7次方的数组表示这个数,只有加法是很好办的,但是有减法的话就不好办了。所以维护两个3*10^7次方的数组,表示加法每一位是否是1减法每一位是否是1.
 查询的时候高位是不关乎当前位的事,只关心当前位的加减法和低位中最高位加减法数组不同的两个位置,加减法不同的位置可以用线段树维护。

AC代码:


# include <iostream>
# include <cstdio>
using namespace std;
const int N = << ;
const int mx = << ;
bool Inc[N],Dec[N],t[N << ];
int l,r,n;
int read()
{
int x = ,f = ;char i = getchar();
while(!isdigit(i))f = i == '-' ? - : f,i = getchar();
while(isdigit(i))x = x * + i - '',i = getchar();
return x * f;
}
void add(bool *c,int x)
{
for(;c[x];c[x++] = );
c[x] = ;
if(x > r)r = x;
}
int find(int x)
{
for(x += mx;x;x >>= )if(x & & t[x ^ ])
{
for(x ^= ;x < mx;x = x << ^ t[x << | ]);
return x - mx;
}
return -;
}
int main()
{
int tp,x,y;n = read();read();read();read();
while(n--)
{
tp = read();
if(tp & )
{
x = read();y = read();
if(!x)continue;
l = r = y;tp = x > ? : ;x = x > ? x : -x;
if(tp){for(int i = ;i < ;i++)if(x >> i & )add(Inc,y + i);}
else {for(int i = ;i < ;i++)if(x >> i & )add(Dec,y + i);}
for(int i = l;i <= r;i++)t[i + mx] = Inc[i] ^ Dec[i];
for(l = (l + mx) >> ,r = (r + mx) >> ;l;l >>= ,r >>= )
for(int i = l;i <= r;i++)t[i] = t[i << ] | t[i << | ];
}
else
{
x = read();y = find(x);
printf("%d\n",t[x + mx] ^ (~y && Inc[y] < Dec[y]) ? : );
}
}
}

最新文章

  1. Selenium+Python的环境配置
  2. java中paint方法和paintComponent方法的不同
  3. codeforces round #201 Div2 A. Difference Row
  4. 【NOIP模拟赛】正方形大阵
  5. c++迭代器(iterator)详解
  6. Using WMIC For Gathering System Info
  7. 与众不同 windows phone (3) - Application Bar(应用程序栏)
  8. vue2.0 通过v-html指令渲染的富文本无法修改样式的解决方案
  9. 【CentOS7】服务环境搭建
  10. HTML(四)
  11. hdu 2126 Buy the souvenirs 【输出方案数】【01背包】(经典)
  12. python+appium+PyCharm==自动化测试APP环境
  13. ubuntu16.04 kinetic 安装 robot-pose-publisher
  14. c++开发环境搭建
  15. android开发分辨率适配总结
  16. 浅谈WebService的调用&lt;转&gt;
  17. 积木城堡(dp)
  18. ORACLE11g 没有控制文件如何通过rman备份恢复数据的详细实战过程
  19. Codeforces 351B Jeff and Furik 概率 | DP
  20. monogdb windows环境下 安装及使用简单示例

热门文章

  1. cf 1020 C
  2. Android自动化测试如何获取坐标点?
  3. 重新造轮子之静态链接2(Static linking)
  4. 关于freetype在安装中的遇到的问题
  5. [转] Vuex入门(2)—— state,mapState,...mapState对象展开符详解
  6. 一个通用的Makefile框架
  7. ogre3d环境配置与简单程序示例
  8. 令人惊叹的Npm工具包
  9. django自定义过滤器和标签
  10. 2016湖南省赛----A 2016 (同余定理)