結果

問題 No.2080 Simple Nim Query
ユーザー eQe
提出日時 2025-05-18 02:46:10
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 7,163 bytes
コンパイル時間 5,919 ms
コンパイル使用メモリ 335,188 KB
実行使用メモリ 16,180 KB
最終ジャッジ日時 2025-05-18 02:46:20
合計ジャッジ時間 8,341 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 3 WA * 5
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
namespace my{
#define LL(...) ll __VA_ARGS__;lin(__VA_ARGS__)
#define RDVL(T,n,...) vec<T>__VA_ARGS__;resizes({n},__VA_ARGS__);lin(__VA_ARGS__)
#define VL(n,...) RDVL(ll,n,__VA_ARGS__)
#define jo(a,b) a##b
#define FO_IMPL(n,c) for(ll jo(_i,c)=n;jo(_i,c)-->0;)
#define FO(n) FO_IMPL(n,__COUNTER__)
#define FOR(i,...) for(auto[i,i##stop,i##step]=range(0,__VA_ARGS__);i<i##stop;i+=i##step)
#define fo(i,...) FO##__VA_OPT__(R)(i __VA_OPT__(,__VA_ARGS__))
#define fe(a,e,...) for(auto&&__VA_OPT__([)e __VA_OPT__(,__VA_ARGS__]):a)
#define maybe(p,c) (p?c:remove_cvref_t<decltype(c)>{})
#define base_operator(op,type) auto operator op(const type&v)const{auto copy=*this;return copy op##=v;}
#define entry void solve();void solve2();}int main(){my::io();my::solve();}namespace my{
void io(){cin.tie(nullptr)->sync_with_stdio(0);cout<<fixed<<setprecision(15);}
using ll=long long;
constexpr auto range(ll s,ll b){ll a=0;if(s)swap(a,b);return array{a-s,b,1-s*2};}
constexpr auto range(ll s,ll a,ll b,ll c=1){return array{a-s,b,(1-s*2)*c};}
const string newline{char(10)};
const string space{char(32)};
constexpr auto even(auto x){return~x&1;}
constexpr ll size10(auto x){x|=1;ll r=0;while(x>0)x/=10,++r;return r;}
template<class T>constexpr ll maxsize10(){return size10(numeric_limits<T>::max());}
auto min(auto...a){return min(initializer_list<common_type_t<decltype(a)...>>{a...});}

template<class A,class B>struct pair{
  A a;B b;
  pair()=default;
  pair(A a,B b):a(a),b(b){}
  pair(const std::pair<A,B>&p):a(p.first),b(p.second){}
  auto operator<=>(const pair&)const=default;
  pair operator+(const pair&p)const{return{a+p.a,b+p.b};}
  friend istream&operator>>(istream&i,pair&p){return i>>p.a>>p.b;}
  friend ostream&operator<<(ostream&o,const pair&p){return o<<p.a<<space<<p.b;}
};

auto&rev(auto&a){ranges::reverse(a);return a;}

template<class T,class F>ostream&operator<<(ostream&o,const multiset<T,F>&s){fe(s,e)o<<e<<maybe(&e!=&*s.rbegin(),space);return o;}

template<class T,class F=less<>>struct multiset:std::multiset<T,F>{
  multiset(const initializer_list<T>&a={}){fe(a,e)this->emplace(e);}
  multiset(const vector<T>&a){fe(a,e)this->emplace(e);}
  ll size()const{return std::multiset<T,F>::size();}
};

template<class T,class F=less<>>struct set:multiset<T,F>{
  set(const initializer_list<T>&a={}){fe(a,e)this->emplace(e);}
  set(const vector<T>&a){fe(a,e)this->emplace(e);}
  template<class...A>auto emplace(A&&...a){
    T x(std::forward<A>(a)...);
    if(auto p=this->find(x);p!=this->end())return pair{p,0};
    return pair{multiset<T,F>::emplace(x),1};
  }
};

template<class...A>using pack_back_t=tuple_element_t<sizeof...(A)-1,tuple<A...>>;

template<class V>concept vectorial=is_base_of_v<vector<typename remove_cvref_t<V>::value_type>,remove_cvref_t<V>>;
template<class V>constexpr int rank(){if constexpr(vectorial<V>)return rank<typename V::value_type>()+1;else return 0;}
template<class T>struct core_t_helper{using core_t=T;};
template<vectorial V>struct core_t_helper<V>{using core_t=typename core_t_helper<typename V::value_type>::core_t;};
template<class T>using core_t=core_t_helper<T>::core_t;
template<class V>istream&operator>>(istream&i,vector<V>&v){fe(v,e)i>>e;return i;}
template<class T>ostream&operator<<(ostream&o,const vector<T>&v){ll n=v.size();fo(i,n)o<<v[i]<<maybe(i<n-1,space);return o;}
template<vectorial V>ostream&operator<<(ostream&o,const vector<V>&v){ll n=v.size();fo(i,n)o<<v[i]<<maybe(i<n-1,newline);return o;}

template<class V>struct vec;
template<int rank,class T>struct hvec_helper{using type=vec<typename hvec_helper<rank-1,T>::type>;};
template<class T>struct hvec_helper<0,T>{using type=T;};
template<int rank,class T>using hvec=typename hvec_helper<rank,T>::type;

template<class V>struct vec:vector<V>{
  static constexpr int R=rank<vec<V>>();
  using C=core_t<V>;
  using vector<V>::vector;
  vec(const vector<V>&v){vector<V>::operator=(v);}
  vec(const auto&...a)requires(sizeof...(a)>=3){resizes(a...);}
  void resizes(const auto&...a){*this=make(a...);}
  static auto make(ll n,const auto&...a){
    if constexpr(sizeof...(a)==1)return vec<C>(n,array{a...}[0]);
    else return vec<decltype(make(a...))>(n,make(a...));
  }

  vec&operator^=(const vec&u){this->insert(this->end(),u.begin(),u.end());return*this;}
  vec&operator+=(const vec&u){vec&v=*this;assert(v.size()==u.size());fo(i,v.size())v[i]+=u[i];return v;}
  vec&operator-=(const vec&u){vec&v=*this;assert(v.size()==u.size());fo(i,v.size())v[i]-=u[i];return v;}
  vec&operator+=(const C&c){fe(*this,e)e+=c;return*this;}
  vec&operator*=(const C&c){fe(*this,e)e*=c;return*this;}
  base_operator(^,vec)
  base_operator(+,vec)
  base_operator(-,vec)
  base_operator(+,C);
  base_operator(*,C);

  vec&operator++(){fe(*this,e)++e;return*this;}
  vec&operator--(){fe(*this,e)--e;return*this;}

  ll size()const{return vector<V>::size();}

  auto scan(const auto&f)const{
    pair<C,bool>r{};
    fe(*this,e)if constexpr(!vectorial<V>)r.b?f(r.a,e),r:r={e,1};else if(auto s=e.scan(f);s.b)r.b?f(r.a,s.a),r:r=s;
    return r;
  }
  auto prod()const{return scan([](auto&a,const auto&b){a*=b;}).a;}
  auto min()const{return scan([](auto&a,auto b){if(b<a)a=b;}).a;}

  auto rev()const{vec v=*this;ranges::reverse(v);return v;}
  auto rev(ll l,ll r)const{vec v=*this;ranges::reverse(v.begin()+l,v.begin()+r);return v;}
};
template<class...A>requires(sizeof...(A)>=2)vec(const A&...a)->vec<hvec<sizeof...(A)-2,pack_back_t<A...>>>;
vec(ll)->vec<ll>;

template<class...A>void resizes(const array<ll,common_type_t<A...>::R+1>&s,A&...a){(apply([&](const auto&...b){a.resizes(b...); },s),...);}

template<bool is_negative=false>struct infinity{
  template<integral T>static constexpr T ones(size_t n){return n?ones<T>(n-1)*10+1:0;}
  template<integral T>constexpr operator T()const{static constexpr T v=ones<T>(maxsize10<T>())*(1-is_negative*2);return v;}
  template<floating_point T>constexpr operator T()const{return static_cast<ll>(*this);}
  template<class T>constexpr bool operator==(const T&x)const{return static_cast<T>(*this)==x;}
  constexpr auto operator-()const{return infinity<!is_negative>();}
  template<class A,class B>constexpr operator pair<A,B>()const{return pair<A,B>{*this,*this};}
};
constexpr infinity oo;

void lin(auto&...a){(cin>>...>>a);}

void pp(const auto&...a){ll n=sizeof...(a);((cout<<a<<maybe(--n>0,space)),...);cout<<newline;}

namespace sgt{
template<class T,auto x>T e(){return x;}
template<class T>T e(){return T{};}
template<class T>T min(T a,T b){return a<b?a:b;}

template<class T>struct segmin:atcoder::segtree<T,min<T>,e<T,oo>>{
  using atcoder::segtree<T,min<T>,e<T,oo>>::segtree;
};
}

entry
void solve(){
  LL(N,Q);
  VL(N,a);
  rev(a);
  a[N-1]=2; // 先頭の値は正であれば意味ない

  sgt::segmin<pair<ll,ll>>s(N);
  fo(i,N)s.set(i,pair{a[i],~i});

  fo(Q){
    LL(t,x,y);--t;

    if(t==0){
      x=N-x;
      if(x<N-1)a[x]=y;
    }else{
      swap(x,y);
      x=N-x;
      y=N+1-y;

      if(y-x==1)pp("F");
      else{
        auto[v,k]=s.prod(x,y);
        if(v>1)pp("F");
        else pp("SF"[even(~k-x+1)]);
      }
    }
  }
}}
0