关于卡常
查看原帖
关于卡常
731608
TeraniRetZiger楼主2022/6/25 17:49

rt,现在这题我已经卡进210ms了,想请各位大佬看看能不能继续卡进200(

#include <stdio.h>
#include <ctype.h>
#include <memory.h>
#include <bitset>

// using fread
#define INPUT_OPTIMIZE

// using fwrite
#define OUTPUT_OPTIMIZE

namespace IO {
	
#ifdef INPUT_OPTIMIZE
	static char buf[1 << 21], *p1 = buf, *p2 = buf;
	#define getchar() p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++
#endif
	
	inline  
	bool read(char *t) {
		memset(t, 0, sizeof t);
		char *p = t, c = getchar();
		while (isspace(c)) c = getchar();
		while (!isspace(c)) *p++ = c, c = getchar();
		return c == EOF;
	}
	
	template 
	<typename T> 
	inline 
	bool read(T &t) {
		t = 0;
    	char c = getchar(); bool f = 1;
    	while (isspace(c)) c = getchar(); 
		if (c == '-') f = 0, c = getchar();
    	while (isdigit(c)) t = (t << 3) + (t << 1) + (c ^ 48), c = getchar();
		t *= f ? 1 : -1;
		return c == EOF;
	}

	template 
	<typename T, typename... Args> 
	inline 
	bool read(T &t, Args&... args) {
		return read(t) ? 1 : read(args...);
	}

#ifdef OUTPUT_OPTIMIZE
	static char outbuf[1 << 24], *out = outbuf;
	#define putchar(x) *out++ = x
	#define flush() fwrite(outbuf, 1, out - outbuf, stdout)
#else 
   #define flush() 0
#endif

	template 
	<typename T> 
	inline 
	void write(T x) {
		if (x < 0) putchar('-'), x = -x;
		if (!x) return putchar('0'), void();
		static char t[20], p = 0;
		while (x) t[++p] = (x % 10) ^ 48, x /= 10;
		while (p) putchar(t[p--]);
	}

}

using namespace IO;

typedef long long ll;

const int MAXN = 1e6 + 10;
const int MAXM = 1e8 + 10;

const int mod = 317847191;
const int inf = 0x3f3f3f3f;

inline 
ll qpow(ll b, ll p) {
	ll res = 1;
	while (p) {
		if (p & 1) res = res * b % mod;
		b = b * b % mod, p >>= 1; 
	}
	return res;
}

inline 
int max(int a, int b) {
	return a > b ? a : b;
}

inline 
int min(int a, int b) {
	return a < b ? a : b;
}

int n, m;

int a[MAXN], val[MAXN], ans[MAXN];

std::bitset<MAXM> dlt;

char op[MAXN][5];

int maxp, minp = inf;

int main() {
    read(n, m);
    for (register int i(1); i <= n; ++i) read(a[i]);
    for (register int i(1); i <= m; ++i) {
    	read(op[i]);
    	if (*op[i] == 'D') read(val[i]), dlt[val[i]] = 1;
	}
	for (register int i(1); i <= n; ++i) {
		if (!dlt[a[i]]) maxp = max(maxp, a[i]), minp = min(minp, a[i]);
	}
	for (register int i(m); i; --i) {
		switch (*op[i]) {
		case 'D': maxp = max(maxp, val[i]), minp = min(minp, val[i]); break;
		case 'B': ans[i] = maxp; break;
		case 'S': ans[i] = minp; break;
		case 'M': ans[i] = qpow(maxp, minp); break;
		}
	}
	for (register int i(1); i <= m; ++i) {
		if (*op[i] != 'D') write(ans[i]), putchar('\n');
	}
	flush();
}
2022/6/25 17:49
加载中...