QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#485374#4940. Token DistancePetroTarnavskyi#Compile Error//C++203.7kb2024-07-20 17:18:532024-07-20 17:18:54

Judging History

你现在查看的是最新测评结果

  • [2024-07-20 17:18:54]
  • 评测
  • [2024-07-20 17:18:53]
  • 提交

answer

#include <bits/stdc++.h>

using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;

const int INF = 1e9 + 47;

struct Node
{
	int mn, mx, gcd;
};
	
struct Segtree
{
	int n;
	vector<Node> t;
	void init(int _n)
	{
		n = 1;
		while (n < _n) n *= 2;
		t.assign(n * 2 - 1, {INF, -INF, 0});
	}
	
	void updVal(int v, int tl, int tr, int i, int x)
	{
		if (tl + 1 == tr)
		{
			t[v].mn = t[v].mx = x;
			return;
		}
		int tm = (tl + tr) / 2;
		if (i < tm)
			updVal(v * 2 + 1, tl, tm, i, x);
		else
			updVal(v * 2 + 2, tm, tr, i, x);
		t[v].mn = min(t[v * 2 + 1].mn, t[v * 2 + 2].mn);
		t[v].mx = max(t[v * 2 + 1].mx, t[v * 2 + 2].mx);
	}
	void updVal(int i, int x)
	{
		updVal(0, 0, n, i, x);
	}
	
	void updGcd(int v, int tl, int tr, int i, int x)
	{
		if (tl + 1 == tr)
		{
			t[v].gcd = x;
			return;
		}
		int tm = (tl + tr) / 2;
		if (i < tm)
			updGcd(v * 2 + 1, tl, tm, i, x);
		else
			updGcd(v * 2 + 2, tm, tr, i, x);
		t[v].gcd = gcd(t[v * 2 + 1].gcd, t[v * 2 + 2].gcd);
	}
	void updGcd(int i, int x)
	{
		updGcd(0, 0, n, i, x);
	}
	
	Node query(int v, int tl, int tr, int l, int r)
	{
		if (l <= tl && tr <= r)
			return t[v];
		if (r <= tl || tr <= l)
			return {INF, -INF, 0};
		int tm = (tl + tr) / 2;
		auto r1 = query(v * 2 + 1, tl, tm, l, r);
		auto r2 = query(v * 2 + 2, tm, tr, l, r);
		return {min(r1.mn, r2.mn), max(r1.mx, r2.mx), gcd(r1.gcd, r2.gcd)};
	}
	Node query(int l, int r)
	{
		return query(0, 0, n, l, r);
	}
};

int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n, q;
	cin >> n >> q;
	map<int, set<int>> pos;
	Segtree st;
	Segtree ps;
	st.init(n);
	ps.init(n);
	VI a(n);
	VI nx(n);
	FOR (i, 0, n)
	{
		cin >> a[i];
		pos[a[i]].insert(i);
	}
	for (auto [val, s] : pos)
	{
		auto it = s.begin();
		while (it != s.end())
		{
			auto it2 = next(it);
			nx[*it] = (it2 == s.end() ? n : *it2);
			it = it2;
		}
	}
	FOR (i, 0, n)
	{
		ps.updVal(i, nx[i]);
		st.updVal(i, a[i]);
		if (i)
			st.updGcd(i, abs(a[i] - a[i - 1]));
	}
	FOR (i, 0, q)
	{
		int t;
		cin >> t;
		if (t == 1)
		{
			int x, y;
			cin >> x >> y;
			x--;
			auto& s = pos[a[x]];
			auto it = s.lower_bound(x);
			if (it != s.begin())
			{
				nx[*prev(it)] = nx[x];
				ps.updVal(*prev(it), nx[x]);
			}
			s.erase(it);
			s = pos[y];
			s.insert(x);
			it = s.lower_bound(x);
			nx[x] = next(it) == s.end() ? n : *next(it);
			ps.updVal(x, nx[x]);
			
			if (it != s.begin())
			{
				nx[*prev(it)] = x;
				ps.updVal(*prev(it), x);
			}
			
			a[x] = y;
			st.updVal(x, y);
			if (x)
				st.updGcd(x - 1, abs(a[x] - a[x - 1]));
			st.updGcd(x, abs(a[x + 1] - a[x]));
			
		}
		else
		{
			int l, r;
			cin >> l >> r;
			l--;
			int sz = r - l;
			auto res = st.query(l, r);
			cerr << res.mn << ' ' << res.mx << ' ' << st.query(l, r - 1).gcd << ' ' << ps.query(l, r).mn << '\n';
			if (res.mn == res.mx || sz < 3)
			{
				cout << "YES\n";
				continue;
			}
			if ((res.mx - res.mn) % (sz - 1) != 0)
			{
				cout << "NO\n";
				continue;
			}
			int mod = (res.mx - res.mn) / (sz - 1);
			int g = st.query(l, r - 1).gcd;
			if (g % mod != 0)
			{
				cout << "NO\n";
				continue;				
			}
			if (ps.query(l, r).mn < r)
			{
				cout << "NO\n";
				continue;
			}
			cout << "YES\n";
		}
	}
	
	
	return 0;
}
vgbnm,.qwmberliquefbwl;euifgbliawrgbkljwebf

Details

answer.code:202:1: error: ‘vgbnm’ does not name a type
  202 | vgbnm,.qwmberliquefbwl;euifgbliawrgbkljwebf
      | ^~~~~
answer.code:202:24: error: ‘euifgbliawrgbkljwebf’ does not name a type
  202 | vgbnm,.qwmberliquefbwl;euifgbliawrgbkljwebf
      |                        ^~~~~~~~~~~~~~~~~~~~