#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
using vi = vector<int>;
using vl = vector<long long>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<long long, long long>>;
#define fur(i, a, b) for(ll i = a; i <= (ll)b; ++i)
#define ruf(i, a, b) for(ll i = a; i >= (ll)b; --i)
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define nl "\n"
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
const ll mxn = 3e5L + 1;
ll n, q;
ll d[mxn];
ll a[mxn];
struct item {
ll zer, one, zlt, zrt, olt, ort;
item() {
zer = one = zlt = zrt = olt = ort = 0;
}
};
struct SegTree {
ll n;
item id;
vector<item> tree;
SegTree(ll N) {
init(N);
}
void init(ll N) {
id = item();
n = N;
while(__builtin_popcountll(n) != 1) ++n;
tree.resize(2*n, id);
}
void build() {
build(1, 0, n - 1);
}
void build(ll x, ll lx, ll rx) {
if(lx == rx)
return;
ll d = (lx + rx) / 2;
build(2*x, lx, d);
build(2*x + 1, d + 1, rx);
tree[x] = merge(tree[2*x], tree[2*x + 1], (rx - lx + 1) / 2);
}
item query(ll x, ll lx, ll rx, ll l, ll r) {
if(r < lx || rx < l)
return id;
if(l <= lx && rx <= r)
return tree[x];
ll d = (lx + rx) / 2;
item a = query(2*x, lx, d, l, r);
item b = query(2*x + 1, d + 1, rx, l, r);
return merge(a, b, (rx - lx + 1) / 2);
}
ll query(ll ql, ll qh) {
item res = query(1, 0, n - 1, ql, qh);
return max(res.one, res.zer);
}
item merge(item lhs, item rhs, ll sz) {
item ans;
// ones
ans.olt = lhs.olt;
if(lhs.olt == sz)
ans.olt += rhs.olt;
ans.ort = rhs.ort;
if(rhs.ort == sz) {
ans.ort += lhs.ort;
}
ans.one = max({lhs.olt, rhs.ort, lhs.one, rhs.one, lhs.ort + rhs.olt});
// zeroes
ans.zlt = lhs.zlt;
if(lhs.zlt == sz) {
ans.zlt += rhs.zlt;
}
ans.zrt = rhs.zrt;
if(rhs.zrt == sz) {
ans.zrt += lhs.zrt;
}
ans.zer = max({lhs.zlt, rhs.zrt, lhs.zer, rhs.zer, lhs.zrt + rhs.zlt});
return ans;
}
};
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> q;
fur(i, 1, n) {
cin >> d[i];
}
ruf(i, n, 2) {
d[i] = d[i] - d[i - 1];
}
d[1] = d[2] + 1;
ll cur = 1;
fur(i, 1, n) {
ll j = i;
while(j <= n && d[j] == d[i]) {
a[j] = cur;
++j;
}
cur = 1 - cur;
i = j - 1;
}
SegTree st(n);
fur(i, st.n, st.n + n - 1) {
if(a[i - st.n + 1] == 0) {
st.tree[i].zer = 1;
st.tree[i].zrt = 1;
st.tree[i].zlt = 1;
} else {
st.tree[i].one = 1;
st.tree[i].ort = 1;
st.tree[i].olt = 1;
}
}
st.build();
while(q--) {
ll t;
cin >> t;
if(t == 1) {
ll l, r, s, c;
cin >> l >> r >> s >> c;
}
else if(t == 2) {
ll l, r, s, c;
cin >> l >> r >> s >> c;
}
else if(t == 3) {
ll l, r;
cin >> l >> r;
cout << 1 << nl;
// ll res = st.query(l - 1, r - 1);
// if(res != r - l + 1)
// ++res;
// cout << res << nl;
}
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
139 ms |
54492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
135 ms |
54784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
147 ms |
54356 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
135 ms |
54784 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
139 ms |
54492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |