/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 2ms 532.0 KiB
#3 Accepted 551ms 2.777 MiB
#4 Accepted 510ms 8.133 MiB
#5 Accepted 438ms 6.801 MiB
#6 Accepted 348ms 2.293 MiB
#7 Accepted 1ms 320.0 KiB
#8 Accepted 1ms 364.0 KiB
#9 Accepted 764ms 8.367 MiB
#10 Accepted 689ms 9.977 MiB

Code

#include<bits/stdc++.h>
using namespace std;
using ll=long long int;

void fastio(){ios::sync_with_stdio(false);cin.tie(0);}

vector<ll> take_inputs_0(ll n){vector<ll> v(n);for(int i=0;i<n;i++){cin>>v[i];}return v;}
vector<ll> take_inputs_1(ll n){vector<ll> v(n);for(int i=1;i<n;i++){cin>>v[i];}return v;}

void show(auto x){ cout<<x<<"\n";}
void show1(auto v){ ll n=(signed)v.size();for(int i=0;i<n;i++){cout<<v[i]<<" ";}cout<<"\n";}
void show2(auto v){ ll n=(signed)v.size();for(int i=0;i<n;i++){	cout<<v[i]<<"\n";}}
void showset(set<ll> st){for(auto x:st){cout<<x<<" ";}cout<<"\n";}

void sort_it(auto &v){ sort(v.begin(),v.end());}
void reverse_it(auto &v){ reverse(v.begin(),v.end());}
void do_both(auto &v){ sort(v.begin(),v.end());reverse(v.begin(),v.end());}

auto find_max(auto v){ sort(v.begin(),v.end());reverse(v.begin(),v.end());return v[0];}
auto find_min(auto v){ sort(v.begin(),v.end());return v[0];}

vector<ll> bitRep64(ll n){vector<ll> v;int i=0;while(i<=63){if(n&(1LL<<i)){v.push_back(1);}else{v.push_back(0);}i++;}return v;}
vector<ll> bitRep32(ll n){vector<ll> v;int i=0;while(i<=31){if(n&(1LL<<i)){v.push_back(1);}else{v.push_back(0);}i++;}return v;}
vector<string> all_subset(ll n){vector<string> v;for(int i=0;i<(1<<n);i++){string st="";for(int j=0;j<n;j++){if(i&(1<<j)){st+="1";}else{st+="0";}}v.push_back(st);}return v;}

vector<ll> prefix_sum_0(vector<ll> v){ll n=(signed)v.size();for(int i=1;i<n;i++){v[i]=v[i-1]+v[i];}return v;}
vector<ll> prefix_sum_1(vector<ll> v){ll n=(signed)v.size();vector<ll> summ(n+1);for(int i=1;i<=n;i++){summ[i]=summ[i-1]+v[i-1];}return summ;}

///////////////////////////////////

int main()
{
	ll n;;cin>>n;
	
	vector<ll> v(n+1);
	
	for(int i=1;i<=n;i++)
	{
		cin>>v[i];
	}
	
	set<ll> st;
	
	for(int i=1;i<=n;i++)
	{
		if(i==1)
		{
			if(v[i]>v[i+1])
			{
				st.insert(i);
			}
		}
		else if(i==n)
		{
			if(v[i-1]>v[i])
			{
				st.insert(i);
			}
		}
		else
		{
			if(v[i-1]>v[i] || v[i]>v[i+1])
			{
				st.insert(i);
			}
		}
	}
	
	ll  q;cin>>q;
	
	while(q--)
	{
		ll x;cin>>x;
		
		if(x==1)
		{
			ll ind,val;cin>>ind>>val;
			
			st.erase(ind);
			
			v[ind]=val;
			
			{
				{
					ll a=max(1LL,ind-1);
					ll b=min(n,ind+1);
					
					for(ll i=a;i<=b;i++)
					{
						if(i==1)
						{
							if(v[i]<=v[i+1])
							{
								st.erase(i);
							}
							else
							{
								st.insert(i);
							}
						}
						else if(i==n)
						{
							if(v[i-1]<=v[i])
							{
								st.erase(i);
							}
							else
							{
								st.insert(i);
							}
						}
						else
						{
							if(v[i-1]<=v[i] && v[i]<=v[i+1])
							{
								st.erase(i);
							}
							else
							{
								st.insert(i);
							}
							
						}
					}
				}
			}
		}
		else
		{
			ll l,r;cin>>l>>r;
			
			auto it=st.lower_bound(l+1);
			
			ll index=*it;
			
			auto it1=st.find(l);
			auto it2=st.find(r);
			
			int check1=0;
			int check2=0;
			
			if(*it1!=l)
			{
				check1=1;
			}
			if(*it2!=r)
			{
				check2=1;
			}
			if(*it1==l)
			{
				if(v[l]<=v[l+1])
				{
					check1=1;
				}
			}
			if(*it2==r)
			{
				if(v[r-1]<=v[r])
				{
					check2=1;
				}
			}
			
			
			if(l==r)
			{
				show("YES");
			}
			else if(st.size()>0 && n==2)
			{
				show("NO");
			}
			else if(st.size()==0 && n==2)
			{
				show("YES");
			}
			else
			{
				if(check1 && check2 && (it==st.end() || *it>=r))
				{
					show("YES");
				}
				else
				{
					show("NO");
				}
			}
		}
		
	
	}
	
	return 0;
} 

Information

Submit By
Type
Submission
Problem
P1085 Sorted or !Sorted
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-25 15:13:20
Judged At
2024-10-03 13:12:59
Judged By
Score
100
Total Time
764ms
Peak Memory
9.977 MiB