QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#272277 | #5173. 染色 | Froranzen | 0 | 7ms | 9536kb | C++23 | 2.7kb | 2023-12-02 16:44:35 | 2023-12-02 16:44:38 |
answer
#include <bits/stdc++.h>
#define rep(i, f, t) for(int i(f); i <= t; ++i)
#define re(i, t) for(int i(1); i <= t; ++i)
#define per(i, t, f) for(int i(t); i >= f; --i)
#define pe(i, t) for(int i(t); i >= 1; --i)
#define nx(i, u) for(int i(head[u]); i; i = e[i].nxt)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
// #define int long long
using namespace std;
typedef pair <int, int> pii;
#define pb push_back
#define fi first
#define se second
#define ix(l, r) ((l + r) | (l != r))
#define ls (ix(l, mid))
#define rs (ix(mid + 1, r))
#define mp(i, j) (make_pair(i, j))
#define inf (int)(1e9+7)
#define INF 0x3f3f3f3f3f3f3f3f
#define eps 1e-10
#define look_memory cerr<<abs(&sT-&eD)/1024.0/1024<<'\n'
bool sT;
namespace IO {
char buf[1 << 21], *p1 = buf, *p2 = buf, buf1[1 << 21];
inline char gc() {
return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++;
}
#ifndef ONLINE_JUDGE
#endif
// #define gc getchar
template<class I>
inline void read(I &x) {
x = 0;
I f = 1;
char c = gc();
while (c < '0' || c > '9') {
if (c == '-')
f = -1;
c = gc();
}
while (c >= '0' && c <= '9') {
x = x * 10 + c - '0';
c = gc();
}
x *= f;
}
template<class I>
inline void write(I x) {
if (x == 0) {
putchar('0');
return;
}
I tmp = x > 0 ? x : -x;
if (x < 0)
putchar('-');
int cnt = 0;
while (tmp > 0) {
buf1[cnt++] = tmp % 10 + '0';
tmp /= 10;
}
while (cnt > 0)
putchar(buf1[--cnt]);
}
#define in(x) read(x)
#define outn(x) write(x), putchar('\n')
#define out(x) write(x), putchar(' ')
} using namespace IO;
const int N = 1e6 + 5;
int n, Q, l, r, ans;
int a[N], b[N];
int main () {
read(n),read(Q);
re(i, n) read(a[i]);
while(Q--) {
read(l), read(r);
ans = inf;
if(l <= r) {
int L = l;
rep(i, l, r) {
if(a[i] != a[l]) {
L = i-1;
break;
}
}
rep(i, L, r) {
++b[a[i]];
ans = min(ans, (r-L+1)-b[a[i]]);
}
}
else {
swap(l, r);
int R = r;
per(i, r, l) {
if(a[i] != a[r]) {
R = i+1;
break;
}
}
rep(i, l, R) {
++b[a[i]];
ans = min(ans, (R-l+1)-b[a[i]]);
}
}
rep(i, l, r) b[a[i]] = 0;
outn(ans + r - l);
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 9524kb
input:
10000 100 84 85 52 2 78 53 20 21 23 76 37 44 18 5 37 8 81 65 46 58 69 1 69 37 53 46 37 35 35 89 1 77 35 6 46 59 89 46 25 55 50 38 61 67 44 23 29 24 46 4 42 15 34 77 20 34 83 79 12 50 69 26 38 14 9 66 80 72 22 26 9 68 35 38 19 84 92 30 83 62 100 71 81 60 7 37 64 50 33 60 86 75 45 78 32 53 3 48 87 60 ...
output:
3797 4743 6188 8683 752 7263 188 7581 507 1180 260 2325 13705 6479 468 7785 2228 10864 1853 2758 4976 299 6210 650 6891 6399 11823 2812 3272 8115 18427 526 5682 18485 9911 6365 5169 15110 688 477 16183 13133 9194 8110 11382 6840 6624 5199 9433 8835 2254 10669 2780 12998 5134 2220 9119 1965 6703 2934...
result:
wrong answer 1st words differ - expected: '3668', found: '3797'
Subtask #2:
score: 0
Time Limit Exceeded
Test #7:
score: 0
Time Limit Exceeded
input:
100000 100000 3 2 3 3 3 3 2 3 2 1 3 1 1 1 3 2 1 3 1 2 2 1 3 1 2 2 1 1 1 3 2 1 3 3 3 3 1 1 1 2 3 3 2 1 1 1 3 1 3 1 3 2 1 3 2 3 3 2 3 3 2 3 3 3 3 3 2 3 2 3 1 3 3 3 3 3 3 3 1 2 3 3 1 3 1 1 2 2 3 1 1 2 3 2 3 1 3 2 1 3 2 3 2 1 1 3 3 1 3 1 2 2 2 3 2 3 2 3 2 1 1 3 1 3 2 2 3 3 3 1 2 2 3 3 2 1 3 1 2 2 2 3 2 ...
output:
128198 150559 62372 7314 10346 88816 106363 32879 44192 126434 75352 8164 74605 48445 50691 55787 12555 122048 81163 12039 5330 98845 53005 85817 30654 12416 13714 67601 21040 62561 13219 8880 6202 43764 76058 65928 19177 79644 79512 60946 58611 624 20937 135713 4507 48945 70659 38442 11174 28293 37...
result:
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 7ms
memory: 9536kb
input:
5000 5000 256 63 197 36 75 66 33 72 27 75 66 248 29 166 209 252 141 95 84 226 147 249 116 94 192 256 199 273 182 166 116 274 27 211 154 144 283 23 53 110 215 11 164 284 161 221 251 96 43 47 18 115 12 51 156 61 116 209 93 98 47 165 174 106 83 67 184 75 12 290 183 197 112 240 67 56 215 148 104 5 141 2...
output:
1347 2751 1774 2662 4858 5098 3015 1353 897 5171 7975 4954 953 938 821 7422 7820 5440 3888 3297 4564 1602 2584 40 921 307 4441 3962 3884 5848 4708 1686 443 1443 3692 5360 576 120 2081 7769 9302 2089 3179 3752 2941 430 737 4092 182 3295 1464 1628 7270 3065 6076 8247 1572 3878 367 4562 3360 1776 831 2...
result:
wrong answer 1st words differ - expected: '1322', found: '1347'
Subtask #4:
score: 0
Time Limit Exceeded
Test #23:
score: 0
Time Limit Exceeded
input:
1000000 1000000 1105 3246 1880 3554 818 2331 2576 4140 149 4562 3498 3536 3400 4788 4363 4742 1216 4218 4032 1701 1489 4889 1761 3022 3145 4945 3067 4304 5016 4624 1612 13 1335 3613 1086 2210 386 3464 1156 3352 4341 5006 3465 3900 622 654 1826 2983 1250 4164 3335 4308 2995 1982 1347 4335 2535 5054 4...
output:
1270776 310299 764268 79884 161221 580035 993649 1725534 1352469 216366 619350 549232 1393529 322463 1100323 52567 277633 228820 2489 148553 145567 670768 25557 224997 185348 1453136 1675475 550650 147214 974637 1112562 238835 821783 113107 85269 1195235 318407 721912 170450 562910 772010 414481 736...