제출 #467936

#제출 시각아이디문제언어결과실행 시간메모리
467936LittlePantsCrossing (JOI21_crossing)C++17
100 / 100
576 ms20568 KiB
#define ll loli
#include<bits/stdc++.h>
#define pb push_back
#define eb emplace_back
#define push emplace
#define sz(x) (int)(x.size())
#define re(x) reverse(all(x))
#define uni(x) x.resize(unique(all(x)) - x.begin())
#define all(x) x.begin(), x.end()
#define mem(x, v) memset(x, v, sizeof x); 
#define int long long
#define pii pair<int, int>
#define inf 1e9
#define INF 1e18
#define mod 1000000007
#define F first
#define S second
#define IO ios_base::sync_with_stdio(0); cin.tie(0);
using namespace std;
void trace_() {cerr << "\n";}
template<typename T1, typename... T2> void trace_(T1 t1, T2... t2) {cerr << ' ' << t1; trace_(t2...); }
#define trace(...) cerr << "[" << #__VA_ARGS__ << "] :", trace_(__VA_ARGS__);

const int mxN = 2e5 + 5, p = 17;
int n, q, h[mxN], ppow[mxN], sump[mxN], mp[300];
string s[3], t;
set<int> st;

string cross(string a, string b) {
	string s;
	for (int i = 0; i < n; i++) {
		if (a[i] == b[i]) s.pb(a[i]);
		else {
			if ('J' != a[i] and 'J' != b[i]) s.pb('J');
			if ('O' != a[i] and 'O' != b[i]) s.pb('O');
			if ('I' != a[i] and 'I' != b[i]) s.pb('I');
		}
	}
	return s;
}

#define ls x<<1
#define rs x<<1|1
#define mid ((l+r)>>1)

int seg[mxN * 4], tag[mxN * 4];
inline void up(int x) {
	seg[x] = (seg[ls] + seg[rs]) % mod;
}

void build(int l = 1, int r = n, int x = 1) {
	if(l == r) {
		seg[x] = h[l];
		return;
	}
	build(l, mid, ls);	build(mid+1, r, rs);
	up(x);
}

void down(int l, int r, int x) {
	if(!tag[x]) return;
	seg[ls] = tag[x] * (sump[mid] - sump[l - 1] + mod) % mod;
	seg[rs] = tag[x] * (sump[r] - sump[mid] + mod) % mod;
	tag[ls] = tag[x];
	tag[rs] = tag[x];
	tag[x] = 0;
}

void modify(int a, int b, int v, int l = 1, int r = n, int x = 1) {
	if (l != r)	down(l, r, x);
	if(a <= l and r <= b) {
		seg[x] = v * (sump[r] - sump[l - 1] + mod) % mod;
		tag[x] = v;
		return;
	}
	if(a <= mid) modify(a, b, v, l, mid, ls);
	if(b > mid) modify(a, b, v, mid+1, r, rs);
	up(x);
}

inline int H(string s) {
	int tmp = 0;
	for (int i = 1; i <= n; i++) {
		tmp = (tmp + (mp[s[i - 1]] * ppow[i]) % mod) % mod;
	}
	return tmp;
}


signed main() {
	IO;	
	cin >> n >> s[0] >> s[1] >> s[2] >> q >> t;
	mp['J'] = 1; mp['O'] = 2; mp['I'] = 3;
	ppow[0] = 1;
	for (int i = 1; i <= n; i++) {
		ppow[i] = (ppow[i - 1] * p) % mod;
		sump[i] = (sump[i - 1] + ppow[i]) % mod;
	}

	vector<string> v;
	v.pb(s[0]); v.pb(s[1]); v.pb(s[2]);
	st.insert(H(s[0]));
	st.insert(H(s[1]));
	st.insert(H(s[2]));

	for (int i = 0; i < sz(v); i++) {
		for (int j = i + 1; j < sz(v); j++) {
			string t = cross(v[i], v[j]);
			int ht = H(t);
			if (!st.count(ht)) {
				st.insert(ht);
				v.pb(t);
			}
		}
	}


	for (int i = 1; i <= n; i++) {
		h[i] = (mp[t[i - 1]] * ppow[i]) % mod; 
	}
	build();
	
	if (st.count(seg[1])) cout << "Yes\n";
	else cout << "No\n";

	while (q--) {
		int l, r; char c;
		cin >> l >> r >> c;	
		modify(l, r, mp[c]);
		if (st.count(seg[1])) cout << "Yes\n";
		else cout << "No\n";
	}
}

컴파일 시 표준 에러 (stderr) 메시지

Main.cpp: In function 'long long int H(std::string)':
Main.cpp:84:28: warning: array subscript has type 'char' [-Wchar-subscripts]
   84 |   tmp = (tmp + (mp[s[i - 1]] * ppow[i]) % mod) % mod;
      |                            ^
Main.cpp: In function 'int main()':
Main.cpp:119:22: warning: array subscript has type 'char' [-Wchar-subscripts]
  119 |   h[i] = (mp[t[i - 1]] * ppow[i]) % mod;
      |                      ^
Main.cpp:129:19: warning: array subscript has type 'char' [-Wchar-subscripts]
  129 |   modify(l, r, mp[c]);
      |                   ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...