话说回来谁能看一下我这个不开 O2 80 分的代码
查看原帖
话说回来谁能看一下我这个不开 O2 80 分的代码
112917
Eason_AC楼主2020/11/4 22:58

Rt,开了 O2 过的(

#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <iostream>
#include <map>
#define ll long long
#define _for(i, a, b) for(int (i) = (a); (i) <= (b); ++(i))
#define _rep(i, a, b) for(int (i) = (a); (i) >= (b); --(i))
#define _spfor(i, a, b, c) for(int (i) = (a); (i) <= (b); (i) += (c))
#define _sprep(i, a, b, c) for(int (i) = (a); (i) >= (b); (i) -= (c))
#define _forll(i, a, b) for(ll (i) = (a); (i) <= (b); ++(i))
#define _repll(i, a, b) for(ll (i) = (a); (i) >= (b); --(i))
#define _spforll(i, a, b, c) for(ll (i) = (a); (i) <= (b); (i) += (c))
#define _sprepll(i, a, b, c) for(ll (i) = (a); (i) >= (b); (i) -= (c))
using namespace std;

inline void getint(int& x) {
	int f = 1; x = 0;
	char c = getchar();
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}
inline void getll(ll &x) {
	ll f = 1; x = 0;
	char c = getchar();
	while(!isdigit(c)) {if(c == '-') f = -1; c = getchar();}
	while(isdigit(c)) {x = x * 10 + c - '0'; c = getchar();}
	x *= f;
}
inline void writeint(int& x) {
	if(!x) {printf("0"); return;}
	else if(x < 0) printf("-");
	int tmp = x < 0 ? -x : x, digit[17] = {0};
	while(tmp) {digit[++digit[0]] = tmp % 10; tmp /= 10;}
	_rep(i, digit[0], 1)	printf("%d", digit[i]);
}
inline void writell(ll& x) {
	if(!x) {printf("0"); return;}
	else if(x < 0) printf("-");
	ll tmp = x < 0 ? -x : x; int digit[27] = {0};
	while(tmp) {digit[++digit[0]] = tmp % 10; tmp /= 10;}
	_rep(i, digit[0], 1)	printf("%d", digit[i]);
}

int n, a, b, p, m;
char t[2000007];
map<int, int> pp;
struct node {
	int l, r;
	bool operator < (const node& rhs) const {return l < rhs.l;}
}ppp[2000007];
inline int mo(int x) {return (x % n + n) % n;}

int main() {
//	freopen("tear.in", "r", stdin);
//	freopen("tear.out", "w", stdout);
	getint(n), getint(a), getint(b), getint(p), getint(m);
	scanf("%s", t);
	if(n < m) return printf("0"), 0;
	_for(i, 0, m - 1) {
		int tmp = (1ll * a * i + b) % n, l, r;
		if(t[i] == '0') l = mo(-tmp), r = mo(p - 1 - tmp);
		else l = mo(p - tmp), r = mo(n - 1 - tmp);
		if(l <= r) pp[l]++, pp[r + 1]--;
		else pp[0]++, pp[r + 1]--, pp[l]++, pp[n]--;
	}
	int l, r, sum = 0, tot = 0, cnt = 0;
	for(auto u : pp) {
		if(!u.second) continue;
		if(sum == m)
			r = u.first - 1, ppp[++tot] = {l, r}, cnt += (r - l + 1);
		sum += u.second;
		if(sum == m) l = u.first;
	}
	sort(ppp + 1, ppp + tot + 1);
	_for(i, n - m + 1, n - 1) {
		int tmp = 1ll * a * i % n, x = upper_bound(ppp + 1, ppp + tot + 1, (node){tmp, 0}) - ppp - 1;
		if(x && tmp <= ppp[x].r) cnt--;
	}
	writeint(cnt);
//	fclose(stdin);
//	fclose(stdout);
	return 0;
}
2020/11/4 22:58
加载中...