1 条题解
-
0
JAVA ac代码:
import java.util.*; import java.util.StringTokenizer; import java.io.*; public class Main { public static void main(String[] args) { int n=in.nextInt(); int m=in.nextInt(); while(m-->0) { int op=in.nextInt(); if(op==1){ int x=in.nextInt(); out.println((n>>x)&1);//n的第x位是不是1 }else if(op==2) { int l=in.nextInt(),r=in.nextInt(); for(int i=l;i<=r;i++) { n=(1<<i)^n; //(1<<i)的异或,需要知道一个数异或0等于它本身。所以只是对该位异或1 } out.println(n); }else if(op==3) { int l=in.nextInt(),r=in.nextInt(); for(int i=l;i<=r;i++) { n=(1<<i)|n; //0|0=0;0|1=1;不改变其他位的结果 } out.println(n); }else if(op==4) { int l=in.nextInt(),r=in.nextInt(); for(int i=l;i<=r;i++) { //如果n的第i个位置的值是1的话 if(((n>>i)&1)==1) { n=(1<<i)^n;//该位1^1=0 } }out.println(n); }else { int ans=0,temp=-1; //pow(2,30)差不多Integer.max for(int i=0;i<=30;i++) { if(((n>>i)&1)==1) { temp=i; break; } } out.println(temp==-1?0:(1<<temp)&n); } } out.close(); } static FastReader in=new FastReader(); static PrintWriter out=new PrintWriter(System.out); static class FastReader{ static BufferedReader br; static StringTokenizer st; FastReader(){ br=new BufferedReader(new InputStreamReader(System.in)); } String next() { String str=""; while(st==null||!st.hasMoreElements()) { try { str=br.readLine(); }catch(IOException e) { throw new RuntimeException(e); } st=new StringTokenizer(str); } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } double nextDouble() { return Double.parseDouble(next()); } long nextLong() { return Long.parseLong(next()); } } }
- 1
信息
- ID
- 71
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 3
- 标签
- 递交数
- 63
- 已通过
- 23
- 上传者