MurataHimeko @ 2021-04-15 14:21:31
RT,而且本蒟蒻下载第一个点的数据在本地跑,全部都过了,交上去第一个点却wa了,希望大佬能解答一下qwq
#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
struct IO {
#define MAXSIZE 1<<21
#define isdigit(x) (x >= '0' && x <= '9')
#define isspace(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')
char ibuf[MAXSIZE], obuf[MAXSIZE], *s1, *s2, *s3, endl, blank;
int round[10] = {0, 0, 0, 0, 0, 1, 1, 1, 1}, sta[65], precisions;
bool fail;
FILE *in_stream, *out_stream;
IO(FILE *_stream = stdin, FILE *__stream = stdout) { reset(_stream,__stream); }
#if DEBUG
#else
~IO() {close();}
#endif
inline void reset (FILE *_stream = stdin, FILE *__stream = stdout, bool reset = true) {
s1 = s3 = ibuf, s2 = obuf, in_stream = _stream, out_stream = __stream, fail = false;
if(reset) { endl = '\n'; blank = ' '; precisions = 6; }
}
inline void flush_in() {s3 = (s1 = ibuf) + fread(ibuf, 1, MAXSIZE, in_stream); }
inline void flush_out() { fwrite(obuf, 1, s2-obuf, out_stream), s2 = obuf; }
inline void flush_out_with_stream() { flush_out(); fflush(out_stream); }
inline char get() {
#if DEBUG
return getchar();
#endif
return s1 == s3 && (flush_in(), fail = s1 == s3) ? 0 : *s1++;
}
inline void put(char ch) {
#if DEBUG
putchar(ch);
#else
s2-obuf == MAXSIZE ? flush_out(), 0 : 0, *s2++=ch;
#endif
}
template <class T>
inline void read(T &x) {
bool sign = false; register char c = get(); x = 0;
while(!isdigit(c) && c) {sign=c=='-'; c = get(); }
while(isdigit(c)) { x = (x<<1) + (x<<3) + (c^'0'); c = get(); }
sign ? x = ~x+1 : 0;
}
inline void read(float &x) {
bool sign = false; register char c = get(); x = 0;
while(!isdigit(c) && c) { sign=c=='-'; c = get(); }
while(isdigit(c)) { x = x*10 + (c^'0'); c = get(); }
if(c == '.') { c = get(); register float tmp = 1; while(isdigit(c)) { tmp /= 10, x += tmp * (c^'0'); c = get(); } }
sign ? x = -x : 0;
}
inline void read(double &x) {
bool sign = false; register char c = get(); x = 0;
while(!isdigit(c) && c) { sign=c=='-'; c = get(); }
while(isdigit(c)) { x = x * 10 + (c^'0'); c = get(); }
if(c=='.') { c = get(); register double tmp = 1; while(isdigit(c)) { tmp /= 10, x += tmp * (c^'0'); c = get(); } }
sign ? x = -x : 0;
}
inline void read(long double &x) {
bool sign = false; register char c = get(); x = 0;
while(!isdigit(c) && c) { sign=c=='-'; c = get(); }
while(isdigit(c)) { x = x * 10 + (c^'0'); c = get(); }
if(c == '.') { c = get(); register long double tmp = 1; while(isdigit(c)) { tmp /= 10, x += tmp * (c^'0'); c = get(); } }
sign ? x = -x : 0;
}
inline void read(char *s) {
register char c = get();
while(isspace(c)) c = get();
while(!isspace(c) && c) { *s++=c; c = get(); }
*s = '\0';
}
inline void read(char &c) {
do
c = get();
while(isspace(c));
}
template <class T, class ...Args>
inline void read(T &x, Args &...args) { read(x), read(args...); }
template <class T>
inline void write(T x) {
register int top = 0;
if(x<0) { put('-'); sta[top++] = ~(x%10)+1, x /= 10; x = ~x+1; }
else sta[top++] = x%10, x /= 10;
while(x) sta[top++] = x%10 ,x /= 10;
while(top) put(sta[--top]^'0');
}
inline void write(float y) {
register int top = 0;
if(y<0) { put('-'); y=-y; }
int x = y; y -= x;
write(x);
while(top) put(sta[--top]^'0');
if(y) {
do
sta[top++] = y*10, y = y*10 - sta[top-1];
while(top<precisions-1);
sta[top++] = y*10 + round[(int)((y*10-((int)(y*10)))*10)];
}
put('.');
for(register int i(0); i<top; ++i) put(sta[i]^'0');
for(register int i(top); i<precisions; ++i) put('0');
}
inline void write(double y) {
register int top = 0;
if(y<0) { put('-'); y=-y; }
int x = y; y -=x;
write(x);
if(y) {
do
sta[top++] = y*10, y = y*10 - sta[top-1];
while(top<precisions-1);
sta[top++] = y*10 + round[(int)((y*10-((int)(y*10)))*10)];
}
put('.');
for(register int i(0); i<top; ++i) put(sta[i]^'0');
for(register int i(top); i<precisions; ++i) put('0');
}
inline void write(long double y) {
register int top = 0;
if(y<0) { put('-'); y=-y; }
int x = y; y -= x;
write(x);
if(y) {
do
sta[top++] = y*10, y = y*10 - sta[top-1];
while(top<precisions-1);
sta[top++] = y*10 + round[(int)((y*10-((int)(y*10)))*10)];
}
put('.');
for(register int i(0); i < top; ++i) put(sta[i]^'0');
for(register int i(top); i < precisions; ++i) put('0');
}
inline void write(const char ch) { put(ch); }
inline void write(char *s) { while(*s!='\0') put(*s++); }
inline void write(const char *s) { while(*s!='\0') put(*s++); }
inline void write(const std::string str) { write(str.c_str()); }
inline IO &precision(const int x) { precisions=x; return *this; }
template <class T,class ...Args>
inline void write(T x,Args ...args) { write(x), blank?put(blank), 0:0, write(args...); }
template <class ...Args>
inline void writeln(Args ...args) { write(args...), endl?put(endl), 0:0; }
template <class T>
inline IO &operator>>(T &x) { read(x); return *this; }
inline IO &operator>>(IO &x) { return *this; }
template <class T>
inline IO &operator<<(const T x) { write(x); return *this; }
inline IO &operator<<(IO &x) { return *this; }
inline operator bool() { return !fail; }
template <class T>
inline operator T() { T x; read(x); return x; }
inline void open(FILE *_stream=stdin,FILE *__stream=stdout) { close(), reset(_stream, __stream, false); }
inline void close() { flush_out_with_stream(); fclose(in_stream), fclose(out_stream); }
#define read(x) io>>x
#define out(x) io<<x
}io;
int n, m;
const int N = 4e4+5;
int val[N], hash_[N];
int q[N], sq, cnt;
int pre[N][1001];
int lth[N], rth[N], vis[N];
int all, l, r, last;
int now[2];
struct node {
int v;
int num;
}f[1001][1001];
inline int query (int l, int r) {
int ql = q[l], qr = q[r];
if (ql + 1 >= qr) {
int tot = 0, tnt = all+1;
for (register int i(l); i <= r; ++i) {
vis[val[i]]++;
if (vis[val[i]] > tot || (vis[val[i]] == tot && val[i] < tnt)) {
tot = vis[val[i]];
tnt = val[i];
}
}
for (register int i(l); i <= r; ++i) vis[val[i]]--;
return tnt;
}
else {
int tot = f[ql+1][qr-1].num;
int tnt = f[ql+1][qr-1].v;
for (register int i(l); i <= rth[ql]; ++i) {
int res = pre[val[i]][qr-1] - pre[val[i]][ql];
vis[val[i]]++;
if (res + vis[val[i]] > tot || (res + vis[val[i]] == tot && (val[i] < tnt))) {
tot = res + vis[val[i]];
tnt = val[i];
}
}
for (register int i(lth[qr]); i <= r; ++i) {
int res = pre[val[i]][qr-1] - pre[val[i]][ql];
vis[val[i]]++;
if (res + vis[val[i]] > tot || (res + vis[val[i]] == tot && (val[i] < tnt))) {
tot = res + vis[val[i]];
tnt = val[i];
}
}
for (register int i(l); i <= rth[ql]; ++i) vis[val[i]]--;
for (register int i(lth[qr]); i <= r; ++i) vis[val[i]]--;
return tnt;
}
}
int main () {
read(n), read(m);
sq = (sqrt(n*2)/3);
for (register int i(1); i <= n; ++i) {read(val[i]); hash_[i] = val[i];}
std::sort(hash_+1, hash_+n+1);
all = std::unique(hash_+1, hash_+n+1) - (hash_+1);
for (register int i(1); i <= n; ++i) {
val[i] = lower_bound(hash_+1, hash_+1+all, val[i]) - hash_;
}
for (register int i(1); i <= n; ++i) {
q[i] = (i-1)/sq + 1;
}
cnt = n / sq + (n % sq > 0);
for (register int i(1); i <= cnt; ++i) {
lth[i] = (i-1)*sq + 1;
rth[i] = i * sq;
}
rth[cnt] = n;
for (register int i(1); i <= cnt; ++i) {
now[1] = 0, now[2] = all+1;
for (register int j(i); j <= cnt; ++j) {
for (register int k(lth[j]); k <= rth[j]; ++k) {
vis[val[k]]++;
if (vis[val[k]] > now[1] || (now[1] == vis[val[k]] && (now[2] > val[k]))) {
now[1] = vis[val[k]];
now[2] = val[k];
}
}
f[i][j].v = now[2];
f[i][j].num = now[1];
}
memset (vis, 0, sizeof (vis));
}
for (register int i(1); i <= cnt; ++i) {
for (register int j(lth[i]); j <= rth[i]; ++j) {
pre[val[j]][i]++;
}
}
for (register int i(1); i <= all; ++i) {
for (register int j(1); j <= cnt; ++j) {
pre[i][j] += pre[i][j-1];
}
}
while (m--) {
read(l), read(r);
l = ((l+last-1) % n) + 1, r = ((r+last-1) % n) + 1;
if (l > r) std::swap(l, r);
last = query (l, r);
last = hash_[last];
out(last), out("\n");
}
return 0;
}
/*
5 3
1 2 3 2 1
1 5
3 5
1 5
*/
by Phanstom_Peng @ 2021-04-15 14:47:17
你自己对拍一下啊。。。
我刚做了这道题,帮你拍了一下:
input:
10 1
2 4 2 1 5 5 1 3 3 1
6 8
ans:
1
by Phanstom_Peng @ 2021-04-15 14:47:39
@翎琉
by Phanstom_Peng @ 2021-04-15 14:49:35
by MurataHimeko @ 2021-04-15 14:50:49
@幻影骑士 az,谢谢大佬qr \
by MurataHimeko @ 2021-04-15 14:54:14
az,好像我这个代码输出也是1, qwq
by Phanstom_Peng @ 2021-04-15 14:56:31
你确认一下本地环境有没有问题
by Phanstom_Peng @ 2021-04-15 14:57:13
用洛谷的IDE试一下,说不定是有人把你define min max了
by MurataHimeko @ 2021-04-15 15:01:54
az,貌似在IDE上也是1
by Phanstom_Peng @ 2021-04-15 15:10:57
你把
by Phanstom_Peng @ 2021-04-15 15:11:11
@翎琉