1641C - Anonymity Is Important - CodeForces Solution


binary search brute force data structures dsu greedy sortings *2200

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
int n,m,o,x,l,r,A,b[N];
set<int>s;
void C(int i,int x)
{
	for(;i<N;i+=i&-i)
		b[i]=max(b[i],x);
}
int Q(int i)
{
	A=0;
	for(;i;i-=i&-i)
		A=max(A,b[i]);
	return A;
}
int main()
{
	cin>>n>>m;
	for(int i=0;i<=n+1;i++)
		s.insert(i);
	while(m--&&cin>>o)
		if(o&&cin>>x)
			cout<<(s.count(x)?(Q(*s.upper_bound(x)-1)>*--s.lower_bound(x)?"YES":"N/A"):"NO")<<'\n';
		else
		{
			cin>>l>>r>>o;
			if (o)
				C(r,l);
			else
				while((x=*s.lower_bound(l))<=r)
					s.erase(x);
		}
}


Comments

Submit
0 Comments
More Questions

Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character
1441. Build an Array With Stack Operations