社区讨论

萌新还没学OI,求助

CF896EWelcome home, Chtholly参与者 5已保存回复 5

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
5 条
当前快照
1 份
快照标识符
@lrt91om1
此快照首次捕获于
2024/01/25 21:28
2 年前
此快照最后确认于
2024/01/26 08:50
2 年前
查看原帖
Wrong answer on test 4.
CPP
#pragma GCC optimize(3, "Ofast", "inline")
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
// #define int long long
#define ll long long
#define ull unsigned long long
#define min std::min
#define max std::max
#define swap std::swap
#define lowbit(x) (x & -x)
#define I_like_chtholly true
#define I_dont_like_chtholly false
#define RandNumber 1814724131
#ifndef ONLINE_JUDGE
bool online_judge = true;
#else
bool online_judge = false;
#endif

namespace IO
{
	const int N = 1e6 + 5;
	char obuf[N], * p3 = obuf; char ibuf[N], * p1 = ibuf, * p2 = ibuf;
	inline void flush() { fwrite(obuf, p3 - obuf, 1, stdout); p3 = obuf; }
	inline void putch(char x) { (p3 - obuf < N) ? (*p3++ = x) : (flush(), *p3++ = x); }
	inline char getch() { if (online_judge) return getchar(); else return p1 == p2 && (p2 = (p1 = ibuf) + fread(ibuf, 1, N, stdin), p1 == p2) ? EOF : *p1++; }
	inline bool READ(char& p) { p = getch(); while (p == ' ' || p == '\n' || p == -1) { if (p == -1) return true; p = getch(); } return false; }
	inline bool READ(char* p) { char ch = getch(); while (ch == ' ' || ch == '\n' || ch == -1) { if (ch == -1) return true; ch = getch(); } while (ch != ' ' && ch != '\n' && ch != -1) { *p++ = ch; ch = getch(); } *p++ = '\0'; return ch == -1; }
	inline bool READ(std::string str) { str = ""; char ch = getch(); while (ch == ' ' || ch == '\n' || ch == -1) { if (ch == -1) return true; ch = getch(); } while (ch != ' ' && ch != '\n' && ch != -1) { str += ch; ch = getch(); } return ch == -1; }
	inline bool READ(signed& x) { register char ch = getch(); while (ch < '0' || ch > '9') { if (ch == -1) return true; if (ch == '-') { if (READ(x)) { x = -x; return true; } x = -x; return false; } ch = getch(); } x = 0; while (ch <= '9' && ch >= '0') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getch(); } if (ch == -1) return true; return false; } inline bool READ(unsigned& x) { register char ch = getch(); while (ch < '0' || ch > '9') { if (ch == -1) return true; ch = getch(); } x = 0; while (ch <= '9' && ch >= '0') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getch(); } if (ch == -1) return true; return false; }
	inline bool READ(short& x) { register char ch = getch(); while (ch < '0' || ch > '9') { if (ch == -1) return true; if (ch == '-') { if (READ(x)) { x = -x; return true; } x = -x; return false; } ch = getch(); } x = 0; while (ch <= '9' && ch >= '0') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getch(); } if (ch == -1) return true; return false; } inline bool READ(unsigned short& x) { register char ch = getch(); while (ch < '0' || ch > '9') { if (ch == -1) return true; ch = getch(); } x = 0; while (ch <= '9' && ch >= '0') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getch(); } if (ch == -1) return true; return false; }
	inline bool READ(long long& x) { register char ch = getch(); while (ch < '0' || ch > '9') { if (ch == -1) return true; if (ch == '-') { if (READ(x)) { x = -x; return true; } x = -x; return false; } ch = getch(); } x = 0; while (ch <= '9' && ch >= '0') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getch(); } if (ch == -1) return true; return false; } inline bool READ(unsigned long long& x) { register char ch = getch(); while (ch < '0' || ch > '9') { if (ch == -1) return true; ch = getch(); } x = 0; while (ch <= '9' && ch >= '0') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getch(); } if (ch == -1) return true; return false; }
	inline bool READ(__int128_t& x) { register char ch = getch(); while (ch < '0' || ch > '9') { if (ch == -1) return true; if (ch == '-') { if (READ(x)) { x = -x; return true; } x = -x; return false; } ch = getch(); } x = 0; while (ch <= '9' && ch >= '0') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getch(); } if (ch == -1) return true; return false; } inline bool READ(__uint128_t& x) { register char ch = getch(); while (ch < '0' || ch > '9') { if (ch == -1) return true; ch = getch(); } x = 0; while (ch <= '9' && ch >= '0') { x = (x << 3) + (x << 1) + (ch ^ 48); ch = getch(); } if (ch == -1) return true; return false; }
	inline bool read() { return false; }
	template < typename T, typename ... T2 > inline bool read(T& x, T2& ... oth) { if (READ(x)) return true; return read(oth...); }
	inline int Read() { register int x = 0; read(x); return x; }
	inline void WRITE(char ch) { putch(ch); }
	inline void WRITE(char* ch) { register int len = strlen(ch); for (register int i = 0; i < len; i++) putch(ch[i]); }
	inline void WRITE(std::string ch) { register int siz = ch.size(); for (register int i = 0; i < siz; i++) putch(ch[i]); }
	inline void WRITE(signed x) { if (!x) { putch('0'); return ; } register int len = 0; register signed k1 = x; register char c[50] = {}; if (k1 < 0) k1 = -k1, putch('-'); while (k1) c[len++] = k1 % 10 ^ 48, k1 /= 10; while (len--) putch(c[len]); }
	inline void WRITE(unsigned x) { if (!x) { putch('0'); return ; } register int len = 0; register unsigned k1 = x; register char c[50] = {}; while (k1) c[len++] = k1 % 10 ^ 48, k1 /= 10; while (len--) putch(c[len]); }
	inline void WRITE(short x) { if (!x) { putch('0'); return ; } register int len = 0; register short k1 = x; register char c[50] = {}; if (k1 < 0) k1 = -k1, putch('-'); while (k1) c[len++] = k1 % 10 ^ 48, k1 /= 10; while (len--) putch(c[len]); }
	inline void WRITE(unsigned short x) { if (!x) { putch('0'); return ; } register int len = 0; register unsigned short k1 = x; register char c[50] = {}; while (k1) c[len++] = k1 % 10 ^ 48, k1 /= 10; while (len--) putch(c[len]); }
	inline void WRITE(long long x) { if (!x) { putch('0'); return ; } register int len = 0; register long long k1 = x; register char c[50] = {}; if (k1 < 0) k1 = -k1, putch('-'); while (k1) c[len++] = k1 % 10 ^ 48, k1 /= 10; while (len--) putch(c[len]); }
	inline void WRITE(unsigned long long x) { if (!x) { putch('0'); return ; } register int len = 0; register unsigned long long k1 = x; register char c[50] = {}; while (k1) c[len++] = k1 % 10 ^ 48, k1 /= 10; while (len--) putch(c[len]); }
	inline void WRITE(__int128_t x) { if (!x) { putch('0'); return ; } register int len = 0; register __int128_t k1 = x; register char c[50] = {}; if (k1 < 0) k1 = -k1, putch('-'); while (k1) c[len++] = k1 % 10 ^ 48, k1 /= 10; while (len--) putch(c[len]); }
	inline void WRITE(__uint128_t x) { if (!x) { putch('0'); return ; } register int len = 0; register __uint128_t k1 = x; register char c[50] = {}; while (k1) c[len++] = k1 % 10 ^ 48, k1 /= 10; while (len--) putch(c[len]); }
	inline void write() {  }
	template < typename T, typename ... T2 > inline void write(T x, T2 ... oth) { WRITE(x); write(oth...); }
	template < typename T, typename ... T2 > inline void writef(T x, T2 ... oth) { WRITE(x); write(oth...); flush(); }
} using IO::read; using IO::write; using IO::writef; using IO::flush; using IO::putch; using IO::getch; using IO::Read;
namespace Matrix
{
	template < typename T > struct matrix { int __x, __y; inline void __init() {  } template < typename ... T2 > inline void __init(T x, T2 ... oth) { value[__x][__y] = x; __y++; if (__y == m + 1) __x++, __y = 1; __init(oth...); } std::vector < std::vector < T > > value; int n, m; inline void out() { for (register int i = 1; i <= n; i++) { for (register int j = 1; j <= m; j++) write(value[i][j], " "); write("\n"); } } void operator = (const matrix < T >& s) { value = s.value, n = s.n, m = s.m; } template < typename ... T2 > inline void init(int N, int M, T2 ... oth) { value.clear(); n = N, m = M; value.resize(n + 5, std::vector < T >(m + 5)); __x = 1, __y = 1, __init(oth...); } template < typename ... T2 > matrix(int N, int M, T2 ... oth) { value.clear(); n = N, m = M; value.resize(n + 5, std::vector < T >(m + 5)); __x = 1, __y = 1, __init(oth...); } matrix(matrix < T >& b) { value = b.value, n = b.n, m = b.m; } matrix() {  } std::vector < T > operator [](const int& i) { return value[i]; } };
	template < typename T > matrix < T > operator ~ (const matrix < T >& a) { matrix < T > c(a.m, a.n); for (register int i = 1; i <= a.n; i++) { for (register int j = 1; j <= a.m; j++) { c.value[j][i] = a.value[i][j]; } } return c; }
	template < typename T > matrix < T > operator + (const matrix < T >& a, const matrix < T >& b) { matrix < T > c(a.n, a.m); for (register int i = 1; i <= c.n; i++) { for (register int j = 1; j <= c.m; j++) { c.value[i][j] = a.value[i][j] + b.value[i][j]; } } return c; } template < typename T > void operator += (matrix < T >& a, const matrix < T >& b) { a = a + b; }
	template < typename T > matrix < T > operator - (const matrix < T >& a, const matrix < T >& b) { matrix < T > c(a.n, a.m); for (register int i = 1; i <= a.n; i++) { for (register int j = 1; j <= a.m; j++) { c.value[i][j] = a.value[i][j] - b.value[i][j]; } } return c; } template < typename T > void operator -= (matrix < T >& a, const matrix < T >& b) { a = a - b; }
	template < typename T > matrix < T > operator * (const matrix < T >& a, const matrix < T >& b) { matrix < T > c(a.n, b.m); for (register int i = 1; i <= a.n; i++) { for (register int j = 1; j <= b.m; j++) { for (register int k = 1; k <= a.m; k++) { c.value[i][j] += a.value[i][k] * b.value[k][j]; } } } return c; } template < typename T > void operator *= (matrix < T >& a, const matrix < T >& b) { a = a * b; }
	template < typename T > matrix < T > operator % (const matrix < T >& a, int mod) { matrix < T > c(a.n, a.m); for (register int i = 1; i <= a.n; i++) { for (register int j = 1; j <= a.m; j++) { c.value[i][j] = a.value[i][j] % mod; } } return c; } template < typename T > void operator %= (matrix < T >& a, int mod) { a = a % mod; }
	template < typename T > matrix < T > matrix_ksm(matrix < T > a, int b, int mod = -1) { matrix < T > res(a.n, a.m); register bool flag = true; while (b) { if (b & 1) { if (flag) res = a; else res *= a; flag = false; if (~mod) res %= mod; } b >>= 1; a *= a; if (~mod) a %= mod; } return res; }
} using namespace Matrix;
namespace Math
{
	std::mt19937 rnd((std::chrono::high_resolution_clock::now()).time_since_epoch().count()); inline int rand(int l, int r) { return rnd() % (r - l + 1) + l; }
	inline int gcd(int x, int y) { register int tmp; while (x % y != 0) { tmp = x, x = y, y = tmp % y; } return y; }
	inline int lcm(int x, int y) { return x / gcd(x, y) * y; }
	int Exgcd(int a, int b, int& x, int& y) { if (!b) { x = 0, y = 1; return a; } register int ans = Exgcd(b, a % b, x, y); register int temp = x; x = y, y = temp - a / b * y; return ans; }
	inline int ksm(int x, int y, int mod, int res = 1) { x %= mod; while (y) { if (y & 1) (res *= x) %= mod; y >>= 1; (x *= x) %= mod; } return res; }
	std::vector < bool > is_prime; std::vector < int > phi; std::vector < int > prime; int prime_cnt;
	inline void euler_init(int n) { is_prime.resize(n + 1, true); phi.resize(n + 1); prime.resize(n); prime_cnt = 0; is_prime[1] = 0; phi[1] = 1; for (register int i = 2; i <= n; i++) { if (is_prime[i]) { prime[++prime_cnt] = i; phi[i] = i - 1; } for (register int j = 1; j <= prime_cnt && i * prime[j] <= n; j++) { is_prime[i * prime[j]] = false; if (i % prime[j]) phi[i * prime[j]] = phi[i] * phi[prime[j]]; else { phi[i * prime[j]] = phi[i] * prime[j]; break; } } } }
	inline void prime_init(int n) { is_prime.resize(n + 1, true); prime.resize(n); prime_cnt = 0; is_prime[1] = 0; for (register int i = 2; i <= n; i++) { if (is_prime[i]) prime[++prime_cnt] = i; for (register int j = 1; j <= prime_cnt && i * prime[j] <= n; j++) { is_prime[i * prime[j]] = false; if (i % prime[j] == 0) break; } } }
	inline int powerdown(int a, int mod) { if (a < phi[mod]) return a; return a % phi[mod] + phi[mod]; }
	inline int powerksm(int a, int b, int mod) { return ksm(a, powerdown(b, mod), mod); }
	inline bool CHECK(const int a, const int p) { register int d = p - 1, get = ksm(a, d, p); if (get != 1) return true; while ((d & 1) ^ 1) { if (d >>= 1, (get = ksm(a, d, p)) == p - 1) return false; else if (get != 1) return true; } return false; } const int test[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37 }; inline bool check(const int p) { if (p > 40) { for (int a : test) if (CHECK(a, p)) return false; return true; } for (int a : test) if (p == a) return true; return false; }
} using namespace Math;
namespace Combination
{
	struct ___combination
	{
		std::vector < int > fac, inv; int n, mod;
		inline int c(int n, int m) { return fac[n] * inv[m] % mod * inv[n - m] % mod; }
		inline int a(int n, int m) { return fac[n] * inv[n - m] % mod; }
		inline int lucas(int n, int m) { if (n > mod || m > mod) return lucas(n / mod, m / mod) * c(n % mod, m % mod) % mod; return c(n, m); }
	}; ___combination __combination;
	inline void combination_init(int N, int Mod) { __combination.n = N, __combination.mod = Mod; __combination.fac.resize(__combination.n + 1), __combination.inv.resize(__combination.n + 1); __combination.fac[0] = 1; for (register int i = 1; i <= __combination.n; i++) __combination.fac[i] = __combination.fac[i - 1] * i % __combination.mod; __combination.inv[__combination.n] = ksm(__combination.fac[__combination.n], __combination.mod - 2, __combination.mod); for (register int i = __combination.n - 1; i >= 0; i--) __combination.inv[i] = __combination.inv[i + 1] * (i + 1) % __combination.mod; }
	inline int C(int n, int m) { return __combination.lucas(n, m); } inline int A(int n, int m) { return __combination.a(n, m); }
}// using namespace Combination;
namespace Simple_DataStructure
{
	struct UnionFind
	{
		std::vector < int > fa;
		UnionFind() { fa.clear(); } UnionFind(int size) { fa.resize(size + 1); } UnionFind(std::vector < int > g) { fa = g; }
		int find(int x) { return (!fa[x]) ? (x) : (fa[x] = find(fa[x])); }
		inline void merge(int x, int y) { x = find(x), y = find(y); if (x != y) fa[x] = y; }
	};
	template < typename T >
	struct BIT
	{
		int n;
		std::vector < T > tree;
		BIT() { n = 0, tree.clear(); } BIT(int size) { n = size, tree.resize(size + 1); }
		inline void add(int x, T y) { if (!x) return ; while (x <= n) tree[x] += y, x += lowbit(x); }
		inline T sum(int x) { register T sum = 0; while (x) sum += tree[x], x -= lowbit(x); return sum; }
		inline T sum(int l, int r) { return sum(r) - sum(l - 1); }
	};
} using namespace Simple_DataStructure;

const int N = 1e5 + 5;
int n, m, ma;
int a[N], fa[N], value[N];
struct Updata { int op, l, r, x; };
Updata u[N];
int sq, sub, L, R;
int ans[N], tim;
struct Node
{
	int root, size, dfn;
};
Node g[N];
int find(int x) { return (x == fa[x]) ? (x) : (fa[x] = find(fa[x])); }
inline void merge(int x, int y)
{
	if (g[y].dfn == tim) fa[g[x].root] = g[y].root, g[y].size += g[x].size;
	else g[y] = g[x], value[g[y].root] = y;
	g[x] = { 0, 0, tim };
}
inline void init()
{
	++tim;
	sub = 0;
	ma = 0;
	for (register int i = L; i <= R; i++)
	{
		fa[i] = i;
		ma = max(ma, a[i]);
		if (g[a[i]].dfn != tim)
		{
			g[a[i]].root = i;
			value[i] = a[i];
			g[a[i]].size = 1;
			g[a[i]].dfn = tim;
		}
		else
		{
			fa[i] = g[a[i]].root;
			g[a[i]].size++;
		}
	}
}
inline void nex()
{
	L = R + 1, R = min(L + sq - 1, n);
}
inline void Range(int x)
{
	if (ma - sub > x + x)
	{
		for (register int i = sub + 1; i <= sub + x; i++)
		{
			if (g[i].dfn == tim)
			{
				merge(i, i + x);
			}
		}
		sub += x;
	}
	else
	{
		for (register int i = sub + x + 1; i <= ma; i++)
		{
			if (g[i].dfn == tim)
			{
				merge(i, i - x);
			}
		}
		ma = min(ma, sub + x);
	}
}
inline void range(int l, int r, int x)
{
	for (register int i = L; i <= R; i++)
	{
		a[i] = value[find(i)] - sub;
		if (l >= i && i <= r && a[i] > x) a[i] -= x;
	}
	init();
}
inline void ___()
{
	read(n, m);
	sq = sqrt(n);
	for (register int i = 1; i <= n; i++)
	{
		read(a[i]);
	}
	for (register int i = 1; i <= m; i++) read(u[i].op, u[i].l, u[i].r, u[i].x);
	while (R != n)
	{
		nex();
		init();
		for (register int i = 1; i <= m; i++)
		{
			if (u[i].r < L || u[i].l > R) continue;
			if (u[i].op == 1)
			{
				if (L >= u[i].l && R <= u[i].r) Range(u[i].x);
				else range(max(u[i].l, L), min(u[i].r, R), u[i].x);
			}
			else
			{
				if (L >= u[i].l && R <= u[i].r && u[i].x + sub <= 1e5 && g[u[i].x + sub].dfn == tim) ans[i] += g[u[i].x + sub].size;
				else for (register int j = max(u[i].l, L); j <= min(u[i].r, R); j++) if (value[find(j)] - sub == u[i].x) ans[i]++;
			}
		}
	}
	for (register int i = 1; i <= m; i++)
	{
		if (u[i].op == 2) write(ans[i], "\n");
	}
}
signed main()
{
	register int t = 1;
	// read(t);
	while (t--) ___();
	flush();
}

回复

5 条回复,欢迎继续交流。

正在加载回复...