Submission #535794

#TimeUsernameProblemLanguageResultExecution timeMemory
535794abc864197532Fire (JOI20_ho_t5)C++17
6 / 100
146 ms12716 KiB
#include <bits/stdc++.h> using namespace std; #define lli long long int #define mp make_pair #define eb emplace_back #define pb push_back #define pii pair<int,int> #define X first #define Y second #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() void abc() {cout << endl;} template <typename T, typename ...U> void abc(T i, U ...j) { cout << i << ' ', abc(j...); } template <typename T> void printv(T l, T r) { for (; l != r; ++l) cout << *l << " \n"[l + 1 == r]; } #ifdef Doludu #define test(x...) abc("[" + string(#x) + "]", x) #define owo freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout) #else #define test(x...) void(0) #define owo ios::sync_with_stdio(false), cin.tie(0) #endif const int N = 200005; int bit[N]; void add(int p, int v) { for (p += 2; p < N; p += p & (-p)) bit[p] += v; } int query(int p) { int ans = 0; for (p += 2; p > 0; p -= p & (-p)) ans += bit[p]; return ans; } int main () { owo; int n, q; cin >> n >> q; vector <int> a(n); for (int i = 0; i < n; ++i) cin >> a[i]; vector <int> pre(n, n + 1); for (int i = 0; i < n; ++i) { if (a[i] == 2) pre[i] = 0; else if (i) { pre[i] = pre[i - 1] + 1; } } vector <array <int, 4>> queries; for (int i = 0, t, l, r; i < q; ++i) { cin >> t >> l >> r, --l, t++; queries.pb({t, l, r, i}); } sort(rall(queries)); vector <int> ans(q); vector <int> p(n); iota(all(p), 0); sort(all(p), [&](int i, int j) { return pre[i] > pre[j]; }); int now = 0; for (auto i : queries) { while (now < n && pre[p[now]] >= i[0]) { add(p[now] + 1, 1); now++; } ans[i[3]] = 2 * (i[2] - i[1]) - (query(i[2]) - query(i[1])); } for (int i : ans) cout << i << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...