Submission #949771

#TimeUsernameProblemLanguageResultExecution timeMemory
949771peterandvoiModern Machine (JOI23_ho_t5)C++17
37 / 100
684 ms69420 KiB
#include <bits/stdc++.h> using namespace std; #ifdef ngu #include "debug.h" #else #define debug(...) 42 #endif const int N = 120005; int n, m, q; char c[N]; int a[N]; struct from_to { int l, L, len; from_to(): l(0), L(0), len(0) {}; from_to(int l, int L, int len): l(l), L(L), len(len) {}; int r() const { return l + len - 1; } bool operator < (const from_to &oth) const { return l < oth.l; } }; vector<from_to> tree[N << 2]; int add(int a, int b) { a += b; while (a >= n + 1) { a -= n + 1; } return a; } vector<from_to> cmb(const vector<from_to> &a, const vector<from_to> &b) { vector<from_to> res; for (auto [bl, al, len] : a) { int ar = add(al, len - 1); int br = add(bl, len - 1); int L = lower_bound(b.begin(), b.end(), from_to(al + 1, 0, 0)) - b.begin() - 1; int R = lower_bound(b.begin(), b.end(), from_to(ar + 1, 0, 0)) - b.begin() - 1; R += al > ar ? (int) b.size() : 0; for (int i = L; i <= R; ++i) { int j = i % (int) b.size(); int delta = max(b[j].l, al) - b[j].l; int len = min(br - bl + 1, b[j].r() - max(b[j].l, al) + 1); int tl = add(b[j].L, delta); res.emplace_back(bl, tl, len); bl += len; al = add(al, len); } } return res; } void bld(int id, int l, int r) { if (l == r) { tree[id].emplace_back(0, add(0, a[l] + 1), a[l]); tree[id].emplace_back(a[l], add(a[l], a[l]), n - a[l] + 1); } else { int mid = l + r >> 1; bld(id << 1, l, mid); bld(id << 1 | 1, mid + 1, r); tree[id] = cmb(tree[id << 1], tree[id << 1 | 1]); } } int get(const vector<from_to> &a, int p) { int pos = lower_bound(a.begin(), a.end(), from_to(p + 1, 0, 0)) - a.begin() - 1; return add(a[pos].L, p - a[pos].l); } int qry(int u, int v, int p, int id = 1, int l = 1, int r = m) { if (u <= l && r <= v) { return get(tree[id], p); } int mid = l + r >> 1; if (u <= mid && mid < v) { return qry(u, v, qry(u, v, p, id << 1, l, mid), id << 1 | 1, mid + 1, r); } if (mid < u) { return qry(u, v, p, id << 1 | 1, mid + 1, r); } return qry(u, v, p, id << 1, l, mid); } signed main() { ios::sync_with_stdio(false); cin.tie(0); #ifdef ngu freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); #endif cin >> n >> m; for (int i = 1; i <= n; ++i) { cin >> c[i]; } for (int i = 1; i <= m; ++i) { cin >> a[i]; } bld(1, 1, m); cin >> q; int s = 0; for (int i = 1; i <= n; ++i) { if (c[i] != 'R') { break; } s = i; } while (q--) { int l, r; cin >> l >> r; cout << qry(l, r, s) << "\n"; } }

Compilation message (stderr)

Main.cpp: In function 'void bld(int, int, int)':
Main.cpp:70:21: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   70 |         int mid = l + r >> 1;
      |                   ~~^~~
Main.cpp: In function 'int qry(int, int, int, int, int, int)':
Main.cpp:86:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   86 |     int mid = l + r >> 1;
      |               ~~^~~
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...