結果

問題 No.1439 Let's Compare!!!!
ユーザー 🍮かんプリン🍮かんプリン
提出日時 2021-03-28 15:44:34
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 307 ms / 2,000 ms
コード長 4,449 bytes
コンパイル時間 1,275 ms
コンパイル使用メモリ 117,404 KB
実行使用メモリ 6,032 KB
最終ジャッジ日時 2023-08-19 15:36:03
合計ジャッジ時間 5,639 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 1 ms
4,380 KB
testcase_07 AC 6 ms
4,380 KB
testcase_08 AC 11 ms
4,376 KB
testcase_09 AC 5 ms
4,384 KB
testcase_10 AC 307 ms
5,744 KB
testcase_11 AC 292 ms
5,988 KB
testcase_12 AC 288 ms
5,736 KB
testcase_13 AC 305 ms
6,032 KB
testcase_14 AC 302 ms
5,984 KB
testcase_15 AC 301 ms
5,952 KB
testcase_16 AC 292 ms
5,920 KB
testcase_17 AC 303 ms
5,968 KB
testcase_18 AC 295 ms
5,984 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <limits>
#include <list>
#include <numeric>
#include <queue>
#include <stack>
#include <utility>
#include <array>
#include <random>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <assert.h>
using namespace std;
typedef long long ll;
#define dump(x) // // cerr << #x << " = " << (x) << " [" << __LINE__ << ":" << __FUNCTION__ << "] " << endl;
// vector出力
template < typename T >
ostream& operator<<(ostream& os, vector< T >& v) {
    os << "{";
    for (int i = 0; i < (int)v.size(); i++) {
        os << v[i] << (i < v.size() - 1 ? ", " : "");
    }
    os << "}";
    return os;
}
// pair出力
template < typename T, typename U >
ostream& operator<<(ostream& os, const pair< T, U >& p) {
    return os << "(" << p.first << ", " << p.second << ")";
}
// map出力
template < typename T, typename U >
ostream& operator<<(ostream& os, const map< T, U >& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set 出力
template < typename T >
ostream& operator<<(ostream& os, const set< T >& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// multiset 出力
template < typename T >
ostream& operator<<(ostream& os, const multiset< T >& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
#pragma endregion

/////////////////////////////////////////

// 0-indexedとして使う
// 実装は1-indexed
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];
    }

    // [0,k)
    inline T sum(int k) const {
        T ret = 0;
        for (k; k > 0; k -= k & -k) ret += data[k];
        return (ret);
    }

    // [left,right)
    inline T sum(int left, int right) const {
        return sum(right) - sum(left);
    }

    // k番目にxを加算
    // 負の数も可
    inline void add(int k, T x) {
        for (++k; k < data.size(); k += k & -k) data[k] += x;
    }

    // [0,x]の和がk以上となる最小のx(0-indexed)
    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