From d8dd0c81b14bc00a36b01f83c00b8eb1cf237779 Mon Sep 17 00:00:00 2001 From: Zengtudor Date: Sat, 23 Aug 2025 13:57:11 +0800 Subject: [PATCH] update --- src/8/23/P3939.cpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/8/23/P3939.cpp diff --git a/src/8/23/P3939.cpp b/src/8/23/P3939.cpp new file mode 100644 index 0000000..6ab9e10 --- /dev/null +++ b/src/8/23/P3939.cpp @@ -0,0 +1,63 @@ +#include +#include +#include + +void fast_io() { + std::ios_base::sync_with_stdio(false); + std::cin.tie(nullptr); +} + +const int MAXN = 300005; + +int n, m; +int a[MAXN]; +std::vector pos[MAXN]; + +int main() { + fast_io(); + + std::cin >> n >> m; + for (int i = 1; i <= n; ++i) { + std::cin >> a[i]; + pos[a[i]].push_back(i); + } + + for (int i = 0; i < m; ++i) { + int op; + std::cin >> op; + if (op == 1) { + + int l, r, c; + std::cin >> l >> r >> c; + + auto it_l = std::lower_bound(pos[c].begin(), pos[c].end(), l); + auto it_r = std::upper_bound(pos[c].begin(), pos[c].end(), r); + + std::cout << (it_r - it_l) << "\n"; + + } else { + + int x; + std::cin >> x; + + int c1 = a[x]; + int c2 = a[x + 1]; + + if (c1 == c2) { + continue; + } + + auto it1 = std::lower_bound(pos[c1].begin(), pos[c1].end(), x); + + *it1 = x + 1; + + auto it2 = std::lower_bound(pos[c2].begin(), pos[c2].end(), x + 1); + + *it2 = x; + + std::swap(a[x], a[x + 1]); + } + } + + return 0; +}