Submission #459667

#TimeUsernameProblemLanguageResultExecution timeMemory
459667JovanBWorst Reporter 3 (JOI18_worst_reporter3)C++17
100 / 100
416 ms21444 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; const ll INF = 100000000000LL; ll intersect(ll l, ll r, ll tl, ll tr){ return max(0LL, min(r, tr) - max(l, tl) + 1); } int main(){ ios_base::sync_with_stdio(false), cin.tie(0); cout.precision(10); cout << fixed; int n, m; cin >> n >> m; vector <pair <pair <int, int>, ll>> intervals; intervals.push_back({{0, 0}, 1}); ll pos = 1; for(int i=1; i<=n; i++){ int x; cin >> x; ll g = pos*((x+pos-1)/pos); g = min(g, INF); if(g == intervals.back().second){ pair <pair <int, int>, ll> v = intervals.back(); intervals.pop_back(); v.first.first = -i; intervals.push_back(v); } else{ pair <pair <int, int>, ll> v; v.first.first = v.first.second = -i; v.second = g; intervals.push_back(v); } pos = g; } while(m--){ ll t, tl, tr; cin >> t >> tl >> tr; ll res = 0; for(auto c : intervals){ ll l = c.first.first; ll r = c.first.second; ll g = c.second; ll dist = g*(t/g); l += dist; r += dist; res += intersect(l, r, tl, tr); } cout << res << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...