Submission #467003

#TimeUsernameProblemLanguageResultExecution timeMemory
467003errayWorst Reporter 3 (JOI18_worst_reporter3)C++17
100 / 100
412 ms23364 KiB
// author: erray #include <bits/stdc++.h> using namespace std; template<typename A, typename B> string to_string(const pair<A, B>& p); template<typename A, typename B, typename C> string to_string(const tuple<A, B, C>& t); template<typename A, typename B, typename C, typename D> string to_string(const tuple<A, B, C, D>& t); string to_string(const string& s) { return '"' + s + '"'; } string to_string(const char& c) { return string("'") + c + "'"; } string to_string(const char *c) { return to_string(string(c)); } string to_string(const bool& b) { return (b ? "true" : "false"); } string to_string(const vector<bool>& v) { string res = "{"; for (int i = 0; i < (int) v.size(); ++i) { if (i > 0) { res += ", "; } res += to_string(v[i]); } res += "}"; return res; } template<size_t T> string to_string(const bitset<T>& bs) { return bs.to_string(); } template<typename T> string to_string(queue<T> q) { string res = "{"; size_t sz = q.size(); while (sz--) { T cur = q.front(); q.pop(); if ((int) res.size() > 1) { res += ", "; } res += to_string(cur); } res += "}"; return res; } template<typename T, class C> string to_string(priority_queue<T, vector<T>, C> pq) { string res = "{"; while (!pq.empty()) { T cur = pq.top(); pq.pop(); if ((int) res.size() > 1) { res += ", "; } res += to_string(cur); } res += "}"; return res; } template<typename T> string to_string(const T& v) { string res = "{"; for (auto &el : v) { if ((int) res.size() > 1) { res += ", "; } res += to_string(el); } res += "}"; return res; } template<typename A, typename B> string to_string(const pair<A, B>& p) { return '(' + to_string(p.first) + ", " + to_string(p.second) + ')'; } template<typename A, typename B, typename C> string to_string(const tuple<A, B, C>& t) { return '(' + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ')'; } template<typename A, typename B, typename C, typename D> string to_string(const tuple<A, B, C, D>& t) { return '(' + to_string(get<0>(t)) + ", " + to_string(get<1>(t)) + ", " + to_string(get<2>(t)) + ", " + to_string(get<3>(t)) + ')'; } void debug_out(int size, bool first, string name) { vector<string> tmp = {name}; vector<int> tmp2 = {size, first}; cerr << endl; } constexpr int buffer_size = 255; template<typename Head, typename... Tail> void debug_out(int size, bool first, string name, Head H, Tail... T) { string tmp; int off = 0; while ((!name.empty() && name[0] != ',') || off != 0) { tmp += name[0]; name.erase(name.begin()); char c = tmp.back(); if (c == '{' || c == '(') { ++off; } else if (c == '}' || c == ')'){ --off; } } if (!name.empty()) { name.erase(name.begin()); } if (tmp[0] == ' ') { tmp.erase(tmp.begin()); } string buff = to_string(H); if ((int) buff.size() + size + (int) tmp.size() > buffer_size - 5 && !first) { cerr << '\n'; size = 0; } cerr << '[' << tmp << ": " << buff << "] "; debug_out(((int) buff.size() + size + (int) tmp.size() + 5) % buffer_size, false, name, T...); } #ifdef DEBUG #define debug(...) cerr << "-> ", debug_out(3, true, string(#__VA_ARGS__), __VA_ARGS__) #define here cerr << "-> " << __LINE__ << endl #else #define debug(...) void(37) #define here void(37) #endif int main() { ios_base::sync_with_stdio(false); cin.tie(0); int n, q; cin >> n >> q; vector<int> a(n); for (int i = 0; i < n; ++i) { cin >> a[i]; } const int inf = int(1e9) + 1; for (int i = 1; i < n; ++i) { debug(a[i] / a[i - 1], !!(a[i] % a[i - 1])); a[i] = min(inf, (a[i] / a[i - 1] + !!(a[i] % a[i - 1])) * a[i - 1]); } debug(a); assert(is_sorted(a.begin(), a.end())); vector<tuple<int, int, int>> all; int lst = 0; for (int i = 0; i < n; ++i) { if (i == n - 1 || a[i + 1] != a[i]) { all.emplace_back(-i - 1, -lst - 1, a[i]); lst = i + 1; } } assert(int(all.size()) < 40); while (q--) { int t, l, r; cin >> t >> l >> r; int ans = (t >= l && t <= r); for (auto[nl, nr, x] : all) { int go = t - (t % x); debug(nl, nr); debug(l - go, r - go); ans += max(0, min(nr, r - go) - max(nl, l - go) + 1); } cout << ans << '\n'; } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...