結果

問題 No.1439 Let's Compare!!!!
ユーザー umezoumezo
提出日時 2021-03-26 22:18:48
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 376 ms / 2,000 ms
コード長 3,232 bytes
コンパイル時間 2,377 ms
コンパイル使用メモリ 202,984 KB
実行使用メモリ 7,720 KB
最終ジャッジ日時 2023-08-19 15:23:10
合計ジャッジ時間 6,814 ms
ジャッジサーバーID
(参考情報)
judge12 / judge10
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 8 ms
4,380 KB
testcase_08 AC 13 ms
4,376 KB
testcase_09 AC 6 ms
4,376 KB
testcase_10 AC 366 ms
7,196 KB
testcase_11 AC 368 ms
7,396 KB
testcase_12 AC 362 ms
7,256 KB
testcase_13 AC 371 ms
7,592 KB
testcase_14 AC 365 ms
7,464 KB
testcase_15 AC 375 ms
7,588 KB
testcase_16 AC 373 ms
7,720 KB
testcase_17 AC 376 ms
7,656 KB
testcase_18 AC 339 ms
7,592 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
 
#include<bits/stdc++.h>
using namespace std;

const int INF=1e9;

template <typename X>
struct SegTree{
  using FX=function<X(X,X)>;// X•X -> X となる関数の型
  int n;
  FX fx;
  const X ex;
  vector<X> dat;
  SegTree(int n_,FX fx_,X ex_) : n(),fx(fx_),ex(ex_),dat(n_*4,ex_){
    int x=1;
    while (n_>x){
      x *= 2;
    }
    n=x;
  }
  void set(int i,X x){ dat[i+n-1]=x;}
  void build(){
    for (int k=n-2;k>=0;k--) dat[k]=fx(dat[2*k+1],dat[2*k+2]);
  }
  void update(int i,X x){
    i += n-1;
    dat[i]=x;
    while(i>0){
      i=(i-1)/2; // parent
      dat[i]=fx(dat[i*2+1],dat[i*2+2]);
    }
  }
  X get(int i){return dat[i+n-1];}
  X all(){return dat[0];}
  X query(int a,int b){ return query_sub(a,b,0,0,n);}
  X query_sub(int a,int b,int k,int l,int r){
    if(r<=a || b<=l){
      return ex;
    }else if(a<=l && r<=b){
      return dat[k];
    }else{
      X vl=query_sub(a,b,k*2+1,l,(l+r)/2);
      X vr=query_sub(a,b,k*2+2,(l+r)/2,r);
      return fx(vl,vr);
    }
  }
  int find_rightest(int a,int b,X x){ return find_rightest_sub(a,b,x,0,0,n);}
  int find_leftest(int a,int b,X x){ return find_leftest_sub(a,b,x,0,0,n);}
  int find_rightest_sub(int a,int b,X x,int k,int l,int r){
    if(dat[k]>x || r<=a || b<=l){  // 自分の値がxより大きい or [a,b)が[l,r)の範囲外ならreturn a-1
      return a-1;
    }else if (k>=n-1){  // 自分が葉ならその位置をreturn
      return (k-(n-1));
    }else{
      int vr=find_rightest_sub(a,b,x,2*k+2,(l+r)/2,r);
      if(vr!=a-1){  // 右の部分木を見て a-1 以外ならreturn
        return vr;
      }else{  // 左の部分木を見て値をreturn
        return find_rightest_sub(a,b,x,2*k+1,l,(l+r)/2);
      }
    }
  }
  int find_leftest_sub(int a,int b,X x,int k,int l,int r){
    if(dat[k]>x || r<=a || b<=l){  // 自分の値がxより大きい or [a,b)が[l,r)の範囲外ならreturn b
      return b;
    }else if (k>=n-1){  // 自分が葉ならその位置をreturn
      return (k-(n-1));
    }else{
      int vl=find_leftest_sub(a,b,x,2*k+1,l,(l+r)/2);
      if(vl != b){  // 左の部分木を見て b 以外ならreturn
        return vl;
      }else{  // 右の部分木を見て値をreturn
        return find_leftest_sub(a,b,x,2*k+2,(l+r)/2,r);
      }
    }
  }
};

int main(){
  int n;
  string s,t;
  cin>>n>>s>>t;
  int q;
  cin>>q;
  
  using X=int;
  auto fx=[](X x1,X x2)->X{ return min(x1,x2);};
  X ex=INF;
  SegTree<X> seg(n+2,fx,ex);
  
  rep(i,n+2) seg.set(i,INF);
  
  vector<int> A(n);
  rep(i,n){
    if(s[i]>t[i]){
      A[i]=1;
      seg.set(i,i);
    }
    else if(s[i]<t[i]){
      A[i]=-1;
      seg.set(i,i);
    }
  }
  seg.build();
  
  while(q--){
    char c,y;
    int x;
    cin>>c>>x>>y;
    x--;
    
    if(c=='S') s[x]=y;
    else t[x]=y;
    
    if(s[x]>t[x]){
      A[x]=1;
      seg.update(x,x);
    }
    else if(s[x]<t[x]){
      A[x]=-1;
      seg.update(x,x);
    }
    else{
      A[x]=0;
      seg.update(x,INF);
    }
   
    int a=seg.all();
    if(a==INF) cout<<'='<<endl;
    else if(A[a]==1) cout<<'>'<<endl;
    else if(A[a]==-1) cout<<'<'<<endl;
  }
  
  return 0;
}
0