/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Wrong Answer 1ms 324.0 KiB
#3 Accepted 534ms 2.824 MiB
#4 Wrong Answer 467ms 5.395 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 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=take_inputs_1(n+1);
	
	ll k;cin>>k;
	
	set<ll> st;
	
	for(int i=1;i<=n-1;i++)
	{
		if(v[i]>v[i+1])
		{
			st.insert(i);
		}
	}
	
	
	while(k--)
	{
		ll x;cin>>x;
		
		if(x==1)
		{
			ll index;;cin>>index;
			ll val;cin>>val;
			
			if(st.find(index)!=st.end())
			{
				st.erase(index);
			}
			
			v[index]=val;
			
			if(n>1 && index!=1 && index!=n)
			{
				if(v[index-1]>v[index])
				{
					st.insert(index);
				}
				else
				{
					st.erase(index-1);
				}
				if(v[index]>v[index+1])
				{
					st.insert(index);
				}
				else
				{
					st.erase(index+1);
				}
			}
			
			else if(index==1)
			{
				
				if(n>1 && v[index]>v[index+1])
				{
					st.insert(index);
				}
				else 
				{
					st.erase(index+1);
				}
			}
			else if(index==n)
			{
				if(n>1 && v[index-1]>v[index])
				{
					st.insert(index);
				}
				else
				{
					st.insert(index-1);
				}
			}
			
		}
		else
		{
			ll l,r;cin>>l>>r;
			
			auto it= st.lower_bound(l);
			
			if(it==st.end())
			{
				show("YES");
			}
			else if(l==r)
			{
				show("YES");
			}
			else if(n==1)
			{
				show("YES");
			}
			
			else
			{
				int f=0;
				
				
				if(r<*it)
				{
					f=0;
				}
				else if(*it==n)
				{
					ll temp=*it;
					ll temp1=v[temp];
					temp--;
					ll temp2=v[temp];
					
					if(temp2>temp1)
					{
						f=1;
					}
					else
					{
						st.erase(it);
					}
				}
				else if(*it==1)
				{
					ll temp=*it;
					ll temp1=v[temp];
					temp++;
					ll temp2=v[temp];
					
					if(temp1>temp2)
					{
						f=1;
					}
					else
					{
						st.erase(it);
					}
				}
				else
				{
					 ll tmp=*it;
					 
					 ll temp1=v[tmp];
					 tmp--;
					 ll temp2=v[tmp];
					 tmp++;
					 tmp++;
					 ll temp3=v[tmp];
					 tmp--;
					 if(tmp==l)
					 {
					 	if(temp1>temp3)
					 	{
					 		f=1;
					 	}
					 }
					 else if(tmp==r)
					 {
					 	if(temp2>temp1)
					 	{
					 		f=1;
					 	}
					 }
					 else
					 {
					 	
					 	
					 	if(temp2<=temp1 && temp3>=temp1)
					 	{
					 		st.erase(it);
					 	}
					 	else if(temp2>temp1)
					 	{
					 		f=1;
					 	}
					 	else if(temp1>temp3)
					 	{
					 		f=1;
					 	}
					 }
				}
				
				if(f)
				{
					show("NO");
				}
				else
				{
					show("YES");
				}
				
			}
			
		}
	}
}

Information

Submit By
Type
Submission
Problem
P1085 Sorted or !Sorted
Language
C++20 (G++ 13.2.0)
Submit At
2024-08-20 09:05:10
Judged At
2024-11-11 03:06:52
Judged By
Score
20
Total Time
534ms
Peak Memory
5.395 MiB