Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstring>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <map>
- #include <stack>
- #include <queue>
- #include <deque>
- #include <unordered_map>
- #include <numeric>
- #include <iomanip>
- using namespace std;
- #define pii pair<long long, long long>
- #define ll long long
- #define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
- const long long dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
- const long long dl[2] = {1, -1};
- const long long MOD = 1000000007;
- const long long MAXN = 100005;
- int N, M;
- int seg[MAXN * 4];
- bool lazy[MAXN * 4];
- void prop(int x, int s, int e){
- if(!lazy[x]) return;
- seg[x] = (e + 1 - s) - seg[x];
- if(s != e){
- lazy[x * 2] = !lazy[x * 2];
- lazy[x * 2 + 1] = !lazy[x * 2 + 1];
- }
- lazy[x] = false;
- }
- void update(int x, int s, int e, int a, int b){
- prop(x, s, e);
- if(b < s or e < a) return;
- if(a <= s and e <= b){
- lazy[x] = !lazy[x];
- prop(x, s, e);
- return;
- }
- int mid = (s + e)/2;
- update(x * 2, s, mid, a, b);
- update(x * 2 + 1, mid + 1, e, a, b);
- seg[x] = seg[x * 2] + seg[x * 2 + 1];
- }
- int query(int x, int s, int e, int a, int b){
- prop(x, s, e);
- if(b < s or e < a) return 0;
- if(a <= s and e <= b) return seg[x];
- int mid = (s + e)/2;
- int q1 = query(x * 2, s, mid, a, b);
- int q2 = query(x * 2 + 1, mid + 1, e, a, b);
- // cout << s << " to " << e << ": " << q1 << " " << q2 << "\n";
- return q1 + q2;
- }
- int main() {
- FAST;
- cin >> N >> M;
- for(int a, b, c, i = 0; i < M; i++){
- cin >> a >> b >> c;
- if(a == 0){
- if(b > c){
- swap(b, c);
- }
- update(1, 1, N, b, c);
- }
- else{
- if(b > c){
- swap(b, c);
- }
- // cout << "Start query " << b << " " << c << ":\n";
- cout << query(1, 1, N, b, c) << "\n";
- }
- }
- }
- /*
- 4 5
- 0 1 2
- 0 2 4
- 1 2 3
- 0 2 4
- 1 1 4
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement