Submission #319291

#TimeUsernameProblemLanguageResultExecution timeMemory
319291mohamedsobhi777Worst Reporter 3 (JOI18_worst_reporter3)C++14
100 / 100
657 ms27492 KiB
#include <bits/stdc++.h> #pragma GCC optimize("-Ofast") //#pragma GCC optimize("trapv") #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx2,tune=native") #pragma GCC optimize("-ffast-math") #pragma GCC optimize("-funroll-loops") #define I inline void #define S struct #define vi vector<int> #define vii vector<pair<int, int>> #define pii pair<int, int> #define pll pair<ll, ll> using namespace std; using ll = long long; using ld = long double; const int N = 5e5 + 7, mod = 1e9 + 7; const ll inf = 2e18; // How interesting! int n, m; int a[N]; ll per[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); //freopen("in.in", "r", stdin); cin >> n >> m; for (int i = 0; i < n; ++i) cin >> a[i]; per[0] = a[0]; for (int i = 1; i < n; ++i) per[i] = ceil(1.0 * a[i] / per[i - 1]) * per[i - 1]; for (int i = 0; i < m; ++i) { int x, y, z; cin >> x >> y >> z; int l = 0, r = n - 1; int ans1 = -1, ans2 = -1; int k = 0; while (l <= r) { int mid = (l + r) >> 1; int pos = -(mid + 1); int d = x / per[mid]; pos += d * per[mid]; if (pos >= y) { ans1 = mid; l = mid + 1; } else r = mid - 1; } l = 0, r = ans1; while (l <= r) { int mid = (l + r) >> 1; int pos = -(mid + 1); int d = x / per[mid]; pos += d * per[mid]; if (pos <= z) { ans2 = mid; r = mid - 1; } else l = mid + 1; } int ans = 0 ; if(ans1== -1 || ans2 == -1);else ans = ans1 - ans2 + 1; cout << ans + (x >= y && x <= z) << "\n"; } return 0; }

Compilation message (stderr)

worst_reporter3.cpp: In function 'int main()':
worst_reporter3.cpp:49:21: warning: unused variable 'k' [-Wunused-variable]
   49 |                 int k = 0;
      |                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...