QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#274431 | #5173. 染色 | Froranzen | 0 | 849ms | 179384kb | C++23 | 3.1kb | 2023-12-03 15:30:31 | 2023-12-03 15:30:31 |
Judging History
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 b[N];
struct Work {
int a[N];
int st[20][N];
int lst[N];
void init () {
int mn = inf;
rep(i, 0, 19) re(j, n) st[i][j] = inf;
re(i, n) lst[a[i]] = inf;
pe(i, n) {
mn = min(mn, lst[a[i]]);
st[0][i] = mn;
lst[a[i]] = i;
}
re(i, 19) {
re(j, n) {
if(st[i-1][j] >= n) break;
st[i][j] = st[i-1][st[i-1][j]+1];
}
}
}
int solve (int l, int r) {
int ans = r - l;
int now = l;
per(i, 19, 0) {
if(st[i][now] <= r) {
now = st[i][now] + 1;
ans -= (1 << i);
}
if(now > n) break;
}
return ans;
}
}T[2];
int main () {
read(n),read(Q);
re(i, n) {
read(b[i]);
T[0].a[i] = b[i];
T[1].a[n-i+1] = b[i];
}
rep(i, 0, 1) T[i].init();
while(Q--) {
read(l), read(r);
int ans = 0;
if(l <= r) {
ans = T[0].solve(l, r);
}
else {
ans = T[1].solve(n-l+1, n-r+1);
swap(l, r);
}
outn(ans + r - l);
}
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 97676kb
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:
3673 4594 5997 8409 730 7033 184 7346 495 1146 254 2260 13275 6279 457 7540 2168 10522 1799 2687 4821 294 6023 629 6678 6199 11452 2722 3172 7862 17849 512 5511 17904 9598 6168 5008 14633 671 466 15672 12715 8903 7860 11024 6624 6418 5040 9134 8559 2184 10334 2704 12583 4982 2153 8839 1913 6499 2844...
result:
wrong answer 1st words differ - expected: '3668', found: '3673'
Subtask #2:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 68ms
memory: 114372kb
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:
127437 149759 61893 7276 10353 88154 105721 32845 43833 125648 75003 8151 74259 48170 50332 55498 12488 121293 80656 12011 5326 98147 52661 85276 30586 12331 13703 67056 20931 62091 13115 8834 6202 43574 75736 65629 19083 79004 79196 60486 58360 624 20829 134953 4518 48756 70364 38259 11129 28170 37...
result:
wrong answer 1st words differ - expected: '113194', found: '127437'
Subtask #3:
score: 0
Wrong Answer
Test #15:
score: 0
Wrong Answer
time: 0ms
memory: 97604kb
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:
1323 2699 1746 2615 4765 5002 2954 1327 881 5081 7820 4865 936 926 809 7279 7671 5332 3816 3229 4483 1579 2542 40 901 301 4355 3887 3818 5744 4616 1660 438 1416 3628 5262 565 119 2046 7623 9121 2049 3126 3688 2886 420 727 4011 180 3234 1444 1604 7135 3011 5962 8091 1539 3812 363 4481 3303 1742 819 2...
result:
wrong answer 1st words differ - expected: '1322', found: '1323'
Subtask #4:
score: 0
Wrong Answer
Test #23:
score: 0
Wrong Answer
time: 849ms
memory: 179384kb
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:
1263867 308628 760159 79458 160359 576934 988266 1716183 1345178 215193 615986 546285 1385971 320728 1094322 52291 276170 227575 2476 147758 144811 667163 25418 223792 184331 1445290 1666388 547662 146413 969361 1106554 237565 817334 112496 84815 1188750 316711 717986 169539 559891 767825 412222 732...
result:
wrong answer 1st words differ - expected: '1263815', found: '1263867'