98222024-03-08 18:38:55szilSokszorozott maximumokcpp17Wrong answer 0/1002.082s395332 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
subtask20/11
2Wrong answer4ms2028 KiB
3Wrong answer3ms2388 KiB
4Wrong answer7ms3760 KiB
5Wrong answer6ms5284 KiB
6Wrong answer3ms3184 KiB
7Wrong answer4ms3916 KiB
subtask30/13
8Wrong answer4ms3180 KiB
9Wrong answer3ms3320 KiB
10Wrong answer10ms4320 KiB
11Accepted1.932s179424 KiB
12Time limit exceeded2.076s198680 KiB
13Time limit exceeded2.069s198756 KiB
subtask40/19
14Wrong answer547ms310540 KiB
15Wrong answer750ms352724 KiB
16Wrong answer824ms373736 KiB
17Accepted922ms395156 KiB
18Accepted902ms395332 KiB
subtask50/25
19Wrong answer199ms90184 KiB
20Wrong answer192ms72760 KiB
21Wrong answer190ms72500 KiB
22Wrong answer188ms88920 KiB
23Wrong answer119ms41144 KiB
subtask60/32
24Accepted1.973s395308 KiB
25Time limit exceeded2.082s199284 KiB
26Wrong answer1.595s311200 KiB
27Wrong answer1.526s353248 KiB
28Wrong answer1.85s374304 KiB
29Wrong answer1.921s394416 KiB
30Wrong answer1.912s338524 KiB