提交时间:2021-12-06 14:06:01

运行 ID: 33495

#include <bits/stdc++.h> using namespace std; #define int long long inline int read() { int x=0; char c=getchar(); for(; c<'0' || c>'9'; c=getchar()); for(; c<='9' && c>='0'; c=getchar()) x=(x<<3)+(x<<1)+c-'0'; return x; } int n, m, a[100005], opt, x, y; signed main() { //freopen("fun1.in","r",stdin); //freopen("fun.out","w",stdout); n = read(), m = read(); if (n <= 1000 && m <= 1000) { for (int i = 1; i <= n; i++) { a[i - 1] = read(); } while (m--) { opt = read(), x = read(), y = read(); if (opt == 0 || opt == 1) { for (int i = x; i <= y; i++) { a[i] = opt; } } else if (opt == 2) { for (int i = x; i <= y; i++) { a[i] = !a[i]; } } else if (opt == 3) { int ans = 0; for (int i = x; i <= y; i++) { ans += a[i]; } printf("%lld\n", ans); } else if (opt == 4) { int ans = 0, now = 0; for (int i = x; i <= y; i++) { if (a[i] == 0) ans = max(ans, now), now = 0; else now += a[i]; } printf("%lld\n", ans); } } } return 0; }