Submission #779812

#TimeUsernameProblemLanguageResultExecution timeMemory
779812tvladm2009Worst Reporter 3 (JOI18_worst_reporter3)C++17
12 / 100
37 ms29392 KiB
#include <bits/stdc++.h> using namespace std; #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds; template<class T> using oset = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; typedef long long ll; const int N = (int) 5e5 + 7; int d[N], when[N], jump[N]; int n, q; struct T { int l; int r; int id; }; vector<T> questions[N]; int sol[N]; signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // freopen("input", "r", stdin); cin >> n >> q; for (int i = 1; i <= n; i++) { cin >> d[i]; } int mxt = 0; for (int i = 1; i <= q; i++) { int t, l, r; cin >> t >> l >> r; mxt = max(mxt, t); questions[t].push_back({l, r, i}); } vector<int> a(n + 1); for (int i = 1; i <= n; i++) { a[i] = -i; } when[1] = d[1]; jump[1] = d[1]; for (int i = 2; i <= n; i++) { int from = -i + d[i] + 1 + (i - 1); assert(jump[i - 1] != 0); int moment = (from - 1) / jump[i - 1] + 1; int t = when[i - 1] * moment; when[i] = t; jump[i] = a[i - 1] + jump[i - 1] * (when[i] / when[i - 1]) - a[i] - 1; } vector<vector<int>> divs(mxt + 1), who(mxt + 1); for (int i = 1; i <= mxt; i++) { for (int j = i; j <= mxt; j += i) { divs[j].push_back(i); } } for (int i = 1; i <= n; i++) { if (when[i] <= mxt) { who[when[i]].push_back(i); } } oset<pair<int, int>> s; for (int i = 1; i <= n; i++) { s.insert({a[i], i}); } for (int i = 1; i <= mxt; i++) { for (auto &j : divs[i]) { for (auto &it : who[j]) { s.erase({a[it], it}); a[it] += jump[it]; s.insert({a[it], it}); } } for (auto &it : questions[i]) { int l = it.l; int r = it.r; int ret = s.order_of_key(make_pair(r, n + 1)) - s.order_of_key(make_pair(l - 1, n + 1)); sol[it.id] = ret + (l <= i && i <= r); } } for (int i = 1; i <= q; i++) { cout << sol[i] << "\n"; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...