9824 | 2024-03-08 18:44:22 | szil | Sokszorozott maximumok | cpp17 | Elfogadva 100/100 | 1.491s | 395316 KiB |
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int MAXN = 200'001;
const ll MOD = 1e9+7;
ll bpow(ll a, ll b) {
ll res = 1;
while (b > 0) {
if (b & 1) {
res = (res * a) % MOD;
}
a = (a * a) % MOD;
b >>= 1;
}
return res;
}
ll inv(ll a) {
return bpow(a, MOD-2);
}
struct Node {
Node *l, *r;
int val = 0;
ll mult = 1;
Node(int x, ll y) : val(x), mult(y) {}
Node(Node *a, Node *b) : l(a), r(b) {
if (a) {
val += a->val;
mult *= a->mult;
mult %= MOD;
}
if (b) {
val += b->val;
mult *= b->mult;
mult %= MOD;
}
}
};
Node *build(int tl, int tr) {
if (tl == tr) {
return new Node(0, 1);
} else {
int tm = (tl + tr) / 2;
return new Node(build(tl, tm), build(tm+1, tr));
}
}
Node *upd(Node *v, int tl, int tr, int pos) {
if (tl == tr) {
return new Node(v->val+1, (v->mult*tl)%MOD);
} else {
int tm = (tl + tr) / 2;
if (pos <= tm) {
return new Node(upd(v->l, tl, tm, pos), v->r);
} else {
return new Node(v->l, upd(v->r, tm+1, tr, pos));
}
}
}
ll qry(Node *v, Node *u, int tl, int tr, int k) {
if (tl == tr) {
return bpow(tl, k);
} else {
int tm = (tl + tr) / 2;
int to_right = v->r->val - u->r->val;
if (k <= to_right) {
return qry(v->r, u->r, tm+1, tr, k);
} else {
return (((v->r->mult*inv(u->r->mult))%MOD)*qry(v->l, u->l, tl, tm, k-to_right))%MOD;
}
}
}
void solve() {
int n, q; cin >> n >> q;
vector<Node *> roots = {build(1, MAXN)};
for (int i = 1; i <= n; i++) {
int x; cin >> x;
roots.emplace_back(upd(roots.back(), 1, MAXN, x));
}
while (q--) {
int l, r, k; cin >> l >> r >> k;
l++; r++;
cout << qry(roots[r], roots[l-1], 1, MAXN, k) << "\n";
}
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
Részfeladat | Összpont | Teszt | Verdikt | Idő | Memória | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Elfogadva | 28ms | 39404 KiB | ||||
subtask2 | 11/11 | ||||||
2 | Elfogadva | 34ms | 39816 KiB | ||||
3 | Elfogadva | 32ms | 40080 KiB | ||||
4 | Elfogadva | 34ms | 41620 KiB | ||||
5 | Elfogadva | 37ms | 43668 KiB | ||||
6 | Elfogadva | 28ms | 40248 KiB | ||||
7 | Elfogadva | 34ms | 41328 KiB | ||||
subtask3 | 13/13 | ||||||
8 | Elfogadva | 34ms | 40520 KiB | ||||
9 | Elfogadva | 32ms | 40664 KiB | ||||
10 | Elfogadva | 35ms | 42324 KiB | ||||
11 | Elfogadva | 1.029s | 208416 KiB | ||||
12 | Elfogadva | 1.284s | 394172 KiB | ||||
13 | Elfogadva | 1.309s | 394392 KiB | ||||
subtask4 | 19/19 | ||||||
14 | Elfogadva | 593ms | 323644 KiB | ||||
15 | Elfogadva | 637ms | 359420 KiB | ||||
16 | Elfogadva | 857ms | 377128 KiB | ||||
17 | Elfogadva | 741ms | 394708 KiB | ||||
18 | Elfogadva | 718ms | 394672 KiB | ||||
subtask5 | 25/25 | ||||||
19 | Elfogadva | 423ms | 129488 KiB | ||||
20 | Elfogadva | 310ms | 111996 KiB | ||||
21 | Elfogadva | 381ms | 112116 KiB | ||||
22 | Elfogadva | 279ms | 128648 KiB | ||||
23 | Elfogadva | 252ms | 82152 KiB | ||||
subtask6 | 32/32 | ||||||
24 | Elfogadva | 1.437s | 395316 KiB | ||||
25 | Elfogadva | 1.424s | 395232 KiB | ||||
26 | Elfogadva | 1.131s | 324428 KiB | ||||
27 | Elfogadva | 1.2s | 360180 KiB | ||||
28 | Elfogadva | 1.396s | 377876 KiB | ||||
29 | Elfogadva | 1.491s | 394408 KiB | ||||
30 | Elfogadva | 1.307s | 347856 KiB |