結果
| 問題 |
No.1439 Let's Compare!!!!
|
| コンテスト | |
| ユーザー |
🍮かんプリン
|
| 提出日時 | 2021-03-28 15:44:34 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 305 ms / 2,000 ms |
| コード長 | 4,449 bytes |
| コンパイル時間 | 1,300 ms |
| コンパイル使用メモリ | 118,060 KB |
| 実行使用メモリ | 6,272 KB |
| 最終ジャッジ日時 | 2024-11-29 09:08:14 |
| 合計ジャッジ時間 | 5,390 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 17 |
ソースコード
#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;
}
/////////////////////////////////////////
🍮かんプリン