#include<bits/stdc++.h>
using namespace std;
int n, m, tag[100010], cn, sum[1010];
bool a[100010], lazy[1010];
void update(int p, int q){
for(int i = p;i <= min(tag[p] * cn, q);i++){
if(a[i] == 0) sum[tag[i]]++;
else sum[tag[i]] --;
a[i] = !a[i];
}
if(tag[p] != tag[q]){
for(int i = (tag[q] - 1) * cn + 1;i <= q;i++){
if(a[i] == 0) sum[tag[i]]++;
else sum[tag[i]] --;
a[i] = !a[i];
}
}
for(int i = tag[p] + 1;i <= tag[q] - 1;i++){
lazy[i] = !lazy[i];
sum[i] = cn - sum[i];
}
/*for(int i = 1;i <= n;i++){
if(lazy[tag[i]] == 0) cout << a[i] << " ";
else cout << !a[i] << " ";
}
cout << endl;*/
}
int query(int p, int q){
int ans = 0;
for(int i = p;i <= min(tag[p] * cn, q);i++){
int j = a[i];
if(lazy[tag[i]] == 1){
j = !j;
}
if(j == 1) {
ans ++;
//cout << i << "+1" << endl;
}
}
if(tag[p] != tag[q]){
for(int i = (tag[q] - 1) * cn + 1;i <= q;i++){
int j = a[i];
if(lazy[tag[i]] == 1){
j = !j;
}
if(j == 1) {
ans ++;
//cout << i << "+1" << endl;
}
}
}
for(int i = tag[p] + 1;i <= tag[q] - 1;i++){
ans += sum[i];
}
return ans;
}
int main(){
cin >> n >> m;
cn = sqrt(n);
for(int i = 1;i <= n;i++){
tag[i] = (i - 1) / cn + 1;
//cout << tag[i] << endl;
}
while(m--) {
int op;
cin >> op;
if(op == 0){
int p, q;
cin >> p >> q;
update(p, q);
/*for(int i = 1;i <= 2;i++) {
cout << sum[i] << " ";
}
cout << endl;*/
}
if(op == 1){
int p, q;
cin >> p >> q;
cout << query(p, q) << endl;
}
}
}
蒟蒻很菜,勿喷。 只能过#2
感觉问题不大