이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
ifstream fin("VNOICUP.INP");
ofstream fout("VNOICUP.OUT");
#define sz(a) (int)a.size()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
const ld PI = 3.14159265359;
using u128 = __uint128_t;
//const int x[4] = {1, -1, 0, 0};
//const int y[4] = {0, 0, 1, -1};
ll mod = 1e9 + 9;
const int mxn = 2e5 + 5, mxq = 2e5 + 5, sq = 400, mxv = 2e5 + 5;
//const int base = (1 << 18);
const int inf = 1e9, neg = -69420;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rr(ll l, ll r){
return(uniform_int_distribution<ll>(l, r)(rng));
}
map<ll, int>mp;
int to[mxn + 1];
ll st[4 * mxn + 1], lz[4 * mxn + 1];
ll pw[mxn + 1], pref[mxn + 1], n, q;
string s[3], t;
string conv(string a, string b){
string res = "";
for(int i = 0; i < sz(a); i++){
if(a[i] == b[i])res += a[i];
else if(a[i] == 'J'){
if(b[i] == 'O')res += 'I';
else res += 'O';
}else if(a[i] == 'O'){
if(b[i] == 'J')res += 'I';
else res += 'J';
}else{
if(b[i] == 'O')res += 'J';
else res += 'O';
}
}
return(res);
}
ll gethash(string s){
ll ans = 0;
for(int i = 0; i < sz(s); i++){
ans += pw[sz(s) - i - 1] * to[s[i]];
ans %= mod;
}
return(ans);
}
void build(int nd, int l, int r){
if(l == r){
st[nd] = to[t[l]];
return;
}
int mid = (l + r) >> 1;
build(nd << 1, l, mid); build(nd << 1 | 1, mid + 1, r);
st[nd] = (st[nd << 1] * pw[r - mid] + st[nd << 1 | 1]) % mod;
//cout << l << " " << r << " " << st[nd] << "\n";
}
void push(int nd, int l, int mid, int r){
if(lz[nd] == -1)return;
ll x = lz[nd];
lz[nd << 1] = lz[nd]; lz[nd << 1 | 1] = lz[nd];
st[nd << 1] = (pref[mid - l] * x) % mod;
st[nd << 1 | 1] = (pref[r - (mid + 1)] * x) % mod;
lz[nd] = -1;
return;
}
void upd(int nd, int l, int r, int ql, int qr, int x){
if(ql > r || qr < l)return;
if(ql <= l && qr >= r){
lz[nd] = x;
st[nd] = (pref[r - l] * x) % mod;
return;
}
int mid = (l + r) >> 1;
push(nd, l, mid, r);
upd(nd << 1, l, mid, ql, qr, x); upd(nd << 1 | 1, mid + 1, r, ql, qr, x);
st[nd] = (st[nd << 1] * pw[r - mid] + st[nd << 1 | 1]) % mod;
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n;
mod = rr(1e8, 1e9);
pw[0] = 1;
for(int i = 1; i <= n; i++){
pw[i] = (pw[i - 1] * 3) % mod;
}
pref[0] = pw[0];
for(int i = 1; i <= n; i++){
pref[i] = (pref[i - 1] + pw[i]) % mod;
}
for(int i = 1; i <= 4 * n; i++)lz[i] = -1;
to['J'] = 0; to['O'] = 1; to['I'] = 2;
cin >> s[0] >> s[1] >> s[2];
for(int i = 0; i < 3; i++){
for(int j = 0; j < 3; j++){
for(int k = 0; k < 3; k++){
mp[gethash(conv(conv(s[i], s[j]), s[k]))] = 1;
}
}
}
cin >> q;
cin >> t;
build(1, 0, n - 1);
ll ht = st[1];
//cout << ht << " ";
if(mp.find(ht) != mp.end()){
cout << "Yes";
}else{
cout << "No";
}
cout << "\n";
while(q--){
int l, r; char c; cin >> l >> r >> c; l--; r--;
upd(1, 0, n - 1, l, r, to[c]);
ll ht = st[1];
if(mp.find(ht) != mp.end()){
cout << "Yes";
}else{
cout << "No";
}
cout << "\n";
}
return(0);
}
컴파일 시 표준 에러 (stderr) 메시지
Main.cpp: In function 'long long int gethash(std::string)':
Main.cpp:56:43: warning: array subscript has type 'char' [-Wchar-subscripts]
56 | ans += pw[sz(s) - i - 1] * to[s[i]];
| ^
Main.cpp: In function 'void build(int, int, int)':
Main.cpp:63:25: warning: array subscript has type 'char' [-Wchar-subscripts]
63 | st[nd] = to[t[l]];
| ^
Main.cpp: In function 'int main()':
Main.cpp:131:35: warning: array subscript has type 'char' [-Wchar-subscripts]
131 | upd(1, 0, n - 1, l, r, to[c]);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |