Submission #127732

#TimeUsernameProblemLanguageResultExecution timeMemory
127732RockyBWorst Reporter 3 (JOI18_worst_reporter3)C++17
0 / 100
2043 ms65268 KiB
#include <bits/stdc++.h> #define f first #define s second #define pb push_back #define pp pop_back #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() #define rep(a, b, c) for (int a = (b); (a) <= (c); ++a) #define per(a, b, c) for (int a = (b); (a) >= (c); --a) #define nl '\n' #define ioi exit(0); using namespace std; const int MAX_N = (int)5e5 + 7; int n, q; int d[MAX_N], l[MAX_N], r[MAX_N], t[MAX_N], ans[MAX_N]; map <int, vector <int> > off; void solve(int T, vector <int> &qr) { vector <int> a; a.pb(T); rep(i, 1, n) { int p = -i; while (a.back() - p > d[i]) p += d[i]; if (i > 1 && a.back() + i > d[i]) p = a.back() - 1; a.pb(p); } reverse(all(a)); /* for (auto it : a) cerr << it << ' '; cerr << nl; */ for (auto it : qr) { int L = l[it], R = r[it]; ans[it] = upper_bound(all(a), R) - lower_bound(all(a), L); } } int main() { #ifdef IOI freopen ("in.txt", "r", stdin); #endif ios_base :: sync_with_stdio(0), cin.tie(0), cout.tie(0); cin >> n >> q; rep(i, 1, n) cin >> d[i]; rep(i, 1, q) { cin >> t[i] >> l[i] >> r[i]; off[t[i]].pb(i); } for (auto it : off) { solve(it.f, it.s); } rep(i, 1, q) { cout << ans[i] << nl; } ioi }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...