QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#416619#8512. Harmonic OperationskevinshanWA 1ms3728kbC++142.5kb2024-05-22 00:29:542024-05-22 00:29:56

Judging History

你现在查看的是最新测评结果

  • [2024-05-22 00:29:56]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3728kb
  • [2024-05-22 00:29:54]
  • 提交

answer

//#pragma GCC optimize("O3")
// 1200

#include <bits/stdc++.h>
#include <random>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi; 
typedef vector<pi> vpi;

#define mp make_pair
#define f first
#define s second
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize
#define bk back()
#define pb push_back

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define For(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define Rof(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

const int MOD = 1e9+7;
const ld PI = acos((ld)-1);
mt19937 rng; // or mt19937_64
template<class T> bool ckmin(T& a, const T& b) { 
	return b < a ? a = b, 1 : 0; }

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {
	cerr << h; if (sizeof...(t)) cerr << ", ";
	DBG(t...); }
#ifdef LOCAL // compile with -DLOCAL
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

#define vl vector<ll>

ll p=97;
vl hashstr(string S) {
	vl hsh(sz(S)+1);
	For(i,sz(S)) {
		hsh[i+1] = hsh[i]*p+(S[i]-'a')%MOD;
	}
	return hsh;
}
void solve() {
	string S;cin>>S;
	int n = sz(S);
	string S2 = S+S;
	vector<vl> hsh(2);
	hsh[0] = hashstr(S2);
	reverse(all(S2));
	hsh[1] = hashstr(S2);
	reverse(all(S2));
	vl pows(n+5);
	pows[0] = 1;
	FOR(i,1,n+3) pows[i] = pows[i-1]*p%MOD;

	map<ll, vpi> M;
	For(k,2) For(i,sz(S)) {
		ll tmp = hsh[k][n+i+1] - hsh[k][i];
		tmp = ((tmp%MOD)+MOD)%MOD;
		tmp = (tmp*pows[n-i])%MOD;
		M[tmp].pb({k,i});
	}

	vector<vl> gr(2, vl(n+1));
	int cnt = 0;
	trav(x,M) {
		trav(y,x.s) {
			gr[y.f][y.s] = cnt;
		}
		cnt++;
	}


	int K; cin>>K;
	vpi pre(K+1);
	For(i,K) {
		char c;cin>>c;
		if(c=='I') {
			pre[i+1] = {1^pre[i].f,-pre[i].s};
		} else if(c=='R') {
			int x;cin>>x;
			pre[i+1] = {pre[i].f,pre[i].s+x};
		} else {
			int x;cin>>x;
			pre[i+1] = {pre[i].f,pre[i].s-x};
		}
	}

	ll ans = 0;
	vi grCnt(cnt+5);
	grCnt[gr[0][0]]++;
	For(i,K) {
		int tmp = pre[i].s;
		tmp = (tmp%n+n)%n;
		int grId = gr[pre[i].f][tmp];
		ans += grCnt[grId];

		grCnt[grId]++;
	}
	cout << ans << endl;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); 
	solve();
}


/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3496kb

input:

pda
2
R 2
L 2

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 1ms
memory: 3512kb

input:

aaa
4
R 1
I
I
R 1

output:

10

result:

ok 1 number(s): "10"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3504kb

input:

caso
6
L 1
I
I
R 1
I
I

output:

4

result:

ok 1 number(s): "4"

Test #4:

score: -100
Wrong Answer
time: 1ms
memory: 3728kb

input:

qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq
100
L 12
I
R 47
L 54
I
I
R 80
L 86
L 19
R 5
L 53
L 40
R 20
L 11
R 40
I
I
R 66
R 6
L 76
L 93
R 39
I
I
L 24
R 59
R 99
L 52
I
I
R 77
L 11
R 60
L 16
I
L 40
I
R 35
L 64
R 11
L 34
I
R 35
I
L 87
I
I
L 42
L ...

output:

59

result:

wrong answer 1st numbers differ - expected: '5050', found: '59'