Submission #135147

#TimeUsernameProblemLanguageResultExecution timeMemory
135147dooweyWorst Reporter 3 (JOI18_worst_reporter3)C++14
100 / 100
905 ms25548 KiB
#pragma GCC optimize("Ofast") #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<ll, ll> pii; #define fi first #define se second #define mp make_pair #define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0); const int N = (int)5e5 + 9; const ll MAX = (ll)2e18; ll per[N]; ll compute(int id, ll tim){ return (tim-(tim%per[id]))-id; } int main(){ fastIO; int n, q; cin >> n >> q; cin >> per[1]; for(int i = 2; i <= n; i ++ ){ cin >> per[i]; per[i] = (per[i - 1] * (((per[i] - 1) / per[i-1]) + 1)); } ll L, R, T; ll res; int lf, rf, md; int p1, p2; for(int i = 0 ; i < q; i ++ ){ cin >> T >> L >> R; lf = 0; rf = n + 1; while(lf + 1 < rf){ md=(lf+rf)/2; if(compute(md, T) < L) rf = md; else lf = md; } p1 = lf; lf = 0; rf = n + 1; while(lf + 1 < rf){ md = (lf + rf) / 2; if(compute(md, T) <= R){ rf = md; } else{ lf = md; } } p2 = lf; cout << max(0, p1 - p2) + (T >= L && T <= R) << "\n"; } return 0; }

Compilation message (stderr)

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:32:8: warning: unused variable 'res' [-Wunused-variable]
     ll res;
        ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...