Submission

Status:
PPPPPTTTTTT

Score: 50

User: Winzzwz

Problemset: เปิดไฟ

Language: cpp

Time: 1.086 second

Submitted On: 2024-11-10 22:35:48

#include <bits/stdc++.h>
using namespace std;
int n,m;
int lights[100100];
int dp[100100];

int main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    cin >> n >> m;
    bool computed = false;
    while (m--) {
        int op, s, e;
        cin >> op >> s >> e;
        if (op == 0) {
            lights[s]++;
            lights[e+1]--;
        } else {
            memset(dp,0,sizeof(dp));
            int cnt = 0;
            for (int i = 1; i <= n; i++) {
                dp[i] = dp[i-1] + lights[i];
                if (i >= s && i <= e && dp[i]%2 == 1) cnt++;
            }
            cout << cnt << "\n";
        }
    }
    return 0;
}