求调
查看原帖
求调
470590
LikAzusa_楼主2024/9/19 19:43

只有十分。

#include <bits/stdc++.h>

using namespace std;

inline int read()
{
	int x = 0, f = 1; char c = getchar();
	while(c > '9' || c < '0') {if(c == '-') f = -1; c = getchar();}
	while(c <= '9' && c >= '0') {x = x * 10 + c - '0'; c = getchar();}
	return x * f;
}

const int maxn = 1e5 + 10;

struct Node
{
	int op, l, r, x, id;
	int block;
} t[maxn];
bool cmp(Node a, Node b)
{
	if(a.block == b.block) return a.r < b.r;
	return a.l < b.l;
}
int N = 100000;
int len, a[maxn], cnt[maxn], ans[maxn];
int n, m;
bitset<maxn>s1, s2;

void add(int x)
{
	s1[a[x]] = s2[N-a[x]] = ++cnt[a[x]];
}

void del(int x)
{
	s1[a[x]] = s2[N-a[x]] = (--cnt[a[x]])!=0;
}

int main()
{
//	freopen("ans.out", "w", stdout);
	n = read(); m = read();
	int len = sqrt(n);
	for(int i = 1; i <= n; i++)
	{
		a[i] = read();
	}
	for(int i = 1; i <= m; i++)
	{
		t[i].id = i; t[i].op = read(); t[i].l = read(); t[i].r = read(); t[i].x = read();
		t[i].block = t[i].l / len + 1;
	}
	sort(t + 1, t + m + 1, cmp);
	int l = 0, r = 0;
	for(int i = 1; i <= m; i++)
	{
		while(l > t[i].l) add(--l);	
		while(r < t[i].r) add(++r);
		while(l < t[i].l) del(l++);
		while(r > t[i].r) del(r--);
		if(t[i].op == 1)
		{
			ans[t[i].id] = (s1 & (s2 << t[i].x)) != 0;
		}
		else if(t[i].op == 2)
		{
			ans[t[i].id] = (s1 & (s2 >> (N-t[i].x))) != 0;
		}
		else if(t[i].op == 3)
		{
			for(int j = 1; j*j <= t[i].x; j++)
			{
				if(t[i].x % j == 0)
				{
					if(s1[j] && s1[t[i].x / j]) ans[t[i].id] = 1;
				}
			}
		}
	}
	for(int i = 1; i <= m; i++)
	{
		if(ans[i]) cout << "hana" << endl;
		else cout << "bi" << endl;
	}
	return 0;
}

2024/9/19 19:43
加载中...