9823 | 2024-03-08 18:41:44 | szil | Sokszorozott maximumok | cpp17 | Time limit exceeded 55/100 | 2.085s | 395252 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 k) {
if (k == 0) return 1;
if (k & 1) return (a*bpow(a, k-1))%MOD;
ll x = bpow(a, k/2);
return (x*x)%MOD;
}
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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 28ms | 39396 KiB | ||||
subtask2 | 11/11 | ||||||
2 | Accepted | 43ms | 39672 KiB | ||||
3 | Accepted | 39ms | 39720 KiB | ||||
4 | Accepted | 41ms | 41552 KiB | ||||
5 | Accepted | 43ms | 43520 KiB | ||||
6 | Accepted | 28ms | 40324 KiB | ||||
7 | Accepted | 43ms | 41448 KiB | ||||
subtask3 | 0/13 | ||||||
8 | Accepted | 43ms | 40444 KiB | ||||
9 | Accepted | 41ms | 40616 KiB | ||||
10 | Accepted | 48ms | 42512 KiB | ||||
11 | Time limit exceeded | 2.068s | 105568 KiB | ||||
12 | Time limit exceeded | 2.085s | 198824 KiB | ||||
13 | Time limit exceeded | 2.079s | 198936 KiB | ||||
subtask4 | 19/19 | ||||||
14 | Accepted | 716ms | 324120 KiB | ||||
15 | Accepted | 722ms | 359944 KiB | ||||
16 | Accepted | 996ms | 377492 KiB | ||||
17 | Accepted | 1.039s | 395236 KiB | ||||
18 | Accepted | 833ms | 395252 KiB | ||||
subtask5 | 25/25 | ||||||
19 | Accepted | 483ms | 129880 KiB | ||||
20 | Accepted | 512ms | 112440 KiB | ||||
21 | Accepted | 441ms | 112428 KiB | ||||
22 | Accepted | 437ms | 128816 KiB | ||||
23 | Accepted | 382ms | 82516 KiB | ||||
subtask6 | 0/32 | ||||||
24 | Time limit exceeded | 2.075s | 199800 KiB | ||||
25 | Time limit exceeded | 2.071s | 199748 KiB | ||||
26 | Accepted | 1.562s | 325032 KiB | ||||
27 | Accepted | 1.661s | 360792 KiB | ||||
28 | Accepted | 1.945s | 378188 KiB | ||||
29 | Time limit exceeded | 2.065s | 199076 KiB | ||||
30 | Accepted | 1.82s | 348388 KiB |