#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,avx2")
#pragma GCC optimize("unroll-loops,O2")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr ll N = 5e5+10,mod = 998244353,inf = 1e9+10,lg = 20;
inline int mkay(int a,int b){
if (a+b >= mod) return a+b-mod;
if (a+b < 0) return a+b+mod;
return a+b;
}
inline int poww(int a,int k){
if (k < 0) return 0;
int z = 1;
while (k){
if (k&1) z = 1ll*z*a%mod;
a = 1ll*a*a%mod;
k /= 2;
}
return z;
}
int d[N];
int po[N/500+10][N/500+10];
int main(){
ios :: sync_with_stdio(0); cin.tie(0);
int n,q;
cin >> n >> q;
bool fl = 1;
rep(i,1,n+1){
cin >> d[i];
if (d[i] != 1) fl = 0;
}
if (fl){
while (q--){
int t,l,r;
cin >> t >> l >> r;
if (t < l || t-n > r){
cout << 0 << endl;
continue;
}
cout << min(t,r)-max(l,t-n)+1 << endl;
}
return 0;
}
rep(i,0,1001) po[0][i] = i;
rep(i,1,n+1) po[i][0] = -i;
rep(j,1,1001){
rep(i,1,n+1){
if (po[i-1][j]-po[i][j-1] >= d[i]+1) po[i][j] = po[i-1][j]-1;
else po[i][j] = po[i][j-1];
}
}
while (q--){
int t,l,r;
cin >> t >> l >> r;
int ans = 0;
rep(i,0,n+1) if (po[i][t] >= l && po[i][t] <= r) ans++;
cout << ans << endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
190 ms |
5172 KB |
Output is correct |
2 |
Correct |
205 ms |
5272 KB |
Output is correct |
3 |
Correct |
194 ms |
5188 KB |
Output is correct |
4 |
Correct |
198 ms |
5344 KB |
Output is correct |
5 |
Correct |
196 ms |
5196 KB |
Output is correct |
6 |
Correct |
192 ms |
5196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
4180 KB |
Output is correct |
2 |
Correct |
6 ms |
4180 KB |
Output is correct |
3 |
Correct |
6 ms |
4192 KB |
Output is correct |
4 |
Correct |
6 ms |
4188 KB |
Output is correct |
5 |
Correct |
7 ms |
4308 KB |
Output is correct |
6 |
Correct |
6 ms |
4308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
190 ms |
5172 KB |
Output is correct |
2 |
Correct |
205 ms |
5272 KB |
Output is correct |
3 |
Correct |
194 ms |
5188 KB |
Output is correct |
4 |
Correct |
198 ms |
5344 KB |
Output is correct |
5 |
Correct |
196 ms |
5196 KB |
Output is correct |
6 |
Correct |
192 ms |
5196 KB |
Output is correct |
7 |
Correct |
6 ms |
4180 KB |
Output is correct |
8 |
Correct |
6 ms |
4180 KB |
Output is correct |
9 |
Correct |
6 ms |
4192 KB |
Output is correct |
10 |
Correct |
6 ms |
4188 KB |
Output is correct |
11 |
Correct |
7 ms |
4308 KB |
Output is correct |
12 |
Correct |
6 ms |
4308 KB |
Output is correct |
13 |
Runtime error |
55 ms |
17496 KB |
Execution killed with signal 11 |
14 |
Halted |
0 ms |
0 KB |
- |