/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 3ms 516.0 KiB
#2 Accepted 3ms 496.0 KiB
#3 Accepted 646ms 2.82 MiB
#4 Accepted 684ms 8.129 MiB
#5 Accepted 613ms 6.938 MiB
#6 Accepted 439ms 2.336 MiB
#7 Accepted 2ms 532.0 KiB
#8 Wrong Answer 2ms 504.0 KiB
#9 Accepted 985ms 8.48 MiB
#10 Wrong Answer 935ms 9.996 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;
			
			if(n==1)
			{
				continue;
			}
			else if(n==2)
			{
				if(ind==1)
				{
					if(v[ind]>v[ind+1])
					{
						st.insert(1);
						st.insert(2);
					}
					else
					{
						st.erase(1);
						st.erase(2);
					}
				}
				else
				{
					if(v[ind-1]<v[ind])
					{
						st.insert(1);
						st.insert(2);
					}
					else
					{
						st.erase(1);
						st.erase(2);
					}
				}
			}
			else
			{
				if(ind==1)
				{
					if(v[ind]>v[ind+1])
					{
						st.insert(ind);
						st.insert(ind+1);
					}
					else if(v[ind+1]<=v[ind+2])
					{
						st.erase(ind+1);
					}
				}
				else if(ind==n)
				{
					if(v[ind]<v[ind-1])
					{
						st.insert(ind);
						st.insert(ind-1);
					}
					else if(v[ind-1]>=v[ind-2])
					{
						st.erase(ind-1);
						
					}
				}
				else
				{
					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)
			{
				show("YES");
			}
			else if(index>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>=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 13:47:26
Judged At
2024-11-11 03:05:15
Judged By
Score
80
Total Time
985ms
Peak Memory
9.996 MiB