結果

問題 No.1439 Let's Compare!!!!
ユーザー milanis48663220milanis48663220
提出日時 2021-03-26 21:36:54
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 357 ms / 2,000 ms
コード長 2,775 bytes
コンパイル時間 894 ms
コンパイル使用メモリ 98,824 KB
実行使用メモリ 5,772 KB
最終ジャッジ日時 2023-08-19 15:12:18
合計ジャッジ時間 5,308 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,384 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,376 KB
testcase_06 AC 1 ms
4,376 KB
testcase_07 AC 7 ms
4,376 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 5 ms
4,384 KB
testcase_10 AC 357 ms
5,676 KB
testcase_11 AC 344 ms
5,772 KB
testcase_12 AC 325 ms
5,520 KB
testcase_13 AC 335 ms
5,764 KB
testcase_14 AC 352 ms
5,704 KB
testcase_15 AC 337 ms
5,696 KB
testcase_16 AC 335 ms
5,704 KB
testcase_17 AC 332 ms
5,704 KB
testcase_18 AC 328 ms
5,700 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;


template <typename T>
struct segtree{
    int n;
    T UNIT;
    vector<T> dat;
    T (*calc)(T, T);

    segtree(int n_, T unit, T (*_calc)(T, T)){
        UNIT = unit;
        calc = _calc;
        n = 1;
        while(n < n_) n *= 2;
        dat = vector<T>(2*n);
        for(int i = 0; i < 2*n; i++) dat[i] = UNIT;
    }

    void insert(int k, T a){
        dat[k+n-1] = a;
    }
    void update_all(){
        for(int i = n-2; i >= 0; i--){
            dat[i] = calc(dat[i*2+1], dat[i*2+2]);
        }
    }
    //k番目の値(0-indexed)をaに変更
    void update(int k, T a){
        k += n-1;
        dat[k] = a;
        while(k > 0){
            k = (k-1)/2;
            dat[k] = calc(dat[k*2+1], dat[k*2+2]);
        }
    }

    //[a, b)
    //区間[a, b]へのクエリに対してはquery(a, b+1)と呼ぶ
    T query(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;
        if(r <= a || b <= l) return UNIT;
        if(a <= l && r <= b) return dat[k];
        else{
            T vl = query(a, b, k*2+1, l, (l+r)/2);
            T vr = query(a, b, k*2+2, (l+r)/2, r);
            return calc(vl, vr);
        }
    }
};

int unit = 0;

int calc(int a, int b){
    if(a == unit) return b;
    if(b == unit) return a;
    return a;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n;
    string s, t;
    cin >> n >> s >> t;
    segtree<int> sgt(n, unit, calc);
    auto update = [&](int i){
        if(s[i] == t[i]){
            sgt.update(i, unit);
        }else if(s[i] > t[i]){
            sgt.update(i, 1);
        }else{
            sgt.update(i, -1);
        }
    };
    for(int i = 0; i < n; i++){
        update(i);
    }
    int q; cin >> q;
    while(q--){
        char c;
        int x, y; cin >> c >> x >> y; x--;
        if(c == 'S') s[x] = '0'+y;
        else t[x] = '0'+y;
        update(x);
        int m = sgt.query(0, n);
        if(m == 0) cout << "=" << endl;
        else if(m == -1) cout << "<" << endl;
        else cout << ">" << endl;
        // cout << s << ' ' << t << endl;
        // for(int i = 0; i < n; i++) cout << sgt.query(i, i+1) << ' ';
        // cout << endl;
    }
}
0