$> Codeforces \ Space 455 D .? Serega? And? Fun <$
Theme:
You have a sequence with a length of \ (n \). You must support two operations.
Given \ (L, r \), convert \ (A _ {I + 1} \) to \ (a_ I \), \ (a_l \) to \ (a_r, I \ in [L, R )\)
Returns \ (L, R, X \), and calculates the number of occurrences of \ (x \) in \ ([L, R] \).
\ (1 \ Leq n, m \ Leq 10 ^ 5 \)
Solution:
Song
/*program by mangoyang*/#pragma GCC optimize("Ofast","O3", "inline","-ffast-math")#pragma GCC target("avx,sse2,sse3,sse4,mmx")#include<bits/stdc++.h>#define inf (0x7f7f7f7f)#define Max(a, b) ((a) > (b) ? (a) : (b))#define Min(a, b) ((a) < (b) ? (a) : (b))typedef long long ll;using namespace std; inline char read() { static const int IN_LEN = 200000; static char buf[IN_LEN], *s, *t; return (s == t ? t = (s = buf) + fread(buf, 1, IN_LEN, stdin), (s == t ? -1 : *s++) : *s++);}template<class T>inline void read(T &x) { static bool iosig; static char c; for (iosig = false, c = read(); !isdigit(c); c = read()) { if (c == '-') iosig = true; if (c == -1) return; } for (x = 0; isdigit(c); c = read()) x = ((x + (x << 2)) << 1) + (c ^ '0'); if (iosig) x = -x;}const int OUT_LEN = 500000;char obuf[OUT_LEN], *ooh = obuf;inline void print(char c) { if (ooh == obuf + OUT_LEN) fwrite(obuf, 1, OUT_LEN, stdout), ooh = obuf; *ooh++ = c;}template<class T>inline void print(T x) { static int buf[30], cnt; if (x == 0) print('0'); else { if (x < 0) print('-'), x = -x; for (cnt = 0; x; x /= 10) buf[++cnt] = x % 10 + 48; while (cnt) print((char)buf[cnt--]); }}inline void flush() { fwrite(obuf, 1, ooh - obuf, stdout); }const int N = 100005;int a[N], s[N], n, m, lastans;int main(){ read(n); for(register int i = 1; i <= n; ++i) read(a[i]), s[a[i]]++; register int *p; read(m); for(register int i = 1, j, op, x, y, z, tmp, res; i <= m; ++i){ read(op), read(x), read(y); x = (x + lastans - 1) % n + 1, y = (y + lastans - 1) % n + 1; if(x > y) swap(x, y); if(op & 1){ p = a + y, tmp = *p, j = y - x; while(j) *p = *(p-1), --p, --j; *p = tmp; } else{ read(z), z = (z + lastans - 1) % n + 1, res = 0; if(y - x + 1<= n / 2){ p = a + x - 1; for(j = x; j + 8 <= y; j += 8) { res += (*(++p) == z), res += (*(++p) == z); res += (*(++p) == z), res += (*(++p) == z); res += (*(++p) == z), res += (*(++p) == z); res += (*(++p) == z), res += (*(++p) == z); } for(; j <= y; j++) res += (*(++p) == z); print(lastans = res), print('\n'); } else{ p = a; for(j = 1; j + 8 < x; j += 8){ res += (*(++p) == z), res += (*(++p) == z); res += (*(++p) == z), res += (*(++p) == z); res += (*(++p) == z), res += (*(++p) == z); res += (*(++p) == z), res += (*(++p) == z); } for(; j < x; j++) res += (*(++p) == z); p = a + y; for(j = y + 1; j + 8 <= n; j += 8){ res += (*(++p) == z), res += (*(++p) == z); res += (*(++p) == z), res += (*(++p) == z); res += (*(++p) == z), res += (*(++p) == z); res += (*(++p) == z), res += (*(++p) == z); } for(; j <= n; j++) res += (*(++p) == z); print(lastans = s[z] - res), print('\n'); } } } return flush(), 0;}
Codeforces 455 D. serega and fun