#include <bits/stdc++.h>
#pragma GCC optimize ("Ofast", "unroll-loops")
using namespace std;
#define ll long long
#define int ll
#define FOR(i,a,b) for (int i = (a); i<(b); i++)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define RREP(i,n) for (int i=(n)-1; i>=0; i--)
#define RREP1(i,n) for (int i=(n); i>=1; i--)
#define f first
#define s second
#define pb push_back
#define ALL(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define SQ(x) (x)*(x)
#define pii pair<int, int>
#define pdd pair<double ,double>
#define pcc pair<char, char>
#define endl '\n'
//#define TOAD
#ifdef TOAD
#define bug(x) cerr<<__LINE__<<": "<<#x<<" is "<<x<<endl
#define IOS()
#else
#define bug(...)
#define IOS() ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#endif
const ll inf = 1ll<<60;
const int iinf=2147483647;
const ll mod = 1e9+7;
const ll maxn=2e5+5;
const double PI=acos(-1);
ll pw(ll x, ll p, ll m=mod){
ll ret=1;
while (p>0){
if (p&1){
ret*=x;
ret%=m;
}
x*=x;
x%=m;
p>>=1;
}
return ret;
}
ll inv(ll a, ll m=mod){
return pw(a,m-2);
}
//=======================================================================================
vector<int> seg(4*maxn);
vector<int> vc(maxn);
void build(int l, int r, int x){
if (l==r){
seg[x]=vc[l];
return;
}
int mid=(l+r)/2;
build(l, mid, x+x);
build(mid+1, r, x+x+1);
seg[x]=max(seg[x+x], seg[x+x+1]);
}
int query(int l, int r, int nl, int nr, int x){
if (r<nl||l>nr){
return 0;
}
if (nl>=l&&nr<=r){
return seg[x];
}
int mid=(nl+nr)/2;
return max(query(l, r, nl, mid, x+x), query(l, r, mid+1, nr, x+x+1));
}
struct typ{
int l, r;
int t;
};
signed main (){
IOS();
int n, q; cin>>n>>q;
REP1(i,n) cin>>vc[i];
vector<typ> vq(q);
build(1, n, 1);
bool gg=1;
REP(i, q){
cin>>vq[i].t>>vq[i].l>>vq[i].r;
gg=(gg&(vq[i].l==vq[i].r));
}
if (n<=200&&q<=200){
REP(i,q){
int sm=0;
FOR(j, vq[i].l, vq[i].r+1){
int l=max(j-vq[i].t, 1ll);
sm+=query(l, j, 1, n, 1);
}
cout<<sm<<endl;
}
return 0;
}
if (!gg){
vector<int> pf(n+1);
REP1(i,n){
int l=max(i-vq[0].t, 1ll);
pf[i]=pf[i-1]+query(l, i, 1, n, 1);
}
REP(i, q){
cout<<pf[vq[i].r]-pf[vq[i].l-1]<<endl;
}
}
else {
REP(i, q){
int l=max(vq[i].l-vq[i].t, 1ll);
cout<<query(l, vq[i].r, 1, n, 1)<<endl;
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
6 ms |
8148 KB |
Output is correct |
3 |
Correct |
5 ms |
8168 KB |
Output is correct |
4 |
Correct |
6 ms |
8148 KB |
Output is correct |
5 |
Correct |
5 ms |
8148 KB |
Output is correct |
6 |
Correct |
5 ms |
8148 KB |
Output is correct |
7 |
Correct |
6 ms |
8120 KB |
Output is correct |
8 |
Correct |
5 ms |
8164 KB |
Output is correct |
9 |
Correct |
5 ms |
8148 KB |
Output is correct |
10 |
Correct |
5 ms |
8148 KB |
Output is correct |
11 |
Correct |
4 ms |
8148 KB |
Output is correct |
12 |
Correct |
4 ms |
8148 KB |
Output is correct |
13 |
Correct |
4 ms |
8164 KB |
Output is correct |
14 |
Correct |
5 ms |
8148 KB |
Output is correct |
15 |
Correct |
4 ms |
8148 KB |
Output is correct |
16 |
Correct |
4 ms |
8148 KB |
Output is correct |
17 |
Correct |
6 ms |
8056 KB |
Output is correct |
18 |
Correct |
4 ms |
8148 KB |
Output is correct |
19 |
Correct |
4 ms |
8168 KB |
Output is correct |
20 |
Correct |
4 ms |
8148 KB |
Output is correct |
21 |
Correct |
4 ms |
8148 KB |
Output is correct |
22 |
Correct |
5 ms |
8044 KB |
Output is correct |
23 |
Correct |
5 ms |
8148 KB |
Output is correct |
24 |
Correct |
5 ms |
8148 KB |
Output is correct |
25 |
Correct |
5 ms |
8148 KB |
Output is correct |
26 |
Correct |
6 ms |
8148 KB |
Output is correct |
27 |
Correct |
5 ms |
8148 KB |
Output is correct |
28 |
Correct |
5 ms |
8160 KB |
Output is correct |
29 |
Correct |
5 ms |
8164 KB |
Output is correct |
30 |
Correct |
5 ms |
8148 KB |
Output is correct |
31 |
Correct |
5 ms |
8148 KB |
Output is correct |
32 |
Correct |
5 ms |
8160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
122 ms |
17316 KB |
Output is correct |
3 |
Correct |
122 ms |
17368 KB |
Output is correct |
4 |
Correct |
127 ms |
17612 KB |
Output is correct |
5 |
Correct |
112 ms |
17352 KB |
Output is correct |
6 |
Correct |
143 ms |
17220 KB |
Output is correct |
7 |
Correct |
120 ms |
17516 KB |
Output is correct |
8 |
Correct |
123 ms |
17472 KB |
Output is correct |
9 |
Correct |
113 ms |
17560 KB |
Output is correct |
10 |
Correct |
113 ms |
17392 KB |
Output is correct |
11 |
Correct |
119 ms |
17560 KB |
Output is correct |
12 |
Correct |
110 ms |
17276 KB |
Output is correct |
13 |
Correct |
125 ms |
17296 KB |
Output is correct |
14 |
Correct |
129 ms |
17168 KB |
Output is correct |
15 |
Correct |
113 ms |
17292 KB |
Output is correct |
16 |
Correct |
117 ms |
17356 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
155 ms |
15028 KB |
Output is correct |
3 |
Correct |
156 ms |
14760 KB |
Output is correct |
4 |
Correct |
206 ms |
14868 KB |
Output is correct |
5 |
Correct |
142 ms |
14680 KB |
Output is correct |
6 |
Correct |
149 ms |
14940 KB |
Output is correct |
7 |
Correct |
163 ms |
14776 KB |
Output is correct |
8 |
Correct |
173 ms |
14908 KB |
Output is correct |
9 |
Correct |
159 ms |
14868 KB |
Output is correct |
10 |
Correct |
182 ms |
14704 KB |
Output is correct |
11 |
Correct |
177 ms |
14916 KB |
Output is correct |
12 |
Correct |
153 ms |
14700 KB |
Output is correct |
13 |
Correct |
166 ms |
14932 KB |
Output is correct |
14 |
Correct |
203 ms |
14832 KB |
Output is correct |
15 |
Correct |
165 ms |
14836 KB |
Output is correct |
16 |
Correct |
154 ms |
14628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
110 ms |
15604 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
8148 KB |
Output is correct |
2 |
Correct |
6 ms |
8148 KB |
Output is correct |
3 |
Correct |
5 ms |
8168 KB |
Output is correct |
4 |
Correct |
6 ms |
8148 KB |
Output is correct |
5 |
Correct |
5 ms |
8148 KB |
Output is correct |
6 |
Correct |
5 ms |
8148 KB |
Output is correct |
7 |
Correct |
6 ms |
8120 KB |
Output is correct |
8 |
Correct |
5 ms |
8164 KB |
Output is correct |
9 |
Correct |
5 ms |
8148 KB |
Output is correct |
10 |
Correct |
5 ms |
8148 KB |
Output is correct |
11 |
Correct |
4 ms |
8148 KB |
Output is correct |
12 |
Correct |
4 ms |
8148 KB |
Output is correct |
13 |
Correct |
4 ms |
8164 KB |
Output is correct |
14 |
Correct |
5 ms |
8148 KB |
Output is correct |
15 |
Correct |
4 ms |
8148 KB |
Output is correct |
16 |
Correct |
4 ms |
8148 KB |
Output is correct |
17 |
Correct |
6 ms |
8056 KB |
Output is correct |
18 |
Correct |
4 ms |
8148 KB |
Output is correct |
19 |
Correct |
4 ms |
8168 KB |
Output is correct |
20 |
Correct |
4 ms |
8148 KB |
Output is correct |
21 |
Correct |
4 ms |
8148 KB |
Output is correct |
22 |
Correct |
5 ms |
8044 KB |
Output is correct |
23 |
Correct |
5 ms |
8148 KB |
Output is correct |
24 |
Correct |
5 ms |
8148 KB |
Output is correct |
25 |
Correct |
5 ms |
8148 KB |
Output is correct |
26 |
Correct |
6 ms |
8148 KB |
Output is correct |
27 |
Correct |
5 ms |
8148 KB |
Output is correct |
28 |
Correct |
5 ms |
8160 KB |
Output is correct |
29 |
Correct |
5 ms |
8164 KB |
Output is correct |
30 |
Correct |
5 ms |
8148 KB |
Output is correct |
31 |
Correct |
5 ms |
8148 KB |
Output is correct |
32 |
Correct |
5 ms |
8160 KB |
Output is correct |
33 |
Correct |
122 ms |
17316 KB |
Output is correct |
34 |
Correct |
122 ms |
17368 KB |
Output is correct |
35 |
Correct |
127 ms |
17612 KB |
Output is correct |
36 |
Correct |
112 ms |
17352 KB |
Output is correct |
37 |
Correct |
143 ms |
17220 KB |
Output is correct |
38 |
Correct |
120 ms |
17516 KB |
Output is correct |
39 |
Correct |
123 ms |
17472 KB |
Output is correct |
40 |
Correct |
113 ms |
17560 KB |
Output is correct |
41 |
Correct |
113 ms |
17392 KB |
Output is correct |
42 |
Correct |
119 ms |
17560 KB |
Output is correct |
43 |
Correct |
110 ms |
17276 KB |
Output is correct |
44 |
Correct |
125 ms |
17296 KB |
Output is correct |
45 |
Correct |
129 ms |
17168 KB |
Output is correct |
46 |
Correct |
113 ms |
17292 KB |
Output is correct |
47 |
Correct |
117 ms |
17356 KB |
Output is correct |
48 |
Correct |
155 ms |
15028 KB |
Output is correct |
49 |
Correct |
156 ms |
14760 KB |
Output is correct |
50 |
Correct |
206 ms |
14868 KB |
Output is correct |
51 |
Correct |
142 ms |
14680 KB |
Output is correct |
52 |
Correct |
149 ms |
14940 KB |
Output is correct |
53 |
Correct |
163 ms |
14776 KB |
Output is correct |
54 |
Correct |
173 ms |
14908 KB |
Output is correct |
55 |
Correct |
159 ms |
14868 KB |
Output is correct |
56 |
Correct |
182 ms |
14704 KB |
Output is correct |
57 |
Correct |
177 ms |
14916 KB |
Output is correct |
58 |
Correct |
153 ms |
14700 KB |
Output is correct |
59 |
Correct |
166 ms |
14932 KB |
Output is correct |
60 |
Correct |
203 ms |
14832 KB |
Output is correct |
61 |
Correct |
165 ms |
14836 KB |
Output is correct |
62 |
Correct |
154 ms |
14628 KB |
Output is correct |
63 |
Incorrect |
110 ms |
15604 KB |
Output isn't correct |
64 |
Halted |
0 ms |
0 KB |
- |