Untitled
unknown
plain_text
a year ago
2.0 kB
7
Indexable
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
struct segTree {
vector<ll> sg;
int n{}, MOD = 1e9 + 7;
explicit segTree(int _n) {
for (n = 1; n < _n; n <<= 1);
sg.assign(2 * n, 0);
}
void upd(int id, int val) {
sg[id += n] += val;
for (id >>= 1; id; id >>= 1) sg[id] = sg[id * 2] * sg[id * 2 + 1] % MOD;
}
ll get(int l, int r) {
ll res = 1;
for (l = l + n, r = r + n + 1; l < r; l >>= 1, r >>= 1) {
if (l & 1) res = res * sg[l++] % MOD;
if (r & 1) res = res * sg[--r] % MOD;
}
return res;
}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr), cout.tie(nullptr);
int tt;
cin >> tt;
for (int tc = 0; tc < tt; ++tc) {
int n, q;
cin >> n >> q;
vector<ll> a(n), com;
for (int i = 0; i < n; ++i) {
cin >> a[i];
com.push_back(a[i]);
}
vector<array<int, 3>> qu(q);
for (auto &[ty, x, y]: qu) {
cin >> ty >> x >> y;
if (ty == 1)
com.push_back(y);
}
sort(com.begin(), com.end());
com.erase(unique(com.begin(), com.end()), com.end());
auto get = [&](int x) { return lower_bound(com.begin(), com.end(), x) - com.begin(); };
int sz = com.size();
segTree sg(sz);
for (int i = 0; i < n; ++i) {
a[i] = get(a[i]);
sg.upd(a[i], 1);
}
for (auto &[ty, x, y]: qu) {
if (ty == 1) {
--x;
sg.upd(a[x], -1);
a[x] = get(y);
sg.upd(a[x], 1);
} else {
int l = get(x), r = get(y);
if (l >= sz || r >= sz || com[l] != x || com[r] != y || r - l != y - x)
cout << "0\n";
else
cout << sg.get(l, r) << "\n";
}
}
}
}Editor is loading...
Leave a Comment