Submission #1097019

#TimeUsernameProblemLanguageResultExecution timeMemory
1097019vladiliusWorst Reporter 3 (JOI18_worst_reporter3)C++17
100 / 100
249 ms27220 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") using namespace std; using ll = long long; using pii = pair<int, int>; #define pb push_back #define ff first #define ss second int main(){ ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n, q; cin>>n>>q; int d[n + 1]; for (int i = 1; i <= n; i++){ cin>>d[i]; } int k[n + 1]; k[0] = 0; k[1] = d[1]; for (int i = 2; i <= n; i++){ k[i] = ceil(1.0 * d[i] / k[i - 1]) * k[i - 1]; } int all[n + 1], S = 0; for (int i = 1; i <= n; i++){ if (k[i] != k[i - 1]){ all[++S] = i; } } all[++S] = n + 1; int t, l, r, L, R, out, p, P, f, l1, r1; while (q--){ cin>>t>>l>>r; out = (l <= t && t <= r); p = t - 1; for (int i = 1; i + 1 <= S; i++){ L = all[i]; R = all[i + 1] - 1; f = (p + L) / k[L]; P = f * k[L]; l1 = max(l, P - R); r1 = min(r, P - L); out += max(0, (r1 - l1 + 1)); p = (f * k[L] - R) - 1; } cout<<out<<"\n"; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...