-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1823.cpp
146 lines (134 loc) · 3.16 KB
/
1823.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#include <stdio.h>
#include <algorithm>
#include <math.h>
#include <assert.h>
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define ln(x) ((int)x.length())
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define dbg(x) cout << #x << ": " << x << endl;
#define clr(x,v) memset(x, v, sizeof(x));
#define fix(x) cout << setprecision(x) << fixed;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// #define rand(st, ed) uniform_int_distribution<int>(st, ed)(rng)
// using ll = long long int;
// using ld = long double;
// using pi = pair<int, int>;
typedef long long int ll;
typedef long double ld;
typedef pair<int, int> pi;
const double PI = acos(-1.0);
const double eps = 1e-9;
const ll mod = 1e9 + 7;
const int inf = 1e7;
const int MAXN = 16000 + 5;
struct ftype
{
int pref, suff, ans, len;
ftype(): pref(0), suff(0), ans(0), len(0) {}
void clear()
{
pref = suff = ans = len;
}
void fill()
{
pref = suff = ans = 0;
}
};
ftype t[4 * MAXN];
int lazy[4 * MAXN];
ftype e; // Identity Element
ftype combine(ftype L, ftype R)
{
ftype res;
res.pref = L.ans == L.len ? L.ans + R.pref : L.pref;
res.suff = R.ans == R.len ? R.ans + L.suff : R.suff;
res.ans = max(max(L.ans, R.ans), L.suff + R.pref);
res.len = L.len + R.len;
return res;
}
void push(int v, int tl, int tr)
{
int tm = (tl + tr) >> 1;
if(lazy[v] == -1) return;
if(lazy[v] == 0) // vacate [tl, tr]
{
t[v << 1].clear();
t[v << 1 | 1].clear();
lazy[v << 1] = lazy[v << 1 | 1] = 0;
}
else
{
t[v << 1].fill();
t[v << 1 | 1].fill();
lazy[v << 1] = lazy[v << 1 | 1] = 1;
}
lazy[v] = -1;
}
void build(int v, int tl, int tr)
{
if(tl == tr)
{
t[v].len = 1, t[v].clear(), lazy[v] = -1;
}
else
{
int tm = (tl + tr) >> 1;
build(v << 1, tl, tm);
build(v << 1 | 1, tm + 1, tr);
t[v] = combine(t[v << 1], t[v << 1 | 1]);
lazy[v] = -1;
}
}
void update(int v, int tl, int tr, int l, int r, int val)
{
if(l > r) return;
if(tl == l && tr == r)
{
if(val == 0) t[v].clear();
else t[v].fill();
lazy[v] = val;
}
else
{
int tm = (tl + tr) >> 1;
push(v, tl, tr);
update(v << 1, tl, tm, l, min(r, tm), val);
update(v << 1 | 1, tm + 1, tr, max(l, tm + 1), r, val);
t[v] = combine(t[v << 1], t[v << 1 | 1]);
}
}
void cp()
{
int n, q;
scanf("%d %d", &n, &q);
build(1, 0, n - 1);
while(q--)
{
int t, x, k;
scanf("%d", &t);
if(t < 3) scanf("%d %d", &x, &k), x--;
if(t == 1) update(1, 0, n - 1, x, x + k - 1, 1);
else if(t == 2) update(1, 0, n - 1, x, x + k - 1, 0);
else printf("%d\n", ::t[1].ans);
}
}
int main()
{
// FASTIO;
int t;
t = 1;
// cin >> t;
while(t--)
{
cp();
}
return 0;
}