結果

問題 No.1439 Let's Compare!!!!
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2021-03-28 15:47:48
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 270 ms / 2,000 ms
コード長 2,259 bytes
コンパイル時間 1,874 ms
コンパイル使用メモリ 170,140 KB
実行使用メモリ 6,216 KB
最終ジャッジ日時 2023-08-19 15:36:17
合計ジャッジ時間 5,717 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 2 ms
4,384 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 5 ms
4,376 KB
testcase_08 AC 9 ms
4,380 KB
testcase_09 AC 5 ms
4,380 KB
testcase_10 AC 270 ms
5,836 KB
testcase_11 AC 250 ms
6,180 KB
testcase_12 AC 252 ms
5,852 KB
testcase_13 AC 260 ms
6,216 KB
testcase_14 AC 266 ms
6,068 KB
testcase_15 AC 264 ms
6,012 KB
testcase_16 AC 264 ms
6,056 KB
testcase_17 AC 264 ms
6,004 KB
testcase_18 AC 256 ms
6,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

/**
 *   @FileName	a.cpp
 *   @Author	kanpurin
 *   @Created	2021.03.28 15:47:39
**/

#include "bits/stdc++.h" 
using namespace std; 
typedef long long ll;



template< typename T >
struct BinaryIndexedTree {
    std::vector< T > data;
    BinaryIndexedTree() {}
    BinaryIndexedTree(int sz) {
        data.assign(++sz, 0);
    }
    BinaryIndexedTree(vector< T > vec) {
        data.assign(vec.size()+1,0);
        copy(vec.begin(), vec.end(), data.begin()+1);
        for (int i = 1; i < data.size(); i++) data[i + (i & -i)] += data[i];
    }
    
    inline T sum(int k) const {
        T ret = 0;
        for (k; k > 0; k -= k & -k) ret += data[k];
        return (ret);
    }
    
    inline T sum(int left, int right) const {
        return sum(right) - sum(left);
    }
    
    
    inline void add(int k, T x) {
        for (++k; k < data.size(); k += k & -k) data[k] += x;
    }
    
    int lower_bound(T k) const {
        if (k <= 0) return 0;
        int res = 0;
        int N = 1; while (N < (int)data.size()) N *= 2;
        for (int i = N / 2; i > 0; i /= 2) {
            if (res + i < (int)data.size() && data[res + i] < k) {
                k -= data[res + i];
                res += i;
            }
        }
        return res;
    }
    
    friend std::ostream& operator<<(std::ostream &os, const BinaryIndexedTree &bit) {
        os << "[ ";
        for (int i = 0; i < bit.data.size() - 1; i++) {
            os << bit.sum(i, i + 1);
            if (i < bit.data.size() - 2) os << ", ";
        }
        os << " ]";
        return os;
    }
};
int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;cin >> n;
    string s,t;cin >> s >> t;
    int q;cin >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++) a[i] = s[i] != t[i];
    BinaryIndexedTree<int> bit(a);
    while(q--) {
        char c; int x,y; cin >> c >> x >> y;
        if (c == 'S') s[x-1] = char(y+'0');
        else t[x-1] = char(y+'0');
        if (s[x-1] == t[x-1]) bit.add(x-1,0-a[x-1]), a[x-1] = 0;
        else bit.add(x-1,1-a[x-1]), a[x-1] = 1;
        int k = bit.lower_bound(1);
        if (k == n) cout << '=' << endl;
        else if (s[k] < t[k]) cout << '<' << endl;
        else cout << '>' << endl;
    }
    return 0;
}
0