每日一题 day15 打卡
Analysis
树状数组
用树状数组来维护每个字符变化的次数,如果是偶数就是0,奇数就是1
#include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #define int long long #define maxn 100000+10 using namespace std; inline int read() { int x=0; bool f=1; char c=getchar(); for(; !isdigit(c); c=getchar()) if(c=='-') f=0; for(; isdigit(c); c=getchar()) x=(x<<3)+(x<<1)+c-'0'; if(f) return x; return 0-x; } inline void write(int x) { if(x<0){putchar('-');x=-x;} if(x>9)write(x/10); putchar(x%10+'0'); } int n,m; int tree[maxn]; inline int lowbit(int num) { return num&-num; } inline void build(int s,int num) { for(int i=s;i<=n;i+=lowbit(i)) tree[i]+=num; } inline int ask(int s) { int ans=0; for(int i=s;i>=1;i-=lowbit(i)) ans+=tree[i]; return ans; } signed main() { n=read();m=read(); for(int i=1;i<=m;i++) { int in=read(); /* for(int i=1;i<=n;i++) { int tim=ask(i); if(tim==0) write(0); else if(tim%2==0) write(0); else if(tim%2==1) write(1); cout<<" "; } cout<<endl; */ if(in==1) { int l=read(),r=read(); build(l,1); build(r+1,-1); } if(in==2) { int x=read(); int tim=ask(x); if(tim%2==0) write(0); else if(tim%2==1) write(1); printf(" "); } } return 0; }
请各位大佬斧正(反正我不认识斧正是什么意思)