密码机

树状数组
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int x,y,c[200005];
 4 char str[20];
 5 int inline read(){
 6     int x=0,f=1;
 7     char ch=getchar();
 8     while(ch<'0'||ch>'9')
 9         ch=getchar();
10     while(ch>='0'&&ch<='9'){
11         x=x*10+ch-'0';
12         ch=getchar();
13     }
14     return x*f;
15 }
16 inline void add(int x,int y){
17     while (x<=20005){
18         c[x]^=y;
19         x+=x&-x;
20     }
21     return;
22 }
23 inline int ask(int x){
24     int sum=0;
25     while (x){
26         sum^=c[x];
27         x-=x&-x;
28     }
29     return sum;
30 }
31 int main(){
32     while (~scanf("%s",str)){
33         if (str[0]=='A'||str[0]=='R'){
34             x=read();
35             add(x,x);
36         }
37         else if (str[0]=='X'){
38             x=read();
39             y=read();
40             if (x>y)
41                 printf("0\n");
42             else 
43                 printf("%d\n",ask(x-1)^ask(y));
44         }
45         else return 0;
46         scanf("\n");
47     }
48     return 0;
49 }

 

转载于:https://www.cnblogs.com/wjnclln/p/9596115.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值