9584 | 2024-02-23 12:24:19 | gortomi | Sokszorozott maximumok | cpp17 | Time limit exceeded 36/100 | 2.085s | 523308 KiB |
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1e9 + 7;
struct node
{
ll db, mul, l, r, m;
node *lc, *rc;
node(int il, int ir)
{
l = il;
r = ir;
m = (l + r) / 2;
db = 0;
mul = 1;
lc = nullptr;
rc = nullptr;
}
node * upd(int x, int val)
{
node *cur = new node(l, r);
cur -> db = db + 1;
cur -> mul = (mul * val) % MOD;
cur -> lc = lc;
cur -> rc = rc;
if(l == r) return cur;
if(x <= m) cur -> lc = lc -> upd(x, val);
else cur -> rc = rc -> upd(x, val);
return cur;
}
int sum(int tl, int tr)
{
if(tl > tr) return 0;
if(tl == l && tr == r) return db;
int m = (l + r) / 2;
return lc -> sum(tl, min(tr, m)) + rc -> sum(max(tl, m + 1), tr);
}
ll sig(int tl, int tr)
{
if(tl > tr) return 1;
if(tl == l && tr == r) return mul;
int m = (l + r) / 2;
return (lc -> sig(tl, min(tr, m)) * rc -> sig(max(tl, m + 1), tr)) % MOD;
}
};
node* build(int il, int ir)
{
node *cur = new node(il, ir);
if(il == ir) return cur;
cur -> lc = build(cur -> l, cur -> m);
cur -> rc = build(cur -> m + 1, cur -> r);
return cur;
}
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<pair<int, int> > a(n);
vector<node*> root(n + 1);
root[0] = build(0, n - 1);
for(int i = 0; i < n; i++)
{
cin >> a[i].first;
a[i].second = i;
}
sort(a.rbegin(), a.rend());
for(int i = 0; i < n; i++)
{
root[i + 1] = root[i] -> upd(a[i].second, a[i].first);
}
while(q--)
{
int x, y, k;
cin >> x >> y >> k;
int l = 0, r = n + 1;
while(l + 1 != r)
{
int m = (l + r) / 2;
if(root[m] -> sum(x, y) <= k) l = m;
else r = m;
}
cout << root[l] -> sig(x, y) << "\n";
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1956 KiB | ||||
subtask2 | 11/11 | ||||||
2 | Accepted | 4ms | 2328 KiB | ||||
3 | Accepted | 4ms | 2676 KiB | ||||
4 | Accepted | 8ms | 4396 KiB | ||||
5 | Accepted | 12ms | 6456 KiB | ||||
6 | Accepted | 3ms | 3440 KiB | ||||
7 | Accepted | 8ms | 4416 KiB | ||||
subtask3 | 0/13 | ||||||
8 | Accepted | 4ms | 3784 KiB | ||||
9 | Accepted | 4ms | 3900 KiB | ||||
10 | Accepted | 8ms | 5512 KiB | ||||
11 | Time limit exceeded | 2.015s | 239488 KiB | ||||
12 | Runtime error | 500ms | 523308 KiB | ||||
13 | Runtime error | 500ms | 523200 KiB | ||||
subtask4 | 0/19 | ||||||
14 | Time limit exceeded | 2.066s | 209648 KiB | ||||
15 | Time limit exceeded | 2.085s | 237784 KiB | ||||
16 | Time limit exceeded | 2.085s | 251520 KiB | ||||
17 | Runtime error | 500ms | 522760 KiB | ||||
18 | Runtime error | 500ms | 522744 KiB | ||||
subtask5 | 25/25 | ||||||
19 | Accepted | 801ms | 122668 KiB | ||||
20 | Accepted | 713ms | 97720 KiB | ||||
21 | Accepted | 702ms | 97560 KiB | ||||
22 | Accepted | 626ms | 120892 KiB | ||||
23 | Accepted | 514ms | 55572 KiB | ||||
subtask6 | 0/32 | ||||||
24 | Runtime error | 614ms | 522532 KiB | ||||
25 | Runtime error | 512ms | 522504 KiB | ||||
26 | Time limit exceeded | 2.078s | 210256 KiB | ||||
27 | Time limit exceeded | 2.078s | 238240 KiB | ||||
28 | Time limit exceeded | 2.076s | 252212 KiB | ||||
29 | Runtime error | 609ms | 522240 KiB | ||||
30 | Time limit exceeded | 2.081s | 228620 KiB |