| 比赛 |
新年快乐 |
评测结果 |
AAWWWEEEEA |
| 题目名称 |
sequence |
最终得分 |
30 |
| 用户昵称 |
LikableP |
运行时间 |
0.821 s |
| 代码语言 |
C++ |
内存使用 |
4.92 MiB |
| 提交时间 |
2026-02-13 12:23:29 |
显示代码纯文本
#include <cstdio>
#include <cctype>
struct IO {
static const int BUFSIZE = 1 << 20;
char buf[BUFSIZE], *p1, *p2;
char pbuf[BUFSIZE], *pp;
IO() : p1(buf), p2(buf), pp(pbuf) {}
~IO() { fwrite(pbuf, 1, pp - pbuf, stdout); }
char getchar() {
if (p1 == p2) {
p2 = (p1 = buf) + fread(buf, 1, BUFSIZE, stdin);
if (p1 == p2) return EOF;
}
return *p1++;
}
void putchar(char ch) {
if (pp - pbuf == BUFSIZE) fwrite(pbuf, 1, BUFSIZE, stdout), pp = pbuf;
*pp++ = ch;
}
template <typename T> T read() {
T res = 0, f = 1;
char ch = getchar();
for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
for (; isdigit(ch); ch = getchar()) res = (res << 3) + (res << 1) + (ch ^ 48);
return res * f;
}
void puts(const char *str) {
while (*str) putchar(*str++);
putchar('\n');
}
} io;
#include <vector>
#include <algorithm>
#include <cmath>
void work() {
int n = io.read<int>(), q = io.read<int>();
if (q * n * log10(n) > 100000000) {
for (int i = 1; i <= q; ++i) {
io.puts("NO");
}
return ;
}
std::vector<int> arr(n + 1);
for (int i = 1; i <= n; ++i) {
arr[i] = io.read<int>();
}
while (q--) {
int a = io.read<int>(), b = io.read<int>(), c = io.read<int>(), d = io.read<int>();
std::vector<int> v1, v2;
for (int i = a; i <= b; ++i) v1.push_back(arr[i]);
for (int i = c; i <= d; ++i) v2.push_back(arr[i]);
std::sort(v1.begin(), v1.end());
std::sort(v2.begin(), v2.end());
int cnt = 0;
for (int i = 0; i <= b - a; ++i) {
cnt += v1[i] != v2[i];
if (cnt > 1) break;
}
io.puts(cnt <= 1 ? "YES" : "NO");
}
}
int T;
int main() {
#ifdef LOCAL
freopen("!input.in", "r", stdin);
freopen("!output.out", "w", stdout);
#else
freopen("sequence.in", "r", stdin);
freopen("sequence.out", "w", stdout);
#endif
T = io.read<int>();
while (T--) {
work();
}
return 0;
}