Submission #937693

#TimeUsernameProblemLanguageResultExecution timeMemory
937693zwezdinvModern Machine (JOI23_ho_t5)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> int main() { std::cin.tie(nullptr)->sync_with_stdio(false); int n, m; std::cin >> n >> m; std::string c; std::cin >> c; int st = 0; for (int i = 0; i < n; ++i) { st |= (c[i] == 'R') << i; } std::vector<std::vector<int>> ss(1 << n, std::vector<int>(n)); for (int mask = 0; mask < 1 << n; ++mask) { for (int i = 0; i < n; ++i) { int m4sk = mask; int ptr = i; m4sk |= 1 << i; while (0 <= ptr && ptr < n) { m4sk ^= 1 << ptr; if (~m4sk >> ptr & 1) { ptr++; } else { ptr--; } } ss[mask][i] = m4sk; } } std::vector<std::vector<int>> cur(n); std::vector<int> a(m); for (auto& i : a) std::cin >> i, --i; std::vector<int> qq(1 << n, -1); std::vector<int> pos(m, -1); std::vector<int> leader(m, -1); std::vector<std::vector<std::pair<int, int>>> que(m); int q; std::cin >> q; std::vector<int> ans(q); for (int i = 0; i < q; ++i) { int l, r; std::cin >> l >> r; --l, --r; que[r].emplace_back(l, i); } for (int i = 0; i < m; ++i) { if (qq[st] == -1) { qq[st] = i; pos[i] = st; leader[i] = i; } else { leader[i] = qq[st]; } std::vector<int> nw(1 << n, -1); for (int j = 0; j < 1 << n; ++j) { nw[ss[j][a[i]]] = qq[j]; if (qq[j] != -1) pos[qq[j]] = ss[j][a[i]]; } qq = nw; for (auto [l, id] : que[i]) { ans[id] = __builtin_popcount(pos[leader[l]]); } } for (auto i : ans) std::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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...