QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#131304#4940. Token Distancearnold518#WA 122ms23984kbC++172.9kb2023-07-26 21:24:442023-07-26 21:24:48

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-07-26 21:24:48]
  • 评测
  • 测评结果:WA
  • 用时:122ms
  • 内存:23984kb
  • [2023-07-26 21:24:44]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 1e5;
const int INF = 1e9+7;

int N, Q, A[MAXN+10];

struct SEG
{
	pii tree[MAXN*4+10];

	void update(int node, int tl, int tr, int p, int q)
	{
		if(tl==tr)
		{
			tree[node]={q, q};
			return;
		}
		int mid=tl+tr>>1;
		if(p<=mid) update(node*2, tl, mid, p, q);
		else update(node*2+1, mid+1, tr, p, q);
		tree[node].first=max(tree[node*2].first, tree[node*2+1].first);
		tree[node].second=min(tree[node*2].second, tree[node*2+1].second);
	}

	pii query(int node, int tl, int tr, int l, int r)
	{
		if(l<=tl && tr<=r) return tree[node];
		if(r<tl || tr<l) return {-INF, INF};
		int mid=tl+tr>>1;
		pii p=query(node*2, tl, mid, l, r), q=query(node*2+1, mid+1, tr, l, r);
		return {max(p.first,q.first), min(p.second,q.second)};
	}
}seg, seg3;

struct SEG2
{
	int tree[MAXN*4+10];
	void update(int node, int tl, int tr, int p, int q)
	{
		if(q>tr || q<tl) return;
		if(tl==tr)
		{
			tree[node]=q;
			return;
		}
		int mid=tl+tr>>1;
		if(p<=mid) update(node*2, tl, mid, p, q);
		else update(node*2+1, mid+1, tr, p, q);
		tree[node]=__gcd(tree[node*2], tree[node*2+1]);
	}
	int query(int node, int tl, int tr, int l, int r)
	{
		if(l<=tl && tr<=r) return tree[node];
		if(r<tl || tr<l) return 0;
		int mid=tl+tr>>1;
		return __gcd(query(node*2, tl, mid, l, r), query(node*2+1, mid+1, tr, l, r));
	}
}seg2;

map<int, set<int>> M;

int main()
{
	scanf("%d%d", &N, &Q);
	for(int i=1; i<=N; i++) scanf("%d", &A[i]);

	for(int i=1; i<=N; i++)
	{
		M[A[i]].insert(i);
		seg.update(1, 1, N, i, A[i]);
		seg2.update(1, 1, N, i, A[i]-A[i-1]);
		seg3.update(1, 1, N, i, INF);
	}

	for(auto &[v, S] : M)
	{
		if(S.size()==1) continue;
		for(auto jt=S.begin(); next(jt)!=S.end(); jt++)
		{
			seg3.update(1, 1, N, *jt, *next(jt));
		}
	}

	while(Q--)
	{
		int t, l, r;
		scanf("%d%d%d", &t, &l, &r);
		if(t==1)
		{
			auto it=M[A[l]].find(l);
			seg3.update(1, 1, N, l, INF);
			if(it!=M[A[l]].begin())
			{
				if(next(it)==M[A[l]].end()) seg3.update(1, 1, N, *prev(it), INF);
				else seg3.update(1, 1, N, *prev(it), *next(it));
			}
			M[A[l]].erase(it);

			A[l]=r;
			seg.update(1, 1, N, l, r);
			seg2.update(1, 1, N, l, A[l]-A[l-1]);
			seg2.update(1, 1, N, l+1, A[l+1]-A[l]);

			M[A[l]].insert(l);
			it=M[A[l]].find(l);

			if(next(it)!=M[A[l]].end()) seg3.update(1, 1, N, l, *next(it));

			if(it!=M[A[l]].begin())
			{
				seg3.update(1, 1, N, *prev(it), l);
			}
		}
		else
		{
			pii t=seg.query(1, 1, N, l, r);
			if(t.first==t.second) printf("YES\n");
			else if((t.first-t.second)%(r-l)) printf("NO\n");
			else
			{
				int val=(t.first-t.second)/(r-l);
				if(seg2.query(1, 1, N, l+1, r)%val!=0) printf("NO\n");
				else
				{
					if(seg3.query(1, 1, N, l, r).second>r) printf("YES\n");
					else printf("NO\n");
				}
			}
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7728kb

input:

5 7
1 1 1 10 1
2 1 3
2 1 5
1 5 4
1 3 7
2 2 4
2 2 5
2 4 5

output:

YES
NO
NO
YES
YES

result:

ok 5 lines

Test #2:

score: 0
Accepted
time: 1ms
memory: 5752kb

input:

2 1
0 1000000000
2 1 2

output:

YES

result:

ok single line: 'YES'

Test #3:

score: 0
Accepted
time: 35ms
memory: 21796kb

input:

81473 13549
972586683 972586964 972587245 972587526 972587807 972588088 972588369 972588650 972588931 972589212 972589493 972589774 972590055 972590336 972590617 972590898 972591179 972591460 972591741 972592022 972592303 972592584 972592865 972593146 972593427 972593708 972593989 972594270 97259455...

output:

YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
YES
YES
YES
YES
Y...

result:

ok 4517 lines

Test #4:

score: 0
Accepted
time: 79ms
memory: 21704kb

input:

81473 13549
994993061 993089286 973546017 983608065 980300695 994305454 992559601 974765838 987574661 988923180 987601637 991357764 981678157 994388630 987066613 976087381 985770922 989296067 975698758 977548300 992236732 978102432 983875296 979745439 977111907 992622264 988921213 987697458 99145442...

output:

NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES
NO
YES...

result:

ok 4517 lines

Test #5:

score: 0
Accepted
time: 43ms
memory: 21636kb

input:

81473 13549
972586964 972586683 972587526 972587245 972588088 972587807 972588650 972588369 972589212 972588931 972589774 972589493 972590336 972590055 972590898 972590617 972591460 972591179 972592022 972591741 972592584 972592303 972593146 972592865 972593708 972593427 972594270 972593989 97259483...

output:

NO
NO
YES
YES
NO
NO
YES
NO
NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
YES
NO
NO
NO
YES
NO
NO
NO
YES
NO
YES
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
NO
YES
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
YES...

result:

ok 13549 lines

Test #6:

score: 0
Accepted
time: 43ms
memory: 13976kb

input:

81473 13549
136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 13635105...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
...

result:

ok 13549 lines

Test #7:

score: 0
Accepted
time: 51ms
memory: 14888kb

input:

81473 13549
136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 136351051 13635105...

output:

YES
NO
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
YES
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO
NO
NO
YES
NO
NO
NO
NO
YES
NO
NO
NO
NO
NO...

result:

ok 6727 lines

Test #8:

score: 0
Accepted
time: 122ms
memory: 23920kb

input:

96888 91338
0 10321 20642 30963 41284 51605 61926 72247 82568 92889 103210 113531 123852 134173 144494 154815 165136 175457 185778 196099 206420 216741 227062 237383 247704 258025 268346 278667 288988 299309 309630 319951 330272 340593 350914 361235 371556 381877 392198 402519 412840 423161 433482 4...

output:

YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
...

result:

ok 91338 lines

Test #9:

score: -100
Wrong Answer
time: 105ms
memory: 23984kb

input:

96888 91338
0 10321 20642 30963 41284 51605 61926 72247 82568 92889 103210 113531 123852 134173 144494 154815 165136 175457 185778 196099 206420 216741 227062 237383 247704 258025 268346 278667 288988 299309 309630 319951 330272 340593 350914 361235 371556 381877 392198 402519 412840 423161 433482 4...

output:

NO
YES
YES
NO
NO
YES
YES
NO
YES
YES
YES
YES
YES
NO
YES
NO
YES
NO
NO
NO
YES
YES
YES
NO
NO
YES
YES
NO
YES
NO
YES
YES
NO
NO
YES
YES
NO
NO
NO
NO
YES
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
NO
YES
YES
NO
NO
YES
YES
YES
NO
NO
NO
NO
YES
NO
YES
YES
YES
YES
NO
YES
NO
YES
YES
NO
YES
NO
YES
YES
YES
YES
YES
YES
YE...

result:

wrong answer 16282nd lines differ - expected: 'NO', found: 'YES'