9822 | 2024-03-08 18:38:55 | szil | Sokszorozott maximumok | cpp17 | Wrong answer 0/100 | 2.082s | 395332 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, n)};
for (int i = 1; i <= n; i++) {
int x; cin >> x;
roots.emplace_back(upd(roots.back(), 1, n, x));
}
while (q--) {
int l, r, k; cin >> l >> r >> k;
l++; r++;
cout << qry(roots[r], roots[l-1], 1, n, 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 | 3ms | 1832 KiB | ||||
subtask2 | 0/11 | ||||||
2 | Wrong answer | 4ms | 2028 KiB | ||||
3 | Wrong answer | 3ms | 2388 KiB | ||||
4 | Wrong answer | 7ms | 3760 KiB | ||||
5 | Wrong answer | 6ms | 5284 KiB | ||||
6 | Wrong answer | 3ms | 3184 KiB | ||||
7 | Wrong answer | 4ms | 3916 KiB | ||||
subtask3 | 0/13 | ||||||
8 | Wrong answer | 4ms | 3180 KiB | ||||
9 | Wrong answer | 3ms | 3320 KiB | ||||
10 | Wrong answer | 10ms | 4320 KiB | ||||
11 | Accepted | 1.932s | 179424 KiB | ||||
12 | Time limit exceeded | 2.076s | 198680 KiB | ||||
13 | Time limit exceeded | 2.069s | 198756 KiB | ||||
subtask4 | 0/19 | ||||||
14 | Wrong answer | 547ms | 310540 KiB | ||||
15 | Wrong answer | 750ms | 352724 KiB | ||||
16 | Wrong answer | 824ms | 373736 KiB | ||||
17 | Accepted | 922ms | 395156 KiB | ||||
18 | Accepted | 902ms | 395332 KiB | ||||
subtask5 | 0/25 | ||||||
19 | Wrong answer | 199ms | 90184 KiB | ||||
20 | Wrong answer | 192ms | 72760 KiB | ||||
21 | Wrong answer | 190ms | 72500 KiB | ||||
22 | Wrong answer | 188ms | 88920 KiB | ||||
23 | Wrong answer | 119ms | 41144 KiB | ||||
subtask6 | 0/32 | ||||||
24 | Accepted | 1.973s | 395308 KiB | ||||
25 | Time limit exceeded | 2.082s | 199284 KiB | ||||
26 | Wrong answer | 1.595s | 311200 KiB | ||||
27 | Wrong answer | 1.526s | 353248 KiB | ||||
28 | Wrong answer | 1.85s | 374304 KiB | ||||
29 | Wrong answer | 1.921s | 394416 KiB | ||||
30 | Wrong answer | 1.912s | 338524 KiB |